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

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

Python

创建一个剧本版本,剧本版本所属工作空间ID为string,剧本ID为909494e3-558e-46b6-a9eb-07a8e18ca62f,数据类ID为909494e3-558e-46b6-a9eb-07a8e18ca62f,规则为启用。

 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
# 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 = CreatePlaybookVersionRequest()
        listActionsbody = [
            ActionInfo(
                id="909494e3-558e-46b6-a9eb-07a8e18ca62f",
                name="MyXXX",
                description="This my XXXX",
                action_type="Workflow",
                action_id="909494e3-558e-46b6-a9eb-07a8e18ca62f",
                playbook_id="string",
                playbook_version_id="string",
                project_id="string"
            )
        ]
        request.body = CreatePlaybookVersionInfo(
            action_strategy="sync",
            dataobject_delete=True,
            dataobject_update=True,
            dataobject_create=True,
            trigger_type="event",
            rule_id="4185bbd2-9d18-4362-92cb-46df0b24fe4e",
            rule_enable=True,
            dataclass_id="909494e3-558e-46b6-a9eb-07a8e18ca62f",
            actions=listActionsbody,
            playbook_id="909494e3-558e-46b6-a9eb-07a8e18ca62f",
            workspace_id="string",
            description="This my XXXX"
        )
        response = client.create_playbook_version(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/CreatePlaybookVersion.html