刪除安全標記
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
說明如何刪除安全標記
程式碼範例
Go
如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Java
如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Python
如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 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 delete security marks\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 // deleteSecurityMarks deletes security marks \"key_a\" and \"key_b\" from\n // assetName's marks. assetName is the resource path for an asset.\n func deleteSecurityMarks(w io.Writer, assetName string) error {\n \t// Specify the value of 'assetName' in one of the following formats:\n \t// \t\tassetName := \"organizations/{org_id}/assets/{asset_id}\"\n \t//\t\tassetName := \"projects/{project_id}/assets/{asset_id}\"\n \t//\t\tassetName := \"folders/{folder_id}/assets/{asset_id}\"\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.UpdateSecurityMarksRequest{\n \t\t// If not set or empty, all marks would be cleared.\n \t\tUpdateMask: &field_mask.FieldMask{\n \t\t\tPaths: []string{\"marks.key_a\", \"marks.key_b\"},\n \t\t},\n \t\tSecurityMarks: &securitycenterpb.SecurityMarks{\n \t\t\tName: fmt.Sprintf(\"%s/securityMarks\", assetName),\n \t\t\t// Intentionally not setting marks with the\n \t\t\t// corresponding field mask deletes them.\n \t\t},\n \t}\n \tupdatedMarks, err := client.UpdateSecurityMarks(ctx, req)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"UpdateSecurityMarks: %w\", err)\n \t}\n\n \tfmt.Fprintf(w, \"Updated marks: %s\\n\", updatedMarks.Name)\n \tfor k, v := range updatedMarks.Marks {\n \t\tfmt.Fprintf(w, \"%s = %s\\n\", k, v)\n \t}\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 SecurityMarks clearFromAsset(String assetName) {\n try (SecurityCenterClient client = SecurityCenterClient.create()) {\n // Specify the value of 'assetName' in one of the following formats:\n // String assetName = \"organizations/{org-id}/assets/{asset-id}\";\n // String assetName = \"projects/{project-id}/assets/{asset-id}\";\n // String assetName = \"folders/{folder-id}/assets/{asset-id}\";\n // Start setting up a request to clear security marks for an asset.\n // Create security mark and field mask for clearing security marks.\n SecurityMarks securityMarks =\n SecurityMarks.newBuilder().setName(assetName + \"/securityMarks\").build();\n FieldMask updateMask =\n FieldMask.newBuilder().addPaths(\"marks.key_a\").addPaths(\"marks.key_b\").build();\n\n UpdateSecurityMarksRequest request =\n UpdateSecurityMarksRequest.newBuilder()\n .setSecurityMarks(securityMarks)\n .setUpdateMask(updateMask)\n .build();\n\n // Call the API.\n SecurityMarks response = client.updateSecurityMarks(request);\n\n System.out.println(\"Security Marks cleared:\");\n System.out.println(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\n async function deleteSecurityMarks() {\n // assetName is the full resource path for the asset to update.\n /*\n * TODO(developer): Uncomment the following lines\n */\n // Specify the value of 'assetName' in one of the following formats:\n // `organizations/${org-id}/assets/${asset-id}`;\n // `projects/${project-id}/assets/${asset-id}`;\n // `folders/${folder-id}/assets/${asset-id}`;\n // const assetName = \"organizations/123123342/assets/12312321\";\n const [newMarks] = await client.updateSecurityMarks({\n securityMarks: {\n name: `${assetName}/securityMarks`,\n // Intentionally, not setting marks to delete them.\n },\n // Only delete marks for the following keys.\n updateMask: {paths: ['marks.key_a', 'marks.key_b']},\n });\n\n console.log('Updated marks: %j', newMarks);\n }\n deleteSecurityMarks();\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\n from google.protobuf import field_mask_pb2\n\n # Create a new client.\n client = securitycenter.SecurityCenterClient()\n\n # 'asset_name' is the resource path for an asset that exists in SCC.\n # Specify the value of 'asset_name' in one of the following formats:\n # f\"organizations/{org_id}/assets/{asset_id}\"\n # f\"projects/{project_id}/assets/{asset_id}\"\n # f\"folders/{folder_id}/assets/{asset_id}\"\n # asset_name = organizations/123123342/assets/12312321\n marks_name = f\"{asset_name}/securityMarks\"\n\n field_mask = field_mask_pb2.FieldMask(paths=[\"marks.key_a\", \"marks.key_b\"])\n\n updated_marks = 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_security_marks(\n request={\n \"security_marks\": {\n \"name\": marks_name\n # Note, no marks specified, so the specified values in\n # the fields masks will be deleted.\n },\n \"update_mask\": field_mask,\n }\n )\n print(updated_marks)\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)."]]