From e01ed2c1a108d6bb4e329d31380a6a6751457d4d Mon Sep 17 00:00:00 2001 From: wangxin Date: Mon, 29 Jun 2020 16:21:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=AD=96=E7=95=A5=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E5=AF=BC=E5=85=A5)1=EF=BC=9Aurl=E5=AF=B9=E8=B1=A1=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=B7=B2=E5=AD=98=E5=9C=A8url=20item=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E5=8A=A0=E4=B8=8A=E5=BE=85=E5=AF=BC=E5=85=A5=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E5=B0=8F=E4=BA=8E100=E4=B8=87=E6=96=B9?= =?UTF-8?q?=E5=8F=AF=E5=AF=BC=E5=85=A5;2=E5=85=B6=E4=BB=96=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=AF=B9=E8=B1=A1=E5=AF=BC=E5=85=A5=E6=80=BB=E6=95=B0?= =?UTF-8?q?=E5=B0=8F=E4=BA=8E10=E4=B8=87=E6=96=B9=E5=8F=AF=E5=AF=BC?= =?UTF-8?q?=E5=85=A5;3:fqdn=5Fcategory=E6=8E=92=E9=99=A4=E9=A2=84=E7=BD=AE?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E5=90=8E=E5=B0=8F=E4=BA=8E10=E4=B8=87?= =?UTF-8?q?=E6=96=B9=E5=8F=AF=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tsg_bfapi/policy_object/Object.robot | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/02-Keyword/tsg_bfapi/policy_object/Object.robot b/02-Keyword/tsg_bfapi/policy_object/Object.robot index 7df0af3..e14ba07 100644 --- a/02-Keyword/tsg_bfapi/policy_object/Object.robot +++ b/02-Keyword/tsg_bfapi/policy_object/Object.robot @@ -70,6 +70,20 @@ GetObjectItems Append To List ${itemIds} ${item['itemId']} END [Return] ${rescode} ${itemIds} ${data['list']} +GetObjectItems1 + [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']} + [Return] ${rescode} ${data} DeleteObjects [Documentation] ... 删除策略对象 @@ -98,6 +112,14 @@ ImportObject File Should Not Be Empty ${path}/${filePath}/${fileName} ${size} Get File Size ${path}/${filePath}/${fileName} Should Not Be Empty ${objectType} + #获取Item 的总数 + ${total} GetItemNum ${objectType} ${objectSubType} + #获取导入文件中的总行数 + ${lines} CountLines ${path}/${filePath}/${fileName} + #总数超过一定数据量测试不通过 + ${total1} Evaluate ${total}+${lines} + Run Keyword If "${objectType}"=="url" and ${total1}>1000000 Fail 当前已经存在item个数${total},待导入个数${lines},总数超过100万条! + ... ELSE IF ${total1}>100000 Fail 当前已经存在item个数${total},待导入个数${lines},总数超过10万条! ${objectSubType} Run Keyword If "${objectType}"=="ip" and "${objectSubType}"=="${EMPTY}" Set Variable endpoint ... ELSE Set Variable ${objectSubType} ${subfix} Fetch From Right ${fileName} . @@ -126,4 +148,37 @@ ExportObject 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} \ No newline at end of file + [Return] ${response} +GetItemNum + [Documentation] + ... 获取策略对象单元总数 + ... + [Arguments] ${objectType} ${objectSubType} + ${getTotal} Create Dictionary pageNo=${1} pageSize=${1} + Run Keyword If "${objectType}"=="ip" and "${objectSubType}"=="endpoint" Set To Dictionary ${getTotal} itemType=IP + ... ELSE IF "${objectType}"=="ip" and "${objectSubType}"=="geo_location" Set To Dictionary ${getTotal} itemType=geo_location + ... ELSE IF "${objectType}"=="ip" and "${objectSubType}"=="as_number" Set To Dictionary ${getTotal} itemType=as_number + ... ELSE IF "${objectType}"=="url" Set To Dictionary ${getTotal} itemType=URL + ... ELSE Set To Dictionary ${getTotal} itemType=${objectType} + ${rescode} ${data} GetObjectItems1 ${getTotal} + ${total} Set Variable ${data['total']} + Run Keyword If "${objectType}"=="fqdn_category" Set To Dictionary ${getTotal} isInitialize=1 + ${rescode} ${data} Run Keyword If "${objectType}"=="fqdn_category" GetObjectItems1 ${getTotal} + ... ELSE Set Variable ${rescode} ${data} + ${total} Run Keyword If "${objectType}"=="fqdn_category" Evaluate ${total} - ${data['total']} + ... ELSE Set Variable ${total} + [Return] ${total} +CountLines + [Documentation] + ... 获取文件总行数 + [Arguments] ${file} + ${count} Set Variable ${0} + ${openFile} Evaluate enumerate(open(r"${file}",'r')) + FOR ${line} IN @{openFile} + ${val} Run Keyword If "${line[0]}"=="0" Set Variable ${line[1]} ELSE Set Variable ${EMPTY} + ${match} Get Regexp Matches ${val} ^--> + ${len} Get Length ${match} + ${count} Run Keyword If "${line[0]}"=="0" and ${len}>0 Set Variable ${count} + ... ELSE Evaluate ${count}+1 + END + [Return] ${count} \ No newline at end of file