235 lines
14 KiB
Plaintext
235 lines
14 KiB
Plaintext
*** Settings ***
|
||
Library json
|
||
Library Collections
|
||
Resource ../../03-Variable/BifangApiVariable.txt
|
||
Resource ../../03-Variable/PolicyObjectDefault.txt
|
||
Resource ../../02-Keyword/tsg_bfapi/PolicyObject.robot
|
||
|
||
*** Keywords ***
|
||
ObjectParamsOpertion
|
||
[Documentation]
|
||
... 描述:入口,opAction参数固定为'add'
|
||
... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
|
||
|
||
[Arguments] ${returnData} ${objectList}
|
||
${emptyList} Create List
|
||
${returnDict} Create Dictionary
|
||
# 断言必传参数
|
||
# Should Not Be Empty ${objectList}[objectType]
|
||
# Set To Dictionary ${returnDict} objectType=${objectList}[objectType]
|
||
Should Not Be Empty ${objectList}[addItemList]
|
||
# 取可选参数,为传入设置默认值
|
||
${return} ${objectType} Run Keyword And Ignore Error Set Variable ${objectList}[objectType]
|
||
${objectTypeV} Run Keyword If "${return}"!="FAIL" and "${objectType}"!="${EMPTY}" Set Variable ${objectType}
|
||
... ELSE Set Variable ${Default_ObjectType}
|
||
Set To Dictionary ${objectList} objectType=${objectTypeV}
|
||
Set To Dictionary ${returnDict} objectType=${objectTypeV}
|
||
${return} ${objectSubType} Run Keyword And Ignore Error Set Variable ${objectList}[objectSubType]
|
||
Run Keyword If "${return}"!="FAIL" and "${objectSubType}"!="${EMPTY}" Set To Dictionary ${returnDict} objectSubType=${objectSubType}
|
||
... ELSE Set To Dictionary ${returnDict} objectSubType=${Default_ObjectSubType}
|
||
${return} ${isValid} Run Keyword And Ignore Error Set Variable ${objectList}[isValid]
|
||
Run Keyword If "${return}"=="FAIL" or "${isValid}"=="${EMPTY}" Set To Dictionary ${returnDict} isValid=${Default_IsValid}
|
||
... ELSE Set To Dictionary ${returnDict} isValid=${isValid}
|
||
${return} ${isInitialize} Run Keyword And Ignore Error Set Variable ${objectList}[isInitialize]
|
||
Run Keyword If "${return}"=="FAIL" or "${isInitialize}"=="${EMPTY}" Set To Dictionary ${returnDict} isInitialize=${Default_IsInitialize}
|
||
... ELSE Set To Dictionary ${returnDict} isInitialize=${isInitialize}
|
||
${return} ${isExclusion} Run Keyword And Ignore Error Set Variable ${objectList}[isExclusion]
|
||
Run Keyword If "${return}"=="FAIL" or "${isExclusion}"=="${EMPTY}" Set To Dictionary ${returnDict} isExclusion=${Default_IsExclusion}
|
||
... ELSE Set To Dictionary ${returnDict} isExclusion=${isExclusion}
|
||
${return} ${objectName} Run Keyword And Ignore Error Set Variable ${objectList}[objectName]
|
||
Run Keyword If "${return}"=="FAIL" or "${objectName}"=="${EMPTY}" Set To Dictionary ${returnDict} objectName=${Default_ObjectName}
|
||
... ELSE Set To Dictionary ${returnDict} objectName=${objectName}
|
||
${return} ${objectDesc} Run Keyword And Ignore Error Set Variable ${objectList}[objectDesc]
|
||
Run Keyword If "${return}"!="FAIL" and "${objectDesc}"!="${EMPTY}" Set To Dictionary ${returnDict} objectDesc=${objectDesc}
|
||
... ELSE Set To Dictionary ${returnDict} objectDesc=${Default_ObjectDesc}
|
||
${return} ${subObjectIds} Run Keyword And Ignore Error Set Variable ${objectList}[subObjectIds]
|
||
Run Keyword If "${return}"!="FAIL" and "${subObjectIds}"!="${EMPTY}" Set To Dictionary ${returnDict} subObjectIds=${subObjectIds}
|
||
... ELSE Set To Dictionary ${returnDict} subObjectIds=${emptyList}
|
||
# 处理AddItemList
|
||
ManageAddItemList ${objectList} ${returnDict}
|
||
|
||
# 转为json结构并返回
|
||
${dict} Create Dictionary opAction=add returnData=${returnData} objectList=${returnDict}
|
||
${json} json.Dumps ${dict} ensure_ascii=False
|
||
Log Object_Request_Body-${json}
|
||
[Return] ${json}
|
||
|
||
ManageAddItemList
|
||
# 处理addItemList数组
|
||
[Arguments] ${objectList} ${returnDict}
|
||
${itemList} Run Keyword If '${objectList}[objectType]'=='ip' ManageIpItemList ${objectList}[addItemList]
|
||
... ELSE IF '${objectList}[objectType]'=='http_signature' ManageStrItemList ${objectList}[addItemList] ${True}
|
||
... ELSE ManageStrItemList ${objectList}[addItemList] ${False}
|
||
Set To Dictionary ${returnDict} addItemList=${itemList}
|
||
|
||
ManageIpItemList
|
||
# 处理IP对象
|
||
[Arguments] ${str}
|
||
${returnList} Create List
|
||
${list} Evaluate re.split('[,]', '${str}') re
|
||
FOR ${var} IN @{list}
|
||
Continue For Loop If '${var}' == '${EMPTY}'
|
||
# 区分入参的类型,分别处理
|
||
${obj} Run Keyword If '#' in '${var}' and '&' in '${var}' IpItemType1 ${var}
|
||
... ELSE IF '#' in '${var}' IpItemType2 ${var}
|
||
... ELSE IF '&' in '${var}' IpItemType3 ${var}
|
||
... ELSE IpItemType4 ${var}
|
||
Append To List ${returnList} ${obj}
|
||
END
|
||
[Return] ${returnList}
|
||
|
||
ManageStrItemList
|
||
# 处理除IP外其它字符串对象
|
||
[Arguments] ${str} ${flag}
|
||
${returnList} Create List
|
||
${list} Evaluate re.split('[,]', '${str}') re
|
||
FOR ${var} IN @{list}
|
||
Continue For Loop If '${var}' == '${EMPTY}'
|
||
${obj} AnalysisStrItem ${var} ${flag}
|
||
Append To List ${returnList} ${obj}
|
||
END
|
||
[Return] ${returnList}
|
||
|
||
IpItemType1
|
||
# IP类型1:4|0|0|endpoint#range|192.168.40.1|192.168.40.50|80/88&range|192.168.40.1|192.168.40.50|80/88|1|itemName|itemDesc,...
|
||
[Arguments] ${str}
|
||
${obj} Create Dictionary
|
||
${left} Evaluate '${str}'[0:'${str}'.find('#')]
|
||
${right} Evaluate '${str}'['${str}'.find('#')+1:]
|
||
${values} Evaluate re.split('[|]', '${left}') re
|
||
${addrType} Convert To Integer ${values}[0]
|
||
${protocol} Convert To Integer ${values}[1]
|
||
${direction} Convert To Integer ${values}[2]
|
||
Set To Dictionary ${obj} addrType=${addrType} protocol=${protocol} direction=${direction} isSession=${values}[3]
|
||
|
||
${cfgs} Evaluate re.split('[&]', '${right}') re
|
||
${client} Set Variable ${cfgs}[0]
|
||
${server} Set Variable ${cfgs}[1]
|
||
|
||
${cValues} Evaluate re.split('[|]', '${client}') re
|
||
${sValues} Evaluate re.split('[|]', '${server}') re
|
||
${clientPort1} Evaluate int(re.split('[/]', '${cValues}[3]')[0]) re
|
||
${clientPort2} Evaluate int(re.split('[/]', '${cValues}[3]')[1]) re
|
||
${serverPort1} Evaluate int(re.split('[/]', '${sValues}[3]')[0]) re
|
||
${serverPort2} Evaluate int(re.split('[/]', '${sValues}[3]')[1]) re
|
||
Set To Dictionary ${obj} clientIpFormat=${cValues}[0] clientIp1=${cValues}[1] clientIp2=${cValues}[2] clientPortFormat=range clientPort1=${clientPort1} clientPort2=${clientPort2}
|
||
Set To Dictionary ${obj} serverIpFormat=${sValues}[0] serverIp1=${sValues}[1] serverIp2=${sValues}[2] serverPortFormat=range serverPort1=${serverPort1} serverPort2=${serverPort2}
|
||
|
||
OtherParams ${sValues} ${obj}
|
||
[Return] ${obj}
|
||
|
||
IpItemType2
|
||
# IP类型2:4|0|0|endpoint#range|192.168.40.1|192.168.40.50|80/88|1|itemName|itemDesc,...
|
||
[Arguments] ${str}
|
||
${obj} Create Dictionary
|
||
${left} Evaluate '${str}'[0:'${str}'.find('#')]
|
||
${client} Evaluate '${str}'['${str}'.find('#')+1:]
|
||
${values} Evaluate re.split('[|]', '${left}') re
|
||
${addrType} Convert To Integer ${values}[0]
|
||
${protocol} Convert To Integer ${values}[1]
|
||
${direction} Convert To Integer ${values}[2]
|
||
Set To Dictionary ${obj} addrType=${addrType} protocol=${protocol} direction=${direction} isSession=${values}[3]
|
||
|
||
${cValues} Evaluate re.split('[|]', '${client}') re
|
||
${clientPort1} Evaluate int(re.split('[/]', '${cValues}[3]')[0]) re
|
||
${clientPort2} Evaluate int(re.split('[/]', '${cValues}[3]')[1]) re
|
||
Set To Dictionary ${obj} clientIpFormat=${cValues}[0] clientIp1=${cValues}[1] clientIp2=${cValues}[2] clientPortFormat=range clientPort1=${clientPort1} clientPort2=${clientPort2}
|
||
# 设置默认值
|
||
Set To Dictionary ${obj} serverIpFormat=range serverIp1= serverIp2= serverPortFormat=range serverPort1=${0} serverPort2=${0}
|
||
OtherParams ${cValues} ${obj}
|
||
[Return] ${obj}
|
||
|
||
IpItemType3
|
||
# IP类型3:range|192.168.40.1|192.168.40.50|80/88&range|192.168.40.1|192.168.40.50|80/88|1|itemName|itemDesc,...
|
||
[Arguments] ${str}
|
||
${obj} Create Dictionary
|
||
# 设置默认值
|
||
Run Keyword If ':' in '${str}' Set To Dictionary ${obj} addrType=${6}
|
||
... ELSE Set To Dictionary ${obj} addrType=${Default_AddItem_AddrType}
|
||
Set To Dictionary ${obj} protocol=${Default_AddItem_Protocol} direction=${Default_AddItem_Direction} isSession=${Default_AddItem_IsSession}
|
||
|
||
${cfgs} Evaluate re.split('[&]', '${str}') re
|
||
${client} Set Variable ${cfgs}[0]
|
||
${server} Set Variable ${cfgs}[1]
|
||
|
||
${cValues} Evaluate re.split('[|]', '${client}') re
|
||
${sValues} Evaluate re.split('[|]', '${server}') re
|
||
${clientPort1} Evaluate int(re.split('[/]', '${cValues}[3]')[0]) re
|
||
${clientPort2} Evaluate int(re.split('[/]', '${cValues}[3]')[1]) re
|
||
${serverPort1} Evaluate int(re.split('[/]', '${sValues}[3]')[0]) re
|
||
${serverPort2} Evaluate int(re.split('[/]', '${sValues}[3]')[1]) re
|
||
Set To Dictionary ${obj} clientIpFormat=${cValues}[0] clientIp1=${cValues}[1] clientIp2=${cValues}[2] clientPortFormat=range clientPort1=${clientPort1} clientPort2=${clientPort2}
|
||
Set To Dictionary ${obj} serverIpFormat=${sValues}[0] serverIp1=${sValues}[1] serverIp2=${sValues}[2] serverPortFormat=range serverPort1=${serverPort1} serverPort2=${serverPort2}
|
||
|
||
OtherParams ${sValues} ${obj}
|
||
[Return] ${obj}
|
||
|
||
IpItemType4
|
||
# IP类型4:range|192.168.40.1|192.168.40.50|80/88|1|itemName|itemDesc,...
|
||
[Arguments] ${str}
|
||
${obj} Create Dictionary
|
||
# 设置默认值
|
||
Run Keyword If ':' in '${str}' Set To Dictionary ${obj} addrType=${6}
|
||
... ELSE Set To Dictionary ${obj} addrType=${4}
|
||
Set To Dictionary ${obj} protocol=${0} direction=${0} isSession=endpoint
|
||
|
||
${cValues} Evaluate re.split('[|]', '${str}') re
|
||
${clientPort1} Evaluate int(re.split('[/]', '${cValues}[3]')[0]) re
|
||
${clientPort2} Evaluate int(re.split('[/]', '${cValues}[3]')[1]) re
|
||
Set To Dictionary ${obj} clientIpFormat=${cValues}[0] clientIp1=${cValues}[1] clientIp2=${cValues}[2] clientPortFormat=range clientPort1=${clientPort1} clientPort2=${clientPort2}
|
||
# 设置默认值
|
||
Set To Dictionary ${obj} serverIpFormat=range serverIp1= serverIp2= serverPortFormat=range serverPort1=${0} serverPort2=${0}
|
||
|
||
OtherParams ${cValues} ${obj}
|
||
[Return] ${obj}
|
||
|
||
AnalysisStrItem
|
||
[Arguments] ${str} ${flag}
|
||
${obj} Create Dictionary
|
||
${list} Evaluate re.split('[|]', '${str}') re
|
||
# keywordArray
|
||
${keywords} KeywordsForEach ${list}[0]
|
||
Set To Dictionary ${obj} keywordArray=${keywords}
|
||
# district
|
||
Run Keyword If '${flag}'=='${True}' Set To Dictionary ${obj} district=${list}[1]
|
||
${index} Run Keyword If '${flag}'=='${True}' Set Variable ${2}
|
||
... ELSE Set Variable ${1}
|
||
# isHexbin
|
||
${return} ${isHexBin} Run Keyword And Ignore Error Convert To Integer ${list}[${index}]
|
||
Run Keyword If "${return}"!="FAIL" and "${isHexBin}"!="${EMPTY}" Set To Dictionary ${obj} isHexbin=${isHexBin}
|
||
... ELSE Set To Dictionary ${obj} isHexbin=${0}
|
||
|
||
# isInitialize、itemName、itemDesc
|
||
${return} ${isInitialize} Run Keyword And Ignore Error Convert To Integer ${list}[${index+1}]
|
||
Run Keyword If "${return}"!="FAIL" and "${isInitialize}"!="${EMPTY}" Set To Dictionary ${obj} isInitialize=${isInitialize}
|
||
${return} ${itemName} Run Keyword And Ignore Error Set Variable ${list}[${index+2}]
|
||
Run Keyword If "${return}"!="FAIL" and "${itemName}"!="${EMPTY}" Set To Dictionary ${obj} itemName=${itemName}
|
||
${return} ${itemDesc} Run Keyword And Ignore Error Set Variable ${list}[${index+3}]
|
||
Run Keyword If "${return}"!="FAIL" and "${itemDesc}"!="${EMPTY}" Set To Dictionary ${obj} itemDesc=${itemDesc}
|
||
[Return] ${obj}
|
||
|
||
KeywordsForEach
|
||
# 处理多关键字keyword1&keyword2&...
|
||
[Arguments] ${str}
|
||
${returnList} Create List
|
||
${list} Evaluate re.split('[&]', '${str}') re
|
||
FOR ${var} IN @{list}
|
||
Append To List ${returnList} ${var}
|
||
END
|
||
[Return] ${returnList}
|
||
|
||
OtherParams
|
||
[Documentation]
|
||
... 处理isInitialize、itemName、itemDesc参数
|
||
[Arguments] ${values} ${obj}
|
||
${return} ${isInitialize} Run Keyword And Ignore Error Convert To Integer ${values}[4]
|
||
Run Keyword If "${return}"!="FAIL" and "${isInitialize}"!="${EMPTY}" Set To Dictionary ${obj} isInitialize=${isInitialize}
|
||
${return} ${itemName} Run Keyword And Ignore Error Set Variable ${values}[5]
|
||
Run Keyword If "${return}"!="FAIL" and "${itemName}"!="${EMPTY}" Set To Dictionary ${obj} itemName=${itemName}
|
||
${return} ${itemDesc} Run Keyword And Ignore Error Set Variable ${values}[6]
|
||
Run Keyword If "${return}"!="FAIL" and "${itemDesc}"!="${EMPTY}" Set To Dictionary ${obj} itemDesc=${itemDesc}
|
||
|
||
|
||
|
||
|