From a567786cd7dd3e9814981a545a18c85ff5eddfdb Mon Sep 17 00:00:00 2001 From: wangxin Date: Wed, 17 Jun 2020 18:53:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:(=E7=AD=96=E7=95=A5=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E5=81=9C=E7=94=A8)=EF=BC=9A=E4=BC=98=E5=8C=96=E5=85=B3?= =?UTF-8?q?=E9=94=AE=E5=AD=97=EF=BC=8C=E7=AD=96=E7=95=A5=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E5=81=9C=E7=94=A8=E5=8F=AA=E7=94=A8=E4=BC=A0policyId,policyTyp?= =?UTF-8?q?e,=E4=B8=8D=E5=A4=84=E7=90=86=E5=85=B6=E4=BB=96=E7=9A=84?= =?UTF-8?q?=E5=AD=97=E5=85=B8=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../policy_object/ProcessPolicyBody.robot | 97 +++++++++++-------- 1 file changed, 58 insertions(+), 39 deletions(-) diff --git a/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot b/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot index 652a8ad..a0069d2 100644 --- a/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot +++ b/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot @@ -84,6 +84,7 @@ WxPolicyOrganize ... 单个策略转换为json [Arguments] ${policy} ${opAction} ${policyObjectVersion} Log To Console Call WxPolicyOrganize + ${returnDict} Create Dictionary ${emptyList} Create List #v1版本接口与v2版本接口不同的字段 Run Keyword If "${policyObjectVersion}"=="v1" Dictionary Should Not Contain Key ${policy} source @@ -101,76 +102,95 @@ WxPolicyOrganize Run Keyword If "${opAction}"=="disable" and "${policyId}"=="${EMPTY}" Fail policyId is required when opAction is disable Run Keyword If "${opAction}"=="enable" and "${return}"=="FAIL" Fail policyId is required when opAction is enable Run Keyword If "${opAction}"=="enable" and "${policyId}"=="${EMPTY}" Fail policyId is required when opAction is enable + ${policyId} Run Keyword If "${opAction}"=="add" Set Variable ${EMPTY} + ... ELSE Get From Dictionary ${policy} policyId + Set To Dictionary ${returnDict} policyId=${policyId} + + ${return} ${policyType} Run Keyword And Ignore Error Get From Dictionary ${policy} policyType + Run Keyword If "${return}"=="FAIL" or "${policyType}"=="${EMPTY}" Set To Dictionary ${returnDict} policyType=${Default_PolicyType} + ... ELSE Set To Dictionary ${returnDict} policyType=${policyType} + + #enable disable直接返回json + Run Keyword And Return If "${opAction}"=="enable" or "${opAction}"=="disable" ManagePolicyEnableAndDisable ${returnDict} ${opAction} # 取可选参数,为传入设置默认值 ${return} ${policyName} Run Keyword And Ignore Error Get From Dictionary ${policy} policyName - Run Keyword If "${return}"=="FAIL" or "${policyName}"=="${EMPTY}" Set To Dictionary ${policy} policyName=${Default_PolicyName} + Run Keyword If "${return}"=="FAIL" or "${policyName}"=="${EMPTY}" Set To Dictionary ${returnDict} policyName=${Default_PolicyName} + ... ELSE Set To Dictionary ${returnDict} policyName=${policyName} - ${return} ${policyType} Run Keyword And Ignore Error Get From Dictionary ${policy} policyType - Run Keyword If "${return}"=="FAIL" or "${policyType}"=="${EMPTY}" Set To Dictionary ${policy} policyType=${Default_PolicyType} #policyDesc 不是必填的选项 ${return} ${policyDesc} Run Keyword And Ignore Error Get From Dictionary ${policy} policyDesc - Run Keyword If "${return}"=="FAIL" or "${policyDesc}"=="${EMPTY}" Set To Dictionary ${policy} policyDesc=${Default_PolicyDesc} + Run Keyword If "${return}"=="FAIL" or "${policyDesc}"=="${EMPTY}" Set To Dictionary ${returnDict} policyDesc=${Default_PolicyDesc} + ... ELSE Set To Dictionary ${returnDict} policyDesc=${policyDesc} ${return} ${action} Run Keyword And Ignore Error Get From Dictionary ${policy} action - Run Keyword If "${return}"=="FAIL" or "${action}"=="${EMPTY}" Set To Dictionary ${policy} action=${Default_Action} + Run Keyword If "${return}"=="FAIL" or "${action}"=="${EMPTY}" Set To Dictionary ${returnDict} action=${Default_Action} + ... ELSE Set To Dictionary ${returnDict} action=${action} #userTags 不是必填的选项 ${return} ${userTags} Run Keyword And Ignore Error Get From Dictionary ${policy} userTags - Run Keyword If "${return}"=="FAIL" or "${userTags}"=="${EMPTY}" Set To Dictionary ${policy} userTags=${Default_UserTags} + Run Keyword If "${return}"=="FAIL" or "${userTags}"=="${EMPTY}" Set To Dictionary ${returnDict} userTags=${Default_UserTags} + ... ELSE Set To Dictionary ${returnDict} userTags=${userTags} ${return} ${doLog} Run Keyword And Ignore Error Get From Dictionary ${policy} doLog - Run Keyword If "${return}"=="FAIL" or "${doLog}"=="${EMPTY}" Set To Dictionary ${policy} doLog=${Default_DoLog} - ${return} ${isValid} Run Keyword And Ignore Error Get From Dictionary ${policy} isValid - Run Keyword If "${return}"=="FAIL" or "${isValid}"=="${EMPTY}" Set To Dictionary ${policy} isValid=${Default_IsValid} - ${return} ${scheduleId} Run Keyword And Ignore Error Set Variable ${policy}[scheduleId] + Run Keyword If "${return}"=="FAIL" or "${doLog}"=="${EMPTY}" Set To Dictionary ${returnDict} doLog=${Default_DoLog} + ... ELSE Set To Dictionary ${returnDict} doLog=${doLog} - Run Keyword If "${opAction}"=="enable" Set To Dictionary ${policy} isValid=1 - Run Keyword If "${opAction}"=="disable" Set To Dictionary ${policy} isValid=0 - + ${return} ${isValid} Run Keyword And Ignore Error Get From Dictionary ${policy} isValid + Run Keyword If "${return}"=="FAIL" or "${isValid}"=="${EMPTY}" Set To Dictionary ${returnDict} isValid=${Default_IsValid} + ... ELSE Set To Dictionary ${returnDict} isValid=${isValid} + + ${return} ${scheduleId} Run Keyword And Ignore Error Get From Dictionary ${policy} scheduleId ${scheduleIdV} Run Keyword If "${return}"!="FAIL" and "${scheduleId}"!="${EMPTY}" and "${scheduleId}"!="${None}" Evaluate list(map(int, re.split('[,]', '${scheduleId}'))) re ... ELSE Set Variable ${emptyList} - Set To Dictionary ${policy} scheduleId=${scheduleIdV} + Set To Dictionary ${returnDict} scheduleId=${scheduleIdV} ${return} ${appObjectIdArray} Run Keyword If "${policyObjectVersion}"=="v1" Run Keyword And Ignore Error Get From Dictionary ${policy} appObjectIdArray ... ELSE Run Keyword And Ignore Error Get From Dictionary ${policy} appIdObjects ${appObjectIdArrayV} Run Keyword If "${return}"=="FAIL" or "${appObjectIdArray}"=="${EMPTY}" Evaluate list(map(int, re.split('[,]', '${Default_AppObjectIdArray}'))) re ... ELSE Evaluate list(map(int, re.split('[,]', '${appObjectIdArray}'))) re - Run Keyword If "${policyObjectVersion}"=="v1" Set To Dictionary ${policy} appObjectIdArray=${appObjectIdArrayV} - ... ELSE IF "${policyObjectVersion}"=="v2" Set To Dictionary ${policy} appIdObjects=${appObjectIdArrayV} - ${policyId} Run Keyword If "${opAction}"=="add" Set Variable ${EMPTY} - ... ELSE Get From Dictionary ${policy} policyId + Run Keyword If "${policyObjectVersion}"=="v1" Set To Dictionary ${returnDict} appObjectIdArray=${appObjectIdArrayV} + ... ELSE IF "${policyObjectVersion}"=="v2" Set To Dictionary ${returnDict} appIdObjects=${appObjectIdArrayV} + # 固定值 - Set To Dictionary ${policy} policyId=${policyId} doBlacklist=${0} + Set To Dictionary ${returnDict} doBlacklist=${0} # 分别处理EffectiveRange、UserRegion和ReferenceObject参数 - WxManageEffectiveRange ${policy} + WxManageEffectiveRange ${policy} ${returnDict} #WxManageUserRegion ${policy} - Run Keyword If "${policyObjectVersion}"=="v1" WxManageReferenceObject ${policy} ELSE IF "${policyObjectVersion}"=="v2" WxManageObjectV2 ${policy} + Run Keyword If "${policyObjectVersion}"=="v1" WxManageReferenceObject ${policy} ${returnDict} ELSE IF "${policyObjectVersion}"=="v2" WxManageObjectV2 ${policy} ${returnDict} #先取出useragion 再放回json ${return} ${userRegion} Run Keyword And Ignore Error Get From Dictionary ${policy} userRegion - Set To Dictionary ${policy} userRegion=${Default_UserRegion} + Set To Dictionary ${returnDict} userRegion=${Default_UserRegion} ${userRegion} Run Keyword If "${return}"=="FAIL" or '${userRegion}'=="${EMPTY}" Set Variable "" ... ELSE Set Variable ${userRegion} #针对主动防御特殊处理,主动防御不应用对象 ${active_defence_emptyList} Create List - ${return} ${policyType} Run Keyword And Ignore Error Set Variable ${policy}[policyType] - Run Keyword If "${policyObjectVersion}"=="v1" and "${policyType}"=="active_defence" Set To Dictionary ${policy} referenceObject=${active_defence_emptyList} - Run Keyword If "${policyObjectVersion}"=="v1" and "${policyType}"=="active_defence" Set To Dictionary ${policy} appObjectIdArray=${active_defence_emptyList} + ${return} ${policyType} Run Keyword And Ignore Error Get From Dictionary ${policy} policyType + Run Keyword If "${policyObjectVersion}"=="v1" and "${policyType}"=="active_defence" Set To Dictionary ${returnDict} referenceObject=${active_defence_emptyList} + Run Keyword If "${policyObjectVersion}"=="v1" and "${policyType}"=="active_defence" Set To Dictionary ${returnDict} appObjectIdArray=${active_defence_emptyList} #v版本主动防御 - Run Keyword If "${policyObjectVersion}"=="v2" and "${policyType}"=="active_defence" Set To Dictionary ${policy} source=${active_defence_emptyList} - Run Keyword If "${policyObjectVersion}"=="v2" and "${policyType}"=="active_defence" Set To Dictionary ${policy} destination=${active_defence_emptyList} - Run Keyword If "${policyObjectVersion}"=="v2" and "${policyType}"=="active_defence" Set To Dictionary ${policy} filterList=${active_defence_emptyList} - Run Keyword If "${policyObjectVersion}"=="v2" and "${policyType}"=="active_defence" Set To Dictionary ${policy} appIdObjects=${active_defence_emptyList} + Run Keyword If "${policyObjectVersion}"=="v2" and "${policyType}"=="active_defence" Set To Dictionary ${returnDict} source=${active_defence_emptyList} + Run Keyword If "${policyObjectVersion}"=="v2" and "${policyType}"=="active_defence" Set To Dictionary ${returnDict} destination=${active_defence_emptyList} + Run Keyword If "${policyObjectVersion}"=="v2" and "${policyType}"=="active_defence" Set To Dictionary ${returnDict} filterList=${active_defence_emptyList} + Run Keyword If "${policyObjectVersion}"=="v2" and "${policyType}"=="active_defence" Set To Dictionary ${returnDict} appIdObjects=${active_defence_emptyList} # 转为json结构并返回 - ${json} json.Dumps ${policy} ensure_ascii=False + ${json} json.Dumps ${returnDict} ensure_ascii=False ${json} Replace String ${json} "method:rst" ${userRegion} #${json} Replace String ${json} "effectiveRange:Empty" {} Log Policy-${json} [Return] ${json} - +ManagePolicyEnableAndDisable + [Documentation] + ... 启用与禁用时调用 + [Arguments] ${returnDict} ${opAction} + Run Keyword If "${opAction}"=="enable" Set To Dictionary ${returnDict} isValid=1 + Run Keyword If "${opAction}"=="disable" Set To Dictionary ${returnDict} isValid=0 + ${json} json.Dumps ${returnDict} ensure_ascii=False + Log Policy-${json} + [Return] ${json} WxManageEffectiveRange [Documentation] ... 处理EffectiveRange ... 加入effectiveRange={}的处理支持 - [Arguments] ${policyList} + [Arguments] ${policyList} ${returnDict} Log To Console Call WxManageEffectiveRange ${emptyList} Create List ${emptyListDouble} Create List ${emptyList} @@ -180,16 +200,16 @@ WxManageEffectiveRange ... ELSE Set Variable ${effectiveRange} ${value} Run Keyword If "${effectiveRange}"=="${EMPTY}" Create Dictionary tag_sets=${emptyListDouble} ... ELSE IF "${effectiveRange}"=="{}" Create Dictionary ELSE AnalysisEffectiveRange ${effectiveRange} - Set To Dictionary ${policyList} effectiveRange=${value} + Set To Dictionary ${returnDict} effectiveRange=${value} WxManageReferenceObject [Documentation] ... 处理引用对象字符串 ... v1版本接口使用 - [Arguments] ${policy} + [Arguments] ${policy} ${returnDict} Log To Console Call WxManageReferenceObject ${emptyList} Create List #默认客户端条件类型:clientip or clientsubid - ${return} ${defaultClient} Run Keyword And Ignore Error Set Variable ${policy}[defalutClient] + ${return} ${defaultClient} Run Keyword And Ignore Error Get From Dictionary ${policy} defalutClient ${defaultClient} Run Keyword If "${return}"=="FAIL" or "${defaultClient}"=="${EMPTY}" Set Variable ${Default_Client_Type} ... ELSE Set Variable ${defaultClient} Run Keyword If '${addTestClentIPFlag}'=='1' and '${defaultClient}'=='clientip' ManageClientIPObject ${emptyList} @@ -209,7 +229,7 @@ WxManageReferenceObject # END ObjectLoop ${value} ${emptyList} - Set To Dictionary ${policy} referenceObject=${emptyList} + Set To Dictionary ${returnDict} referenceObject=${emptyList} ObjectLoop [Arguments] ${value} ${valueList} @@ -224,7 +244,7 @@ WxManageObjectV2 ... v2版本接口使用 ... source,destination,filterList # 处理引用对象字符串 - [Arguments] ${policy} + [Arguments] ${policy} ${returnDict} Log To Console Call WxManageObjectV2 #默认客户端条件类型:clientip or clientsubid ${return} ${defaultClient} Run Keyword And Ignore Error Get From Dictionary ${policy} defalutClient @@ -240,7 +260,7 @@ WxManageObjectV2 AnalysisObjectV2 ${policy} destination ${destinationList} AnalysisObjectV2 ${policy} filterList ${filterList} - Set To Dictionary ${policy} source=${sourceList} destination=${destinationList} filterList=${filterList} + Set To Dictionary ${returnDict} source=${sourceList} destination=${destinationList} filterList=${filterList} Log ${policy} ManageClientIPObjectV2 @@ -320,7 +340,6 @@ WxGet-PolicyIds ${policyIds} Create List FOR ${policy} IN @{value['data']['policyList']} - ${policyType} = Evaluate type(${policy}) ${policyIdList} Create List ${policy['policyId']} ${policyObj} Create Dictionary policyType=${policy['policyType']} policyIds=${policyIdList} Append To List ${policyIds} ${policyObj}