feat:(日志功能)1:schema获取;2:日志列表查询
This commit is contained in:
@@ -3,6 +3,7 @@ Test Teardown DeletePolicyAndObjectAndProfile ${policyIds} ${objectIds
|
|||||||
Resource ../../../02-Keyword/tsg_bfapi/PolicyObject.robot
|
Resource ../../../02-Keyword/tsg_bfapi/PolicyObject.robot
|
||||||
Resource ../../../02-Keyword/tsg_bfapi/policy_object/Policy.robot
|
Resource ../../../02-Keyword/tsg_bfapi/policy_object/Policy.robot
|
||||||
Resource ../../../02-Keyword/tsg_bfapi/policy_object/Object.robot
|
Resource ../../../02-Keyword/tsg_bfapi/policy_object/Object.robot
|
||||||
|
Resource ../../../02-Keyword/tsg_bfapi/policy_object/Log.robot
|
||||||
Resource ../../../02-Keyword/tsg_bfapi/Common.robot
|
Resource ../../../02-Keyword/tsg_bfapi/Common.robot
|
||||||
Library json
|
Library json
|
||||||
*** Variables ***
|
*** Variables ***
|
||||||
@@ -495,3 +496,46 @@ Policy-Verify-v1-00023
|
|||||||
${verifySession} Create Dictionary attributes=${attributes}
|
${verifySession} Create Dictionary attributes=${attributes}
|
||||||
${verifyList} Create Dictionary policyType=tsg_security verifySession=${verifySession}
|
${verifyList} Create Dictionary policyType=tsg_security verifySession=${verifySession}
|
||||||
${rescode} ${resData} VerifyPolicies ${verifyList}
|
${rescode} ${resData} VerifyPolicies ${verifyList}
|
||||||
|
Policy-log-v1-00024
|
||||||
|
${objectIds} Set Variable ${EMPTY}
|
||||||
|
Comment 查询schema
|
||||||
|
${schema_query} ${schema_type} ${default_columns} ${fields} GetLogSchema security_event_log
|
||||||
|
${queryFieldList} Create List
|
||||||
|
FOR ${field} IN @{fields}
|
||||||
|
${return} ${doc} Run Keyword And Ignore Error Get From Dictionary ${field} doc
|
||||||
|
Continue For Loop If "${return}"=="FAIL"
|
||||||
|
${return} ${allow_query} Run Keyword And Ignore Error Get From Dictionary ${doc} allow_query
|
||||||
|
Continue For Loop If "${allow_query}"=="false" or "${return}"=="FAIL"
|
||||||
|
${fieldDict} Create Dictionary name=${field['name']} type=${field['type']}
|
||||||
|
Append To List ${queryFieldList} ${fieldDict}
|
||||||
|
END
|
||||||
|
Log ${queryFieldList}
|
||||||
|
Policy-log-v1-00025
|
||||||
|
${objectIds} Set Variable ${EMPTY}
|
||||||
|
Comment 查询schema
|
||||||
|
${schema_query} ${schema_type} ${default_columns} ${fields} GetLogSchema security_event_log
|
||||||
|
|
||||||
|
${filters} Get From Dictionary ${schema_query} filters
|
||||||
|
Log ${filters}
|
||||||
|
Policy-log-v1-00026
|
||||||
|
${objectIds} Set Variable ${EMPTY}
|
||||||
|
Comment 查询schema
|
||||||
|
${schema_query} ${schema_type} ${default_columns} ${fields} GetLogSchema security_event_log
|
||||||
|
Comment 处理schema,构造查询条件
|
||||||
|
${queryFieldList} Create List
|
||||||
|
FOR ${field} IN @{fields}
|
||||||
|
log ${field}
|
||||||
|
${return} ${doc} Run Keyword And Ignore Error Get From Dictionary ${field} doc
|
||||||
|
Continue For Loop If "${return}"=="FAIL"
|
||||||
|
${return} ${allow_query} Run Keyword And Ignore Error Get From Dictionary ${doc} allow_query
|
||||||
|
Continue For Loop If "${allow_query}"=="false" or "${return}"=="FAIL"
|
||||||
|
${fieldDict} Create Dictionary name=${field['name']} type=${field['type']}
|
||||||
|
Append To List ${queryFieldList} ${fieldDict}
|
||||||
|
END
|
||||||
|
${params} Create Dictionary pageSize=${10} logType=security_event_log
|
||||||
|
... start_common_recv_time=2020-06-01 00:00:00
|
||||||
|
... end_common_recv_time=2020-06-24 00:00:00
|
||||||
|
... fields=common_log_id|long,http_url|string,common_client_ip|string,common_client_port|int,common_server_ip|string,common_server_port|int
|
||||||
|
... conditions=common_server_port|int|in|${80}^${8080}
|
||||||
|
... orderBy=common_server_ip|true
|
||||||
|
${resData} QueryLogList ${params}
|
||||||
114
02-Keyword/tsg_bfapi/policy_object/Log.robot
Normal file
114
02-Keyword/tsg_bfapi/policy_object/Log.robot
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
*** Settings ***
|
||||||
|
Library json
|
||||||
|
Library Collections
|
||||||
|
Library RequestsLibrary
|
||||||
|
Resource ../../../03-Variable/BifangApiVariable.txt
|
||||||
|
Resource ../../../02-Keyword/tsg_bfapi/policy_file_interface/FunctionalKeywords.robot
|
||||||
|
Resource ../Common.robot
|
||||||
|
*** Variables ***
|
||||||
|
${logUrl} /log
|
||||||
|
*** Keywords ***
|
||||||
|
GetLogSchema
|
||||||
|
[Documentation]
|
||||||
|
... 日志schema查询
|
||||||
|
... logType 日志类型
|
||||||
|
... resData schema数据
|
||||||
|
[Arguments] ${logType}
|
||||||
|
${response} BaseFormRequest ${logUrl}/schema logType=${logType} ${version}
|
||||||
|
${rescode} Set Variable ${response['code']}
|
||||||
|
Should Be Equal As Integers ${rescode} 200
|
||||||
|
${resData} Set Variable ${response['data']}
|
||||||
|
${schema_query} Get From Dictionary ${resData['doc']} schema_query
|
||||||
|
${schema_type} Get From Dictionary ${resData['doc']} schema_type
|
||||||
|
${default_columns} Get From Dictionary ${resData['doc']} default_columns
|
||||||
|
[Return] ${schema_query} ${schema_type} ${default_columns} ${resData['fields']}
|
||||||
|
QueryLogList
|
||||||
|
[Documentation]
|
||||||
|
... 日志列表查询
|
||||||
|
... params字典列表
|
||||||
|
... 注意如下字典字段格式
|
||||||
|
... orderBy=field名字1|true,field名字2|false
|
||||||
|
... fields=name1|type,name2|type
|
||||||
|
... conditions=field1|type|symbol|value1^value2,field2|type|symbol|value3^value4
|
||||||
|
... value1^value2是使用^分隔的字符串解析后为[value1,value2]格式的数组
|
||||||
|
[Arguments] ${params}
|
||||||
|
Should Not Be Empty ${params}
|
||||||
|
${return} ${pageSize} Run Keyword And Ignore Error Get From Dictionary ${params} pageSize
|
||||||
|
Run Keyword If "${return}"=="PASS" and "${pageSize}"=="${EMPTY}" Remove From Dictionary ${params} pageSize
|
||||||
|
${return} ${pageNo} Run Keyword And Ignore Error Get From Dictionary ${params} pageNo
|
||||||
|
Run Keyword If "${return}"=="PASS" and "${pageNo}"=="${EMPTY}" Remove From Dictionary ${params} pageNo
|
||||||
|
Dictionary Should Contain Key ${params} logType
|
||||||
|
${logType} Get From Dictionary ${params} logType
|
||||||
|
#处理排序
|
||||||
|
${return} ${orderBy} Run Keyword And Ignore Error Get From Dictionary ${params} orderBy
|
||||||
|
${orderBy} Run Keyword If "${return}"=="FAIL" or "${orderBy}"=="${EMPTY}" Create List
|
||||||
|
... ELSE ManageOrderBy ${orderBy}
|
||||||
|
Set To Dictionary ${params} orderBy=${orderBy}
|
||||||
|
|
||||||
|
${fields} Get From Dictionary ${params} fields
|
||||||
|
Should Not Be Empty ${fields}
|
||||||
|
${fields} ManageFields ${fields}
|
||||||
|
Set To Dictionary ${params} fields=${fields}
|
||||||
|
|
||||||
|
${start_common_recv_time} Get From Dictionary ${params} start_common_recv_time
|
||||||
|
Should Not Be Empty ${start_common_recv_time}
|
||||||
|
${end_common_recv_time} Get From Dictionary ${params} end_common_recv_time
|
||||||
|
Should Not Be Empty ${end_common_recv_time}
|
||||||
|
|
||||||
|
${return} ${userTags} Run Keyword And Ignore Error Get From Dictionary ${params} userTags
|
||||||
|
Run Keyword If "${return}"=="PASS" and "${userTags}"=="${EMPTY}" Remove From Dictionary ${params} userTags
|
||||||
|
${return} ${conditions} Run Keyword And Ignore Error Get From Dictionary ${params} conditions
|
||||||
|
${conditions} Run Keyword If "${return}"=="PASS" and "${conditions}"!="${EMPTY}" ManageConditions ${conditions}
|
||||||
|
... ELSE Create List
|
||||||
|
Set To Dictionary ${params} conditions=${conditions}
|
||||||
|
${bodyJson} json.Dumps ${params} ensure_ascii=False
|
||||||
|
${response} BasePostRequestForV2 ${logUrl}/list ${bodyJson} ${version}
|
||||||
|
${rescode} Set Variable ${response['code']}
|
||||||
|
Should Be Equal As Integers ${rescode} 200
|
||||||
|
${resData} Set Variable ${response['data']}
|
||||||
|
[Return] ${resData}
|
||||||
|
ManageOrderBy
|
||||||
|
[Documentation]
|
||||||
|
...
|
||||||
|
[Arguments] ${orderBy}
|
||||||
|
${orderByList} Create List
|
||||||
|
@{orderByArr} Split String ${orderBy} ,
|
||||||
|
FOR ${order} IN @{orderByArr}
|
||||||
|
@{orderByArr} Split String ${order} |
|
||||||
|
${dict} Create Dictionary field=${orderByArr}[0] asc=${orderByArr}[1]
|
||||||
|
Append To List ${orderByList} ${dict}
|
||||||
|
END
|
||||||
|
[Return] ${orderByList}
|
||||||
|
ManageFields
|
||||||
|
[Arguments] ${fields}
|
||||||
|
${fieldsList} Create List
|
||||||
|
@{fieldsArr} Split String ${fields} ,
|
||||||
|
FOR ${field} IN @{fieldsArr}
|
||||||
|
@{fieldsArr} Split String ${field} |
|
||||||
|
${dict} Create Dictionary name=${fieldsArr}[0] type=${fieldsArr}[1]
|
||||||
|
Append To List ${fieldsList} ${dict}
|
||||||
|
END
|
||||||
|
[Return] ${fieldsList}
|
||||||
|
ManageConditions
|
||||||
|
[Arguments] ${conditions}
|
||||||
|
${conditionsList} Create List
|
||||||
|
@{conditionsArr} Split String ${conditions} ,
|
||||||
|
FOR ${condition} IN @{conditionsArr}
|
||||||
|
@{conditionArr} Split String ${condition} |
|
||||||
|
@{value} Split String ${conditionArr}[3] ^
|
||||||
|
${type} Set Variable ${conditionArr}[1]
|
||||||
|
${value} Run Keyword If "${type}"=="int" or "${type}"=="long" toDigitList ${value} ${type}
|
||||||
|
... ELSE Set Variable ${value}
|
||||||
|
${dict} Create Dictionary field=${conditionArr}[0] type=${type} symbol=${conditionArr}[2] value=${value}
|
||||||
|
Append To List ${conditionsList} ${dict}
|
||||||
|
END
|
||||||
|
[Return] ${conditionsList}
|
||||||
|
toDigitList
|
||||||
|
[Arguments] ${values} ${type}
|
||||||
|
${list} Create List
|
||||||
|
FOR ${var} IN @{values}
|
||||||
|
${var} Run Keyword If "${type}"=="int" Evaluate int('${var}')
|
||||||
|
... ELSE Evaluate long('${var}')
|
||||||
|
Append To List ${list} ${var}
|
||||||
|
END
|
||||||
|
[Return] ${list}
|
||||||
Reference in New Issue
Block a user