398 lines
15 KiB
Python
398 lines
15 KiB
Python
|
# coding: utf-8
|
|||
|
|
|||
|
from __future__ import absolute_import
|
|||
|
|
|||
|
import datetime
|
|||
|
import re
|
|||
|
import importlib
|
|||
|
|
|||
|
import six
|
|||
|
|
|||
|
from huaweicloudsdkcore.client import Client
|
|||
|
from huaweicloudsdkcore.exceptions import exceptions
|
|||
|
from huaweicloudsdkcore.utils import http_utils
|
|||
|
|
|||
|
|
|||
|
class CtsAsyncClient(Client):
|
|||
|
"""
|
|||
|
:param configuration: .Configuration object for this client
|
|||
|
:param pool_threads: The number of threads to use for async requests
|
|||
|
to the API. More threads means more concurrent API requests.
|
|||
|
"""
|
|||
|
|
|||
|
PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types
|
|||
|
NATIVE_TYPES_MAPPING = {
|
|||
|
'int': int,
|
|||
|
'long': int if six.PY3 else long,
|
|||
|
'float': float,
|
|||
|
'str': str,
|
|||
|
'bool': bool,
|
|||
|
'date': datetime.date,
|
|||
|
'datetime': datetime.datetime,
|
|||
|
'object': object,
|
|||
|
}
|
|||
|
|
|||
|
def __init__(self):
|
|||
|
super(CtsAsyncClient, self).__init__()
|
|||
|
self.model_package = importlib.import_module("huaweicloudsdkcts.v1.model")
|
|||
|
self.preset_headers = {'User-Agent': 'HuaweiCloud-SDK-Python'}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
def create_tracker_async(self, request):
|
|||
|
"""创建追踪器
|
|||
|
|
|||
|
云审计服务开通后系统会自动创建一个追踪器,用来关联系统记录的所有操作。目前,一个云账户在一个Region下仅支持创建一个追踪器。 云审计服务支持在管理控制台查询近7天内的操作记录。如需保存更长时间的操作记录,您可以在创建追踪器之后通过对象存储服务(Object Storage Service,以下简称OBS)将操作记录实时保存至OBS桶中。
|
|||
|
|
|||
|
:param CreateTrackerRequest request
|
|||
|
:return: CreateTrackerResponse
|
|||
|
"""
|
|||
|
return self.create_tracker_with_http_info(request)
|
|||
|
|
|||
|
def create_tracker_with_http_info(self, request):
|
|||
|
"""创建追踪器
|
|||
|
|
|||
|
云审计服务开通后系统会自动创建一个追踪器,用来关联系统记录的所有操作。目前,一个云账户在一个Region下仅支持创建一个追踪器。 云审计服务支持在管理控制台查询近7天内的操作记录。如需保存更长时间的操作记录,您可以在创建追踪器之后通过对象存储服务(Object Storage Service,以下简称OBS)将操作记录实时保存至OBS桶中。
|
|||
|
|
|||
|
:param CreateTrackerRequest request
|
|||
|
:return: tuple(CreateTrackerResponse, status_code(int), headers(HTTPHeaderDict))
|
|||
|
"""
|
|||
|
|
|||
|
all_params = ['create_tracker_request_body']
|
|||
|
all_params.append('async_req')
|
|||
|
all_params.append('_return_http_data_only')
|
|||
|
all_params.append('_preload_content')
|
|||
|
all_params.append('_request_timeout')
|
|||
|
|
|||
|
local_var_params = {}
|
|||
|
for attr in request.attribute_map:
|
|||
|
if hasattr(request, attr):
|
|||
|
local_var_params[attr] = getattr(request, attr)
|
|||
|
|
|||
|
collection_formats = {}
|
|||
|
|
|||
|
path_params = {}
|
|||
|
|
|||
|
query_params = []
|
|||
|
|
|||
|
header_params = {}
|
|||
|
|
|||
|
form_params = []
|
|||
|
|
|||
|
body_params = None
|
|||
|
if 'body' in local_var_params:
|
|||
|
body_params = local_var_params['body']
|
|||
|
|
|||
|
header_params['Accept'] = http_utils.select_header_accept(
|
|||
|
['*/*', 'application/json'])
|
|||
|
|
|||
|
header_params['Content-Type'] = http_utils.select_header_content_type(
|
|||
|
['application/json;charset=UTF-8'])
|
|||
|
auth_settings = []
|
|||
|
|
|||
|
return self.call_api(
|
|||
|
'/v1.0/{project_id}/tracker', 'POST',
|
|||
|
path_params,
|
|||
|
query_params,
|
|||
|
header_params,
|
|||
|
body=body_params,
|
|||
|
post_params=form_params,
|
|||
|
response_type='CreateTrackerResponse',
|
|||
|
auth_settings=auth_settings,
|
|||
|
collection_formats=collection_formats,
|
|||
|
request_type=request.__class__.__name__)
|
|||
|
|
|||
|
def delete_tracker_async(self, request):
|
|||
|
"""删除追踪器
|
|||
|
|
|||
|
云审计服务支持删除已创建的追踪器。删除追踪器对已有的操作记录没有影响,当您重新开通云审计服务后,依旧可以查看已有的操作记录。
|
|||
|
|
|||
|
:param DeleteTrackerRequest request
|
|||
|
:return: None
|
|||
|
"""
|
|||
|
return self.delete_tracker_with_http_info(request)
|
|||
|
|
|||
|
def delete_tracker_with_http_info(self, request):
|
|||
|
"""删除追踪器
|
|||
|
|
|||
|
云审计服务支持删除已创建的追踪器。删除追踪器对已有的操作记录没有影响,当您重新开通云审计服务后,依旧可以查看已有的操作记录。
|
|||
|
|
|||
|
:param DeleteTrackerRequest request
|
|||
|
:return: None
|
|||
|
"""
|
|||
|
|
|||
|
all_params = ['tracker_name']
|
|||
|
all_params.append('async_req')
|
|||
|
all_params.append('_return_http_data_only')
|
|||
|
all_params.append('_preload_content')
|
|||
|
all_params.append('_request_timeout')
|
|||
|
|
|||
|
local_var_params = {}
|
|||
|
for attr in request.attribute_map:
|
|||
|
if hasattr(request, attr):
|
|||
|
local_var_params[attr] = getattr(request, attr)
|
|||
|
|
|||
|
collection_formats = {}
|
|||
|
|
|||
|
path_params = {}
|
|||
|
|
|||
|
query_params = []
|
|||
|
if 'tracker_name' in local_var_params:
|
|||
|
query_params.append(('tracker_name', local_var_params['tracker_name']))
|
|||
|
|
|||
|
header_params = {}
|
|||
|
|
|||
|
form_params = []
|
|||
|
|
|||
|
body_params = None
|
|||
|
|
|||
|
|
|||
|
auth_settings = []
|
|||
|
|
|||
|
return self.call_api(
|
|||
|
'/v1.0/{project_id}/tracker', 'DELETE',
|
|||
|
path_params,
|
|||
|
query_params,
|
|||
|
header_params,
|
|||
|
body=body_params,
|
|||
|
post_params=form_params,
|
|||
|
response_type=None,
|
|||
|
auth_settings=auth_settings,
|
|||
|
collection_formats=collection_formats,
|
|||
|
request_type=request.__class__.__name__)
|
|||
|
|
|||
|
def list_traces_v2_async(self, request):
|
|||
|
"""查询事件列表(v2.0)
|
|||
|
|
|||
|
通过事件列表查询接口,可以查出系统记录的7天内资源操作记录。
|
|||
|
|
|||
|
:param ListTracesV2Request request
|
|||
|
:return: ListTracesV2Response
|
|||
|
"""
|
|||
|
return self.list_traces_v2_with_http_info(request)
|
|||
|
|
|||
|
def list_traces_v2_with_http_info(self, request):
|
|||
|
"""查询事件列表(v2.0)
|
|||
|
|
|||
|
通过事件列表查询接口,可以查出系统记录的7天内资源操作记录。
|
|||
|
|
|||
|
:param ListTracesV2Request request
|
|||
|
:return: tuple(ListTracesV2Response, status_code(int), headers(HTTPHeaderDict))
|
|||
|
"""
|
|||
|
|
|||
|
all_params = ['tracker_name', 'service_type', 'user', '_from', 'limit', 'next', 'resource_id', 'resource_name', 'resource_type', 'to', 'trace_id', 'trace_name', 'trace_rating']
|
|||
|
all_params.append('async_req')
|
|||
|
all_params.append('_return_http_data_only')
|
|||
|
all_params.append('_preload_content')
|
|||
|
all_params.append('_request_timeout')
|
|||
|
|
|||
|
local_var_params = {}
|
|||
|
for attr in request.attribute_map:
|
|||
|
if hasattr(request, attr):
|
|||
|
local_var_params[attr] = getattr(request, attr)
|
|||
|
|
|||
|
collection_formats = {}
|
|||
|
|
|||
|
path_params = {}
|
|||
|
if 'tracker_name' in local_var_params:
|
|||
|
path_params['tracker_name'] = local_var_params['tracker_name']
|
|||
|
|
|||
|
query_params = []
|
|||
|
if 'service_type' in local_var_params:
|
|||
|
query_params.append(('service_type', local_var_params['service_type']))
|
|||
|
if 'user' in local_var_params:
|
|||
|
query_params.append(('user', local_var_params['user']))
|
|||
|
if '_from' in local_var_params:
|
|||
|
query_params.append(('from', local_var_params['_from']))
|
|||
|
if 'limit' in local_var_params:
|
|||
|
query_params.append(('limit', local_var_params['limit']))
|
|||
|
if 'next' in local_var_params:
|
|||
|
query_params.append(('next', local_var_params['next']))
|
|||
|
if 'resource_id' in local_var_params:
|
|||
|
query_params.append(('resource_id', local_var_params['resource_id']))
|
|||
|
if 'resource_name' in local_var_params:
|
|||
|
query_params.append(('resource_name', local_var_params['resource_name']))
|
|||
|
if 'resource_type' in local_var_params:
|
|||
|
query_params.append(('resource_type', local_var_params['resource_type']))
|
|||
|
if 'to' in local_var_params:
|
|||
|
query_params.append(('to', local_var_params['to']))
|
|||
|
if 'trace_id' in local_var_params:
|
|||
|
query_params.append(('trace_id', local_var_params['trace_id']))
|
|||
|
if 'trace_name' in local_var_params:
|
|||
|
query_params.append(('trace_name', local_var_params['trace_name']))
|
|||
|
if 'trace_rating' in local_var_params:
|
|||
|
query_params.append(('trace_rating', local_var_params['trace_rating']))
|
|||
|
|
|||
|
header_params = {}
|
|||
|
|
|||
|
form_params = []
|
|||
|
|
|||
|
body_params = None
|
|||
|
|
|||
|
header_params['Accept'] = http_utils.select_header_accept(
|
|||
|
['*/*', 'application/json'])
|
|||
|
|
|||
|
auth_settings = []
|
|||
|
|
|||
|
return self.call_api(
|
|||
|
'/v2.0/{project_id}/{tracker_name}/trace', 'GET',
|
|||
|
path_params,
|
|||
|
query_params,
|
|||
|
header_params,
|
|||
|
body=body_params,
|
|||
|
post_params=form_params,
|
|||
|
response_type='ListTracesV2Response',
|
|||
|
auth_settings=auth_settings,
|
|||
|
collection_formats=collection_formats,
|
|||
|
request_type=request.__class__.__name__)
|
|||
|
|
|||
|
def list_tracker_async(self, request):
|
|||
|
"""查询追踪器
|
|||
|
|
|||
|
开通云审计服务成功后,您可以在追踪器信息页面查看系统自动创建的追踪器的详细信息。详细信息主要包括追踪器名称,用于存储操作事件的OBS桶名称和OBS桶中的事件文件前缀。
|
|||
|
|
|||
|
:param ListTrackerRequest request
|
|||
|
:return: ListTrackerResponse
|
|||
|
"""
|
|||
|
return self.list_tracker_with_http_info(request)
|
|||
|
|
|||
|
def list_tracker_with_http_info(self, request):
|
|||
|
"""查询追踪器
|
|||
|
|
|||
|
开通云审计服务成功后,您可以在追踪器信息页面查看系统自动创建的追踪器的详细信息。详细信息主要包括追踪器名称,用于存储操作事件的OBS桶名称和OBS桶中的事件文件前缀。
|
|||
|
|
|||
|
:param ListTrackerRequest request
|
|||
|
:return: tuple(ListTrackerResponse, status_code(int), headers(HTTPHeaderDict))
|
|||
|
"""
|
|||
|
|
|||
|
all_params = ['tracker_name']
|
|||
|
all_params.append('async_req')
|
|||
|
all_params.append('_return_http_data_only')
|
|||
|
all_params.append('_preload_content')
|
|||
|
all_params.append('_request_timeout')
|
|||
|
|
|||
|
local_var_params = {}
|
|||
|
for attr in request.attribute_map:
|
|||
|
if hasattr(request, attr):
|
|||
|
local_var_params[attr] = getattr(request, attr)
|
|||
|
|
|||
|
collection_formats = {}
|
|||
|
|
|||
|
path_params = {}
|
|||
|
|
|||
|
query_params = []
|
|||
|
if 'tracker_name' in local_var_params:
|
|||
|
query_params.append(('tracker_name', local_var_params['tracker_name']))
|
|||
|
|
|||
|
header_params = {}
|
|||
|
|
|||
|
form_params = []
|
|||
|
|
|||
|
body_params = None
|
|||
|
|
|||
|
header_params['Accept'] = http_utils.select_header_accept(
|
|||
|
['*/*', 'application/json'])
|
|||
|
|
|||
|
auth_settings = []
|
|||
|
|
|||
|
return self.call_api(
|
|||
|
'/v1.0/{project_id}/tracker', 'GET',
|
|||
|
path_params,
|
|||
|
query_params,
|
|||
|
header_params,
|
|||
|
body=body_params,
|
|||
|
post_params=form_params,
|
|||
|
response_type='ListTrackerResponse',
|
|||
|
auth_settings=auth_settings,
|
|||
|
collection_formats=collection_formats,
|
|||
|
request_type=request.__class__.__name__)
|
|||
|
|
|||
|
def update_tracker_async(self, request):
|
|||
|
"""修改追踪器
|
|||
|
|
|||
|
云审计服务支持修改已创建追踪器的配置项,包括OBS桶转储、关键事件通知、事件转储加密、通过LTS对管理类事件进行检索、事件文件完整性校验以及追踪器启停状态等相关参数,修改追踪器对已有的操作记录没有影响。修改追踪器完成后,系统立即以新的规则开始记录操作。
|
|||
|
|
|||
|
:param UpdateTrackerRequest request
|
|||
|
:return: None
|
|||
|
"""
|
|||
|
return self.update_tracker_with_http_info(request)
|
|||
|
|
|||
|
def update_tracker_with_http_info(self, request):
|
|||
|
"""修改追踪器
|
|||
|
|
|||
|
云审计服务支持修改已创建追踪器的配置项,包括OBS桶转储、关键事件通知、事件转储加密、通过LTS对管理类事件进行检索、事件文件完整性校验以及追踪器启停状态等相关参数,修改追踪器对已有的操作记录没有影响。修改追踪器完成后,系统立即以新的规则开始记录操作。
|
|||
|
|
|||
|
:param UpdateTrackerRequest request
|
|||
|
:return: None
|
|||
|
"""
|
|||
|
|
|||
|
all_params = ['tracker_name', 'update_tracker_request_body']
|
|||
|
all_params.append('async_req')
|
|||
|
all_params.append('_return_http_data_only')
|
|||
|
all_params.append('_preload_content')
|
|||
|
all_params.append('_request_timeout')
|
|||
|
|
|||
|
local_var_params = {}
|
|||
|
for attr in request.attribute_map:
|
|||
|
if hasattr(request, attr):
|
|||
|
local_var_params[attr] = getattr(request, attr)
|
|||
|
|
|||
|
collection_formats = {}
|
|||
|
|
|||
|
path_params = {}
|
|||
|
if 'tracker_name' in local_var_params:
|
|||
|
path_params['tracker_name'] = local_var_params['tracker_name']
|
|||
|
|
|||
|
query_params = []
|
|||
|
|
|||
|
header_params = {}
|
|||
|
|
|||
|
form_params = []
|
|||
|
|
|||
|
body_params = None
|
|||
|
if 'body' in local_var_params:
|
|||
|
body_params = local_var_params['body']
|
|||
|
|
|||
|
|
|||
|
header_params['Content-Type'] = http_utils.select_header_content_type(
|
|||
|
['application/json;charset=UTF-8'])
|
|||
|
auth_settings = []
|
|||
|
|
|||
|
return self.call_api(
|
|||
|
'/v1.0/{project_id}/tracker/{tracker_name}', 'PUT',
|
|||
|
path_params,
|
|||
|
query_params,
|
|||
|
header_params,
|
|||
|
body=body_params,
|
|||
|
post_params=form_params,
|
|||
|
response_type=None,
|
|||
|
auth_settings=auth_settings,
|
|||
|
collection_formats=collection_formats,
|
|||
|
request_type=request.__class__.__name__)
|
|||
|
|
|||
|
|
|||
|
def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None,
|
|||
|
body=None, post_params=None, response_type=None, auth_settings=None, collection_formats=None,
|
|||
|
request_type=None):
|
|||
|
"""Makes the HTTP request and returns deserialized data.
|
|||
|
|
|||
|
:param resource_path: Path to method endpoint.
|
|||
|
:param method: Method to call.
|
|||
|
:param path_params: Path parameters in the url.
|
|||
|
:param query_params: Query parameters in the url.
|
|||
|
:param header_params: Header parameters to be
|
|||
|
placed in the request header.
|
|||
|
:param body: Request body.
|
|||
|
:param post_params dict: Request post form parameters,
|
|||
|
for `application/x-www-form-urlencoded`, `multipart/form-data`.
|
|||
|
:param auth_settings list: Auth Settings names for the request.
|
|||
|
:param response_type: Response data type.
|
|||
|
:param collection_formats: dict of collection formats for path, query,
|
|||
|
header, and post parameters.
|
|||
|
:return:
|
|||
|
Return the response directly.
|
|||
|
"""
|
|||
|
return self.do_http_request(method, resource_path, path_params,
|
|||
|
query_params, header_params, body, post_params,
|
|||
|
response_type, collection_formats, request_type, True)
|