feat:(策略导入导出)上传文件下载文件以及样例
This commit is contained in:
@@ -425,4 +425,13 @@ Policy-Delete-v1-00017
|
|||||||
Comment 删除安全策略
|
Comment 删除安全策略
|
||||||
${rescode} DeletePolicies ${policyIds}
|
${rescode} DeletePolicies ${policyIds}
|
||||||
${policyIds} Create List
|
${policyIds} Create List
|
||||||
Log ${rescode}
|
Log ${rescode}
|
||||||
|
Policy-Import-v1-00018
|
||||||
|
Comment 导入json
|
||||||
|
${objectIds} Set Variable ${EMPTY}
|
||||||
|
${rescode} ${policyIds} ImportPolicy uploadFiles tsg_security_imp.json tsg_security
|
||||||
|
Policy-Export-v1-00019
|
||||||
|
Comment 导 出json
|
||||||
|
${objectIds} Set Variable ${EMPTY}
|
||||||
|
${response} ExportPolicy tsg_security ${EMPTY} ${EMPTY}
|
||||||
|
WriteFile downloads download.json ${response}
|
||||||
@@ -3,6 +3,7 @@ Resource ../../03-Variable/BifangApiVariable.txt
|
|||||||
Library REST http://${host}:${port}
|
Library REST http://${host}:${port}
|
||||||
Library Collections
|
Library Collections
|
||||||
Library RequestsLibrary
|
Library RequestsLibrary
|
||||||
|
Library json
|
||||||
|
|
||||||
*** Keywords ***
|
*** Keywords ***
|
||||||
ManageApistr
|
ManageApistr
|
||||||
@@ -142,4 +143,29 @@ BaseFormRequest
|
|||||||
log return data =${response}
|
log return data =${response}
|
||||||
Should Be Equal As Strings ${response.status_code} 200
|
Should Be Equal As Strings ${response.status_code} 200
|
||||||
${response} to json ${response.content}
|
${response} to json ${response.content}
|
||||||
|
[Return] ${response}
|
||||||
|
BaseFormRequest1
|
||||||
|
[Documentation]
|
||||||
|
... 下载文件专用
|
||||||
|
... 由于下载的json存在特殊字符
|
||||||
|
... 隐藏需要设置response.encoding='utf-8-sig'
|
||||||
|
[Arguments] ${requestUri} ${data} ${apiVersion}
|
||||||
|
${headers} set variable {"Authorization":"${token}","Content-Type":"application/x-www-form-urlencoded"}
|
||||||
|
create session api http://${host}:${port}/${apiVersion} ${headers}
|
||||||
|
${response} Run Keyword If "${data}"=="${EMPTY}" Get Request api ${requestUri}
|
||||||
|
... ELSE Get Request api ${requestUri}?${data}
|
||||||
|
log return data =${response}
|
||||||
|
${response.encoding} set variable utf-8-sig
|
||||||
|
Should Be Equal As Strings ${response.status_code} 200
|
||||||
|
${response} json.Loads ${response.content}
|
||||||
|
[Return] ${response}
|
||||||
|
BaseMultipartPostRequest
|
||||||
|
[Arguments] ${requestUri} ${data} ${files} ${apiVersion}
|
||||||
|
${headers} set variable {"Authorization":"${token}"}
|
||||||
|
${dataString} Dictionary-To-QueryParams ${data}
|
||||||
|
create session api http://${host}:${port}/${apiVersion} ${headers}
|
||||||
|
${response}= Post Request api ${requestUri}?${dataString} files=${files}
|
||||||
|
log return data =${response}
|
||||||
|
Should Be Equal As Strings ${response.status_code} 200
|
||||||
|
${response} to json ${response.content}
|
||||||
[Return] ${response}
|
[Return] ${response}
|
||||||
@@ -107,4 +107,38 @@ WxDeletePolicy1
|
|||||||
${response} BaseDeleteRequest /${version}${policyUrl} ${params}
|
${response} BaseDeleteRequest /${version}${policyUrl} ${params}
|
||||||
${rescode} Set Variable ${response['code']}
|
${rescode} Set Variable ${response['code']}
|
||||||
Should Be Equal As Strings ${rescode} 200
|
Should Be Equal As Strings ${rescode} 200
|
||||||
[Return] ${rescode}
|
[Return] ${rescode}
|
||||||
|
ImportPolicy
|
||||||
|
[Documentation]
|
||||||
|
... 策略导入
|
||||||
|
[Arguments] ${filePath} ${fileName} ${policyType}
|
||||||
|
Directory Should Exist ${path}
|
||||||
|
File Should Exist ${path}/${filePath}/${fileName}
|
||||||
|
File Should Not Be Empty ${path}/${filePath}/${fileName}
|
||||||
|
${size} Get File Size ${path}/${filePath}/${fileName}
|
||||||
|
${binFile} Evaluate (r'import_policy.json',open(r"${path}/${filePath}/${fileName}",'rb'),'application/json')
|
||||||
|
Log ${binFile}
|
||||||
|
${data} Create Dictionary policyType=${policyType}
|
||||||
|
${file} Create Dictionary file=${binFile}
|
||||||
|
${response} BaseMultipartPostRequest ${policyUrl}/batch ${data} ${file} ${version}
|
||||||
|
${rescode} Set Variable ${response['code']}
|
||||||
|
Should Be Equal As Strings ${rescode} 200
|
||||||
|
[Return] ${rescode}
|
||||||
|
ExportPolicy
|
||||||
|
[Documentation]
|
||||||
|
... 策略导出
|
||||||
|
[Arguments] ${policyType} ${policyIds} ${policyName}
|
||||||
|
Should Not Be Empty ${policyType}
|
||||||
|
${params} Create Dictionary policyType=${policyType}
|
||||||
|
Run Keyword If "${policyIds}"!="${EMPTY}" Set To Dictionary ${params} policyIds=${policyIds}
|
||||||
|
Run Keyword If "${policyName}"!="${EMPTY}" Set To Dictionary ${params} policyName=${policyName}
|
||||||
|
${paramsStr} Dictionary-To-QueryParams ${params}
|
||||||
|
${response} BaseFormRequest1 ${policyUrl}/batch ${paramsStr} ${version}
|
||||||
|
[Return] ${response}
|
||||||
|
WriteFile
|
||||||
|
[Arguments] ${filePath} ${fileName} ${content}
|
||||||
|
Create File ${path}/${filePath}/${fileName}
|
||||||
|
${type} Evaluate type(${content})
|
||||||
|
${content} Run Keyword If "${type}" == "<class 'dict'>" json.Dumps ${content}
|
||||||
|
... ELSE Set Variable ${content}
|
||||||
|
Append To File ${path}/${filePath}/${fileName} ${content}
|
||||||
52
05-Other/uploadFiles/tsg_security_imp.json
Normal file
52
05-Other/uploadFiles/tsg_security_imp.json
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
{
|
||||||
|
"list": [
|
||||||
|
{
|
||||||
|
"action": "deny",
|
||||||
|
"appObjectIdArray": [
|
||||||
|
2
|
||||||
|
],
|
||||||
|
"doLog": 1,
|
||||||
|
"evaluationLayer": "any_layer",
|
||||||
|
"evaluationOrder": 0,
|
||||||
|
"evaluationStage": 0,
|
||||||
|
"filterInfo": "2537:TSG_FIELD_HTTP_REQ_HDR;3002:TSG_SECURITY_SOURCE_ADDR;2723:TSG_SECURITY_DESTINATION_ADDR;2:app_id",
|
||||||
|
"isValid": 0,
|
||||||
|
"opTime": "2020-06-15 13:31:39",
|
||||||
|
"opUser": 353,
|
||||||
|
"policyDesc": "",
|
||||||
|
"policyId": 1231,
|
||||||
|
"policyName": "zw_test",
|
||||||
|
"policyType": "tsg_security",
|
||||||
|
"protocol": "HTTP",
|
||||||
|
"referenceObject": [
|
||||||
|
{
|
||||||
|
"objectId": 2723,
|
||||||
|
"protocolFields": [
|
||||||
|
"TSG_SECURITY_DESTINATION_ADDR"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"objectId": 2537,
|
||||||
|
"protocolFields": [
|
||||||
|
"TSG_FIELD_HTTP_REQ_HDR"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"objectId": 3002,
|
||||||
|
"protocolFields": [
|
||||||
|
"TSG_SECURITY_SOURCE_ADDR"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"scheduleId": [],
|
||||||
|
"userRegion": {
|
||||||
|
"protocol": "HTTP",
|
||||||
|
"code": 200,
|
||||||
|
"method": "alert",
|
||||||
|
"message": "aaaa"
|
||||||
|
},
|
||||||
|
"userTags": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"totalNum": 1
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user