[SDK] を使用すると、Google Cloud Platform (GCP) コネクタを追加したり、仮想マシン (VM) をGCPからWorkload Securityに同期したりできます。概要については、Google Cloud Platformサービスアカウントの作成 を参照してください。
開始する前に、Workload Securityで使用するためのGCPサービスアカウントを準備する必要があります。
GCPコネクタを追加するには、次の手順を実行します。
手順
GcpConnector
オブジェクトを作成し、名前とサービスアカウントを設定します。名前とサービスアカウントは必須プロパティです。名前の長さは255文字を超えることはできません。GcpConnectorsApi
オブジェクトを作成し、それを使用してWorkload SecurityでGcpConnector
を作成します。設定できるプロパティのリストについては、APIレファレンスのCreate a Computer操作を参照してください。def create_gcp_connector(api, configuration, api_version, api_exception, name, service_account): api_instance = api.GCPConnectorsApi(api.ApiClient(configuration)) gcp_connector = api.GCPConnector() gcp_connector.name = name gcp_connector.service_account = service_account api_response = api_instance.create_gcp_connector(gcp_connector, api_version) return api_response
GCPコネクタの同期処理を送信する
GCPコネクタが正常に作成されたら、同期をトリガーするようにGCPコネクタに指示できます。
同期処理を送信するには、次の手順を実行します。
手順
Action
オブジェクトを作成し、タイプをsynchronize
に設定します。タイプは必須プロパティです。- 特定のGCPコネクタIDによるアクションをWorkload Securityに送信するために、
GcpConnectorActionsApi
オブジェクトを作成して使用します。def create_gcp_connector_action(api, configuration, api_version, api_exception, gcp_connector_id): api_instance = api.GCPConnectorActionsApi(api.ApiClient(configuration)) gcp_connector_action = api.Action() gcp_connector_action.type = "synchronize" api_response = api_instance.create_gcp_connector_action(gcp_connector_id, gcp_connector_action, api_version) return api_response