云审计服务 CTS-修改关键操作通知:Python

时间:2023-12-22 17:31:29

Python

修改关键操作通知请求样例。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcts.v3.region.cts_region import CtsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcts.v3 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.getenv("CLOUD_SDK_AK")
    sk = os.getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = CtsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CtsRegion.value_of("cn-north-4")) \
        .build()

    try:
        request = UpdateNotificationRequest()
        listUserListNotifyUserList = [
            "test2",
            "test3"
        ]
        listUserListNotifyUserList1 = [
            "test",
            "test1"
        ]
        listNotifyUserListbody = [
            NotificationUsers(
                user_group="admin",
                user_list=listUserListNotifyUserList1
            ),
            NotificationUsers(
                user_group="CTS view",
                user_list=listUserListNotifyUserList
            )
        ]
        listTraceNamesOperations = [
            "deletePolicyGroup",
            "updatePolicyGroup",
            "createPolicyGroup"
        ]
        listTraceNamesOperations1 = [
            "deleteNotification",
            "updateNotification"
        ]
        listTraceNamesOperations2 = [
            "createTracker",
            "deleteTracker"
        ]
        listOperationsbody = [
            Operations(
                service_type="CTS",
                resource_type="tracker",
                trace_names=listTraceNamesOperations2
            ),
            Operations(
                service_type="CTS",
                resource_type="notification",
                trace_names=listTraceNamesOperations1
            ),
            Operations(
                service_type="AOM",
                resource_type="pe",
                trace_names=listTraceNamesOperations
            )
        ]
        request.body = UpdateNotificationRequestBody(
            notification_id="6d4a09bb-aa8e-40db-9e87-0d5e203823a8",
            topic_id="urn:smn:{regionid}:24edf66e79d04187acb99a463e610764:foo",
            status="enabled",
            notify_user_list=listNotifyUserListbody,
            operations=listOperationsbody,
            operation_type="customized",
            notification_name="keyOperate_info_cfwy"
        )
        response = client.update_notification(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
support.huaweicloud.com/api-cts/cts_api_0313.html