Mettre à jour une source
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Montre comment mettre à jour une source.
Exemple de code
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","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)."]]