安全云脑 SECMASTER-创建剧本动作:Python

时间:2023-12-06 18:52:42

Python

创建一个剧本动作,剧本名称为MyXXX,描述为This my XXXX,剧本动作类型为aopworkflow,剧本动作ID为909494e3-558e-46b6-a9eb-07a8e18ca62f,排序顺序为string。

 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
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdksecmaster.v2.region.secmaster_region import SecMasterRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdksecmaster.v2 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 = SecMasterClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(SecMasterRegion.value_of("cn-north-4")) \
        .build()

    try:
        request = CreatePlaybookActionRequest()
        listCreateActionInfobody = [
            CreateAction(
                name="MyXXX",
                description="This my XXXX",
                action_type="aopworkflow",
                action_id="909494e3-558e-46b6-a9eb-07a8e18ca62f",
                sort_order="string"
            )
        ]
        request.body = listCreateActionInfobody
        response = client.create_playbook_action(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-secmaster/CreatePlaybookAction.html