feat:(策略启用停用):优化关键字,策略启用停用只用传policyId,policyType,不处理其他的字典字段

This commit is contained in:
wangxin
2020-06-17 18:53:58 +08:00
parent 2d673f6711
commit a567786cd7

View File

@@ -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}