ソースの更新
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
ソースを更新する方法を説明します。
コードサンプル
Go
Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Java
Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Node.js
Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Python
Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],[],[],[],null,["Demonstrates how to update a source\n\nCode sample \n\nGo\n\n\nTo authenticate to Security Command Center, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \tsecuritycenter \"cloud.google.com/go/securitycenter/apiv1\"\n \t\"cloud.google.com/go/securitycenter/apiv1/securitycenterpb\"\n \t\"google.golang.org/genproto/protobuf/field_mask\"\n )\n\n // updateSource changes a sources display name to \"New Display Name\" for a\n // specific source. sourceName is the full resource name of the source to be\n // updated.\n func updateSource(w io.Writer, sourceName string) error {\n \t// sourceName := \"organizations/111122222444/sources/1234\"\n \t// Instantiate a context and a security service client to make API calls.\n \tctx := context.Background()\n \tclient, err := securitycenter.https://cloud.google.com/go/docs/reference/cloud.google.com/go/securitycenter/latest/apiv1.html#cloud_google_com_go_securitycenter_apiv1_Client_NewClient(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"securitycenter.NewClient: %w\", err)\n \t}\n \tdefer client.https://cloud.google.com/go/docs/reference/cloud.google.com/go/securitycenter/latest/apiv1.html#cloud_google_com_go_securitycenter_apiv1_Client_Close() // Closing the client safely cleans up background resources.\n\n \treq := &securitycenterpb.UpdateSourceRequest{\n \t\tSource: &securitycenterpb.Source{\n \t\t\tName: sourceName,\n \t\t\tDisplayName: \"New Display Name\",\n \t\t},\n \t\t// Only update the display name field (if not set all mutable\n \t\t// fields of the source will be updated.\n \t\tUpdateMask: &field_mask.FieldMask{\n \t\t\tPaths: []string{\"display_name\"},\n \t\t},\n \t}\n \tsource, err := client.UpdateSource(ctx, req)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"UpdateSource: %w\", err)\n \t}\n \tfmt.Fprintf(w, \"Source Name: %s, \", source.Name)\n \tfmt.Fprintf(w, \"Display name: %s, \", source.DisplayName)\n \tfmt.Fprintf(w, \"Description: %s\\n\", source.Description)\n\n \treturn nil\n }\n\nJava\n\n\nTo authenticate to Security Command Center, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n static Source updateSource(SourceName sourceName) {\n try (SecurityCenterClient client = SecurityCenterClient.create()) {\n // Start setting up a request to update a source.\n // SourceName sourceName = SourceName.of(/*organization=*/\"123234324\",/*source=*/\n // \"423432321\");\n Source source =\n Source.newBuilder()\n .setDisplayName(\"Updated Display Name\")\n .setName(sourceName.toString())\n .build();\n FieldMask updateMask = FieldMask.newBuilder().addPaths(\"display_name\").build();\n\n UpdateSourceRequest.Builder request =\n UpdateSourceRequest.newBuilder().setSource(source).setUpdateMask(updateMask);\n\n // Call the API.\n Source response = client.updateSource(request.build());\n\n System.out.println(\"Updated Source: \" + response);\n return response;\n } catch (IOException e) {\n throw new RuntimeException(\"Couldn't create client.\", e);\n }\n }\n\nNode.js\n\n\nTo authenticate to Security Command Center, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n // Imports the Google Cloud client library.\n const {SecurityCenterClient} = require('https://cloud.google.com/nodejs/docs/reference/security-center/latest/overview.html');\n\n // Creates a new client.\n const client = new https://cloud.google.com/nodejs/docs/reference/security-center/latest/overview.html();\n // sourceName is the full resource path to the update target.\n /*\n * TODO(developer): Uncomment the following lines\n */\n // const sourceName = \"organizations/111122222444/sources/1234\";\n async function updateSource() {\n const [source] = await client.updateSource({\n source: {\n name: sourceName,\n displayName: 'New Display Name',\n },\n // Only update the display name field (if not set all mutable\n // fields of the source will be updated.\n updateMask: {paths: ['display_name']},\n });\n console.log('Updated source: %j', source);\n }\n\n updateSource();\n\nPython\n\n\nTo authenticate to Security Command Center, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud import securitycenter_v1\n from google.protobuf import field_mask_pb2\n\n client = securitycenter_v1.SecurityCenterClient()\n\n # Field mask to only update the display name.\n field_mask = field_mask_pb2.FieldMask(paths=[\"display_name\"])\n\n # 'source_name' is the resource path for a source that has been\n # created previously (you can use list_sources to find a specific one).\n # Its format is:\n # source_name = \"organizations/{organization_id}/sources/{source_id}\"\n # e.g.:\n # source_name = \"organizations/111122222444/sources/1234\"\n updated = client.https://cloud.google.com/python/docs/reference/securitycenter/latest/google.cloud.securitycenter_v1.services.security_center.SecurityCenterClient.html#google_cloud_securitycenter_v1_services_security_center_SecurityCenterClient_update_source(\n request={\n \"source\": {\"name\": source_name, \"display_name\": \"Updated Display Name\"},\n \"update_mask\": field_mask,\n }\n )\n print(f\"Updated Source: {updated}\")\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=securitycenter)."]]