2020-06-18 16:29:17 +08:00
|
|
|
|
*** Settings ***
|
|
|
|
|
|
Library Collections
|
|
|
|
|
|
Library RequestsLibrary
|
|
|
|
|
|
Resource ../../../03-Variable/BifangApiVariable.txt
|
|
|
|
|
|
Resource ../../../02-Keyword/tsg_bfapi/policy_file_interface/FunctionalKeywords.robot
|
|
|
|
|
|
Resource ProcessObjectBody.robot
|
|
|
|
|
|
Library Collections
|
|
|
|
|
|
Resource ../Common.robot
|
|
|
|
|
|
*** Variables ***
|
|
|
|
|
|
${objectUrl} /policy/object
|
|
|
|
|
|
*** Keywords ***
|
|
|
|
|
|
AddObjects
|
|
|
|
|
|
[Documentation]
|
|
|
|
|
|
... 新增策略对象
|
|
|
|
|
|
... objectList,策略对象,可为list类型与dict类型
|
|
|
|
|
|
... returnData,是否返回数据,固定为1
|
|
|
|
|
|
[Arguments] ${returnData} ${objectList}
|
|
|
|
|
|
${returnData}= Run Keyword If '${returnData}' == '${EMPTY}' Set Variable 1
|
|
|
|
|
|
... ELSE Set Variable ${returnData}
|
|
|
|
|
|
|
|
|
|
|
|
#必选参数判定
|
|
|
|
|
|
Should Not Be Empty ${objectList}
|
|
|
|
|
|
${dictType} = Evaluate type(${objectList})
|
2020-06-23 18:15:03 +08:00
|
|
|
|
${body} Run Keyword If "${dictType}" == "<class 'list'>" ObjectListOperation ${returnData} ${objectList} add
|
|
|
|
|
|
... ELSE IF "${dictType}" == "<class 'dict'>" ObjectOperation ${returnData} ${objectList} add
|
2020-06-18 16:29:17 +08:00
|
|
|
|
... ELSE Set Variable ${EMPTY}
|
|
|
|
|
|
|
|
|
|
|
|
${response} BasePostRequestForV2 ${objectUrl} ${body} ${version}
|
2020-06-23 18:15:03 +08:00
|
|
|
|
${objectIds} Run Keyword If "${returnData}" == "1" Get-ObjectIds ${response}
|
2020-06-18 16:29:17 +08:00
|
|
|
|
... ELSE Create List
|
|
|
|
|
|
${rescode} Set Variable ${response['code']}
|
|
|
|
|
|
Should Be Equal As Strings ${rescode} 200
|
|
|
|
|
|
[Return] ${rescode} ${objectIds}
|
|
|
|
|
|
UpdateObjects
|
|
|
|
|
|
[Documentation]
|
|
|
|
|
|
... 更新策略对象
|
|
|
|
|
|
... objectList,策略对象,可为list类型与dict类型
|
|
|
|
|
|
... returnData,是否返回数据,固定为1
|
|
|
|
|
|
... opAction,可为update,enable,disable
|
|
|
|
|
|
[Arguments] ${returnData} ${objectList} ${opAction}
|
|
|
|
|
|
${returnData}= Run Keyword If '${returnData}' == '${EMPTY}' Set Variable 1
|
|
|
|
|
|
... ELSE Set Variable ${returnData}
|
|
|
|
|
|
|
|
|
|
|
|
#必选参数判定
|
|
|
|
|
|
Should Not Be Empty ${objectList}
|
|
|
|
|
|
${dictType} = Evaluate type(${objectList})
|
2020-06-23 18:15:03 +08:00
|
|
|
|
${body} Run Keyword If "${dictType}" == "<class 'list'>" ObjectListOperation ${returnData} ${objectList} ${opAction}
|
|
|
|
|
|
... ELSE IF "${dictType}" == "<class 'dict'>" ObjectOperation ${returnData} ${objectList} ${opAction}
|
2020-06-18 16:29:17 +08:00
|
|
|
|
... ELSE Set Variable ${EMPTY}
|
|
|
|
|
|
|
|
|
|
|
|
${response} BaseEditRequestForV2 ${objectUrl} ${body} ${version}
|
|
|
|
|
|
${rescode} Set Variable ${response['code']}
|
|
|
|
|
|
Should Be Equal As Strings ${rescode} 200
|
|
|
|
|
|
[Return] ${rescode}
|
|
|
|
|
|
GetObjectItems
|
|
|
|
|
|
[Documentation]
|
|
|
|
|
|
... 获取策略对象中的item,策略对象单元
|
|
|
|
|
|
... 当updateItemList中有需要传入数据时
|
|
|
|
|
|
... 调用此关键字
|
|
|
|
|
|
[Arguments] ${params}
|
|
|
|
|
|
#必选参数判定
|
|
|
|
|
|
Should Not Be Empty ${params}
|
|
|
|
|
|
${paramsStr} Dictionary-To-QueryParams ${params}
|
|
|
|
|
|
${response} BaseFormRequest /policy/items ${paramsStr} ${version}
|
|
|
|
|
|
${rescode} Set Variable ${response['code']}
|
|
|
|
|
|
Should Be Equal As Strings ${rescode} 200
|
|
|
|
|
|
${data} Set Variable ${response['data']}
|
|
|
|
|
|
${itemIds} Create List
|
|
|
|
|
|
FOR ${item} IN @{data['list']}
|
|
|
|
|
|
Append To List ${itemIds} ${item['itemId']}
|
|
|
|
|
|
END
|
2020-06-28 17:35:34 +08:00
|
|
|
|
[Return] ${rescode} ${itemIds} ${data['list']}
|
|
|
|
|
|
DeleteObjects
|
|
|
|
|
|
[Documentation]
|
|
|
|
|
|
... 删除策略对象
|
|
|
|
|
|
... params,传入的删除字典
|
|
|
|
|
|
... 结构为[1,2,3]
|
|
|
|
|
|
[Arguments] ${objectIds}
|
|
|
|
|
|
${type} Evaluate isinstance(${objectIds},list)
|
|
|
|
|
|
Should Be True ${type}
|
|
|
|
|
|
${dict} Create Dictionary objectIds=${objectIds}
|
|
|
|
|
|
${json} json.Dumps ${dict} ensure_ascii=False
|
|
|
|
|
|
${response} BaseDeleteRequest /${version}${objectUrl} ${json}
|
|
|
|
|
|
${rescode} Set Variable ${response['code']}
|
|
|
|
|
|
Should Be Equal As Strings ${rescode} 200
|
|
|
|
|
|
[Return] ${rescode}
|
|
|
|
|
|
ImportObject
|
|
|
|
|
|
[Documentation]
|
|
|
|
|
|
... 策略对象导入
|
|
|
|
|
|
... filePath文件路径
|
|
|
|
|
|
... fileName文件名称
|
|
|
|
|
|
... objectType对象类型
|
|
|
|
|
|
... objectSubType对象子类型
|
|
|
|
|
|
... objectName对象名称
|
|
|
|
|
|
[Arguments] ${filePath} ${fileName} ${objectType} ${objectSubType} ${objectName}
|
|
|
|
|
|
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}
|
|
|
|
|
|
Should Not Be Empty ${objectType}
|
|
|
|
|
|
${objectSubType} Run Keyword If "${objectType}"=="ip" and "${objectSubType}"=="${EMPTY}" Set Variable endpoint
|
|
|
|
|
|
... ELSE Set Variable ${objectSubType}
|
|
|
|
|
|
${subfix} Fetch From Right ${fileName} .
|
|
|
|
|
|
${binFile} Run Keyword If "${subfix}"=="txt" Evaluate (r'${fileName}',open(r"${path}/${filePath}/${fileName}",'rb'),'text/plain')
|
|
|
|
|
|
... ELSE IF "${subfix}"=="csv" Evaluate (r'${fileName}',open(r"${path}/${filePath}/${fileName}",'rb'),'application/vnd.ms-excel')
|
|
|
|
|
|
... ELSE ${EMPTY}
|
|
|
|
|
|
${data} Create Dictionary objectType=${objectType}
|
|
|
|
|
|
Run Keyword If "${objectSubType}"!="${EMPTY}" Set To Dictionary ${data} objectSubType=${objectSubType}
|
|
|
|
|
|
Run Keyword If "${objectName}"!="${EMPTY}" Set To Dictionary ${data} objectName=${objectName}
|
|
|
|
|
|
${file} Create Dictionary file=${binFile}
|
|
|
|
|
|
${response} BaseMultipartPostRequest ${objectUrl}/batch ${data} ${file} ${version}
|
|
|
|
|
|
${rescode} Set Variable ${response['code']}
|
|
|
|
|
|
Should Be Equal As Strings ${rescode} 200
|
|
|
|
|
|
[Return] ${rescode}
|
|
|
|
|
|
ExportObject
|
|
|
|
|
|
[Documentation]
|
|
|
|
|
|
... 策略对象导出
|
|
|
|
|
|
... objectType ip,url等
|
|
|
|
|
|
... objectSubType 子类型
|
|
|
|
|
|
... objectIds 1,2,3
|
|
|
|
|
|
... objectName 字符串
|
|
|
|
|
|
[Arguments] ${objectType} ${objectSubType} ${objectIds} ${objectName}
|
|
|
|
|
|
Should Not Be Empty ${objectType}
|
|
|
|
|
|
${params} Create Dictionary objectType=${objectType}
|
|
|
|
|
|
Run Keyword If "${objectSubType}"!="${EMPTY}" Set To Dictionary ${params} objectSubType=${objectSubType}
|
|
|
|
|
|
Run Keyword If "${objectIds}"!="${EMPTY}" Set To Dictionary ${params} objectIds=${objectIds}
|
|
|
|
|
|
Run Keyword If "${objectName}"!="${EMPTY}" Set To Dictionary ${params} objectName=${objectName}
|
|
|
|
|
|
${response} BaseGetRequestReturnBinary ${objectUrl}/batch ${params} ${version}
|
|
|
|
|
|
[Return] ${response}
|