2020-12-15 19:58:08 +08:00
|
|
|
|
*** Settings ***
|
|
|
|
|
|
Library Collections
|
|
|
|
|
|
Library RequestsLibrary
|
|
|
|
|
|
Resource ../../../03-Variable/BifangApiVariable.txt
|
|
|
|
|
|
Resource ../../common/ApiHttpRequest.robot
|
2020-12-25 15:10:10 +08:00
|
|
|
|
Library REST http://${host}:${port}
|
|
|
|
|
|
Library json
|
2020-12-15 19:58:08 +08:00
|
|
|
|
|
|
|
|
|
|
*** Variables ***
|
|
|
|
|
|
${policyapiv2} /v2/policy/compile
|
|
|
|
|
|
${objectapiv1} /v1/policy/object
|
|
|
|
|
|
${hosturl} http://${host}:${port}
|
|
|
|
|
|
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
|
|
|
|
|
*** Keywords ***
|
|
|
|
|
|
GetRequestResposeCodePrivate
|
|
|
|
|
|
[Arguments] ${data}
|
|
|
|
|
|
[Documentation] [Get方法封装:第二层,]
|
|
|
|
|
|
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
|
|
|
|
|
${response} GetRequestBase http://${hosturl}:${port} ${policyapiv2} ${header} ${data}
|
|
|
|
|
|
${response} to json ${response}
|
|
|
|
|
|
${code} get from dictionary ${response} code
|
|
|
|
|
|
[Return] ${code}
|
|
|
|
|
|
|
|
|
|
|
|
GetPolicyData
|
|
|
|
|
|
[Arguments] ${host} ${api} ${header} ${data} ${returnKey}
|
|
|
|
|
|
[Documentation] [Get方法封装:第二层,]
|
|
|
|
|
|
${response} GetRequestBase ${hosturl} ${policyapiv2} ${header} ${data}
|
|
|
|
|
|
${response} to json ${response}
|
|
|
|
|
|
${returnValue} get from dictionary ${response} ${returnKey}
|
|
|
|
|
|
[Return] ${returnValue}
|
|
|
|
|
|
|
|
|
|
|
|
AddPolicyData
|
2020-12-25 15:10:10 +08:00
|
|
|
|
[Arguments] ${returnData} ${data}
|
2020-12-15 19:58:08 +08:00
|
|
|
|
[Documentation] [Get方法封装:第二层,]
|
2020-12-25 15:10:10 +08:00
|
|
|
|
${response} PostHttpRequestBase ${hosturl} ${policyapiv2} ${header} ${data}
|
2020-12-15 19:58:08 +08:00
|
|
|
|
${response} to json ${response}
|
2020-12-25 15:10:10 +08:00
|
|
|
|
${policyIds} Run Keyword If "${returnData}" == "1" GetPolicyIds ${response}
|
|
|
|
|
|
... ELSE Create List
|
|
|
|
|
|
${rescode} Set Variable ${response['code']}
|
|
|
|
|
|
[Return] ${rescode} ${policyIds}
|
2020-12-15 19:58:08 +08:00
|
|
|
|
|
|
|
|
|
|
AddObjectData
|
2020-12-25 15:10:10 +08:00
|
|
|
|
[Arguments] ${returnData} ${data}
|
2020-12-15 19:58:08 +08:00
|
|
|
|
[Documentation] [Get方法封装:第二层,]
|
|
|
|
|
|
${response} PostHttpRequestBase ${hosturl} ${objectapiv1} ${header} ${data}
|
|
|
|
|
|
${response} to json ${response}
|
2020-12-25 15:10:10 +08:00
|
|
|
|
${objectIds} Run Keyword If "${returnData}" == "1" GetObjectIds ${response}
|
|
|
|
|
|
... ELSE Create List
|
|
|
|
|
|
${rescode} Set Variable ${response['code']}
|
|
|
|
|
|
[Return] ${rescode} ${objectIds}
|
2020-12-15 19:58:08 +08:00
|
|
|
|
|
|
|
|
|
|
AddPolicyBase
|
|
|
|
|
|
[Arguments] ${host} ${api} ${header} ${body}
|
|
|
|
|
|
${header} Create Dictionary Content-Type=application/json Authorization=${token}
|
|
|
|
|
|
Create Session api ${hosturl} headers=${header}
|
|
|
|
|
|
${remoteResponse} Post Request api ${api} data=${body}
|
|
|
|
|
|
[Return] ${remoteResponse.content}
|
|
|
|
|
|
|
|
|
|
|
|
AddPolicyCode
|
|
|
|
|
|
[Arguments] ${host} ${api} ${header} ${data}
|
|
|
|
|
|
[Documentation] [Get方法封装:第二层,]
|
|
|
|
|
|
${response} PostRequestBase ${hosturl} ${api} ${header} ${data}
|
|
|
|
|
|
${response} to json ${response}
|
|
|
|
|
|
${code} get from dictionary ${response} code
|
|
|
|
|
|
[Return] ${code}
|
|
|
|
|
|
|
2020-12-25 15:10:10 +08:00
|
|
|
|
|
|
|
|
|
|
GetObjectIds
|
|
|
|
|
|
[Documentation]
|
|
|
|
|
|
... 获取结果中的对象ID
|
|
|
|
|
|
[Arguments] ${value}
|
|
|
|
|
|
Log Call Get-ObjectIds
|
|
|
|
|
|
${objectIds} Create List
|
|
|
|
|
|
${objectIdsTemp} Set Variable ${EMPTY}
|
|
|
|
|
|
${return} ${data} Run Keyword And Ignore Error Get From Dictionary ${value} data
|
|
|
|
|
|
Return From Keyword If "${return}"=="FAIL" ${objectIdsTemp}
|
|
|
|
|
|
|
|
|
|
|
|
FOR ${object} IN @{value['data']['objectList']}
|
|
|
|
|
|
Append To List ${objectIds} ${object['objectId']}
|
|
|
|
|
|
END
|
|
|
|
|
|
${json} json.Dumps ${objectIds} ensure_ascii=False
|
|
|
|
|
|
${json} Remove String ${json} [
|
|
|
|
|
|
${json} Remove String ${json} ]
|
|
|
|
|
|
[Return] ${json}
|
|
|
|
|
|
|
|
|
|
|
|
GetPolicyIds
|
|
|
|
|
|
[Arguments] ${value}
|
|
|
|
|
|
[Documentation] 获取结果中的策略ID
|
|
|
|
|
|
${policyIds} Create List
|
|
|
|
|
|
FOR ${policy} IN @{value['data']['policyList']}
|
|
|
|
|
|
#${policyIdList} Create List ${policy['policyId']}
|
|
|
|
|
|
#${policyObj} Create Dictionary policyType=${policy['policyType']} policyIds=${policyIdList}
|
|
|
|
|
|
#Append To List ${policyIds} ${policyObj}
|
|
|
|
|
|
Append To List ${policyIds} ${policy['policyId']}
|
|
|
|
|
|
END
|
|
|
|
|
|
${len} Get Length ${policyIds}
|
|
|
|
|
|
${policyIds} Run Keyword If ${len}==1 Set Variable ${policyIds[0]}
|
|
|
|
|
|
... ELSE Set Variable ${policyIds}
|
|
|
|
|
|
[Return] ${policyIds}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DelPolicysAndGroupObjects
|
|
|
|
|
|
[Arguments] ${policyids} ${objectids}
|
|
|
|
|
|
#引用此关键字,${objectids}参数必须是双层列表,eg:['[1]','[2,3]','[4,5,6,7]']
|
|
|
|
|
|
#删除和对象
|
|
|
|
|
|
#删除策略
|
|
|
|
|
|
log toDeletePolicy_DelPolicys
|
|
|
|
|
|
${listlenth}= Get Length ${policyids}
|
|
|
|
|
|
Run Keyword If "${listlenth}"=="0" log no Policys to del
|
|
|
|
|
|
... ELSE DelPolicys ${policyids}
|
|
|
|
|
|
#删除对象
|
|
|
|
|
|
log todeleteobj_DelGroupObjects
|
|
|
|
|
|
Run Keyword If "${objectids}"=="${EMPTY}" log no Objects to del
|
|
|
|
|
|
... ELSE DelGroupObjects ${objectids}
|
|
|
|
|
|
|
|
|
|
|
|
DelPolicys
|
|
|
|
|
|
[Arguments] ${policyids}
|
|
|
|
|
|
${listlenth}= Get Length ${policyids}
|
|
|
|
|
|
FOR ${var} IN RANGE ${listlenth}
|
|
|
|
|
|
log ${var}
|
|
|
|
|
|
DelPolicy ${policyids}[${var}]
|
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
|
|
DelPolicy
|
|
|
|
|
|
[Arguments] ${body}
|
|
|
|
|
|
#删除策略
|
|
|
|
|
|
log toDeletePolicy_DeletePolicyDeletePolicy
|
|
|
|
|
|
${response} DeleteRequestBase /${version}/policy/compile ${body}
|
|
|
|
|
|
#{"policyType":"tsg_security","policyIds":[${policyids}]}
|
|
|
|
|
|
${response_code} Get From Dictionary ${response} code
|
|
|
|
|
|
Should Be Equal As Strings ${response_code} 200
|
|
|
|
|
|
${response} Convert to String ${response}
|
|
|
|
|
|
log ${response}
|
|
|
|
|
|
#Should Be Equal As Strings ${response} {'code': 200, 'msg': 'Success', 'success': True}
|
|
|
|
|
|
|
|
|
|
|
|
DelGroupObjects
|
|
|
|
|
|
[Arguments] ${objectids}
|
|
|
|
|
|
FOR ${var} IN @{objectids}
|
|
|
|
|
|
log ${var}
|
|
|
|
|
|
DelGroupObject ${var}
|
2021-01-07 10:24:42 +08:00
|
|
|
|
END
|
2020-12-25 15:10:10 +08:00
|
|
|
|
|
|
|
|
|
|
DelGroupObject
|
|
|
|
|
|
[Arguments] ${objectids}
|
|
|
|
|
|
#删除对象
|
|
|
|
|
|
log todeleteobj
|
|
|
|
|
|
${response} DeleteRequestBase /${version}/policy/object {"objectIds":${objectids}}
|
|
|
|
|
|
${response_code} Get From Dictionary ${response} code
|
|
|
|
|
|
Should Be Equal As Strings ${response_code} 200
|
|
|
|
|
|
${response} Convert to String ${response}
|
|
|
|
|
|
log ${response}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DelPolicyAndObjectAndProfile
|
|
|
|
|
|
[Arguments] ${policyids} ${objectids} ${profiles}
|
|
|
|
|
|
DelPolicysAndGroupObjects ${policyids} ${objectids}
|
|
|
|
|
|
DelProfiles ${profiles}
|
|
|
|
|
|
|
|
|
|
|
|
DelProfiles
|
|
|
|
|
|
[Arguments] ${profiles}
|
|
|
|
|
|
FOR ${profile} IN @{profiles}
|
2021-01-07 10:24:42 +08:00
|
|
|
|
Run Keyword If "${profile}"!="" and ${profile}!="${EMPTY}" DelProfile ${profile}[typeUrl] ${profile}[profileIds]
|
2020-12-25 15:10:10 +08:00
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
|
|
DelProfile
|
|
|
|
|
|
[Arguments] ${typeUrl} ${profileIds}
|
|
|
|
|
|
#删除对象
|
|
|
|
|
|
log DeleteProfile
|
|
|
|
|
|
${response} DeleteRequestBase /${version}/policy/profile/${typeUrl} {"profileIds":[${profileIds}]}
|
|
|
|
|
|
${response_code} Get From Dictionary ${response} code
|
|
|
|
|
|
Should Be Equal As Strings ${response_code} 200
|
|
|
|
|
|
#Integer ${response_code} 200
|
|
|
|
|
|
${response} Convert to String ${response}
|
2021-01-07 10:24:42 +08:00
|
|
|
|
log ${response}
|
|
|
|
|
|
|