更新忽略規則
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
示範如何更新忽略規則
程式碼範例
Go
如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Java
如要向 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 update a mute rule\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\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/protobuf/types/known/fieldmaskpb\"\n )\n\n // updateMuteRule Updates an existing mute configuration.\n // The following can be updated in a mute config: description and filter.\n func updateMuteRule(w io.Writer, muteConfigName string) error {\n \t// Specify the name of the mute config to delete.\n \t// muteConfigName: Use any one of the following formats:\n \t// - organizations/{organization}/muteConfigs/{config_id}\n \t// - folders/{folder}/muteConfigs/{config_id}\n \t// - projects/{project}/muteConfigs/{config_id}\n \t// muteConfigName := fmt.Sprintf(\"projects/%s/muteConfigs/%s\", \"project-id\", \"mute-config\")\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()\n\n \tupdateMuteConfig := &securitycenterpb.MuteConfig{\n \t\tName: muteConfigName,\n \t\tDescription: \"Updated mute config description\",\n \t}\n\n \treq := &securitycenterpb.UpdateMuteConfigRequest{\n \t\tMuteConfig: updateMuteConfig,\n \t\t// Set the update mask to specify which properties of the mute config should be\n \t\t// updated.\n \t\t// If empty, all mutable fields will be updated.\n \t\t// Make sure that the mask fields match the properties changed in 'updateMuteConfig'.\n \t\t// For more info on constructing update mask path, see the proto or:\n \t\t// https://cloud.google.com/security-command-center/docs/reference/rest/v1/folders.muteConfigs/patch?hl=en#query-parameters\n \t\tUpdateMask: &fieldmaskpb.FieldMask{\n \t\t\tPaths: []string{\n \t\t\t\t\"description\",\n \t\t\t},\n \t\t},\n \t}\n\n \tresponse, err := client.UpdateMuteConfig(ctx, req)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"mute rule update failed! %w\", err)\n \t}\n \tfmt.Fprintf(w, \"Mute rule updated %s\", response.Name)\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\n import com.google.cloud.securitycenter.v1.https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.MuteConfig.html;\n import com.google.cloud.securitycenter.v1.https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.SecurityCenterClient.html;\n import com.google.cloud.securitycenter.v1.https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.UpdateMuteConfigRequest.html;\n import com.google.protobuf.https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.FieldMask.html;\n import java.io.IOException;\n\n public class UpdateMuteRule {\n\n public static void main(String[] args) {\n // TODO: Replace the variables within {}\n\n // Specify the name of the mute config to delete.\n // muteConfigName: Use any one of the following formats:\n // - organizations/{organization}/muteConfigs/{config_id}\n // - folders/{folder}/muteConfigs/{config_id}\n // - projects/{project}/muteConfigs/{config_id}\n String muteConfigName = \"{any-one-of-the-above-formats}\";\n updateMuteRule(muteConfigName);\n }\n\n // Updates an existing mute configuration.\n // The following can be updated in a mute config: description and filter.\n public static void updateMuteRule(String muteConfigName) {\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests. After completing all of your requests, call\n // the \"close\" method on the client to safely clean up any remaining background resources.\n try (https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.SecurityCenterClient.html securityCenterClient = https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.SecurityCenterClient.html.create()) {\n\n https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.MuteConfig.html updateMuteConfig =\n https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.MuteConfig.html.newBuilder()\n .setName(muteConfigName)\n .setDescription(\"Updated mute config description\")\n .build();\n\n https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.UpdateMuteConfigRequest.html updateMuteConfigRequest =\n https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.UpdateMuteConfigRequest.html.newBuilder()\n .setMuteConfig(updateMuteConfig)\n // Set the update mask to specify which properties of the mute config should be\n // updated.\n // If empty, all mutable fields will be updated.\n // Make sure that the mask fields match the properties changed in 'updateMuteConfig'.\n // For more info on constructing update mask path, see the proto or:\n // https://cloud.google.com/security-command-center/docs/reference/rest/v1/folders.muteConfigs/patch?hl=en#query-parameters\n .setUpdateMask(https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.FieldMask.html.newBuilder().https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.FieldMask.Builder.html#com_google_protobuf_FieldMask_Builder_addPaths_java_lang_String_(\"description\").build())\n .build();\n\n https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.MuteConfig.html response = securityCenterClient.updateMuteConfig(updateMuteConfigRequest);\n System.out.println(response);\n } catch (IOException e) {\n System.out.println(\"Mute rule update failed! \\n Exception: \" + e);\n }\n }\n }\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 def update_mute_rule(mute_config_name: str) -\u003e None:\n \"\"\"\n Updates an existing mute configuration.\n The following can be updated in a mute config: description, and filter/ mute rule.\n Args:\n mute_config_name: Specify the name of the mute config to delete.\n Use any one of the following formats:\n - organizations/{organization}/muteConfigs/{config_id}\n - folders/{folder}/muteConfigs/{config_id}\n - projects/{project}/muteConfigs/{config_id}\n \"\"\"\n from google.cloud import securitycenter\n from google.protobuf import field_mask_pb2\n\n client = securitycenter.SecurityCenterClient()\n\n update_mute_config = securitycenter.https://cloud.google.com/python/docs/reference/securitycenter/latest/google.cloud.securitycenter_v1.types.MuteConfig.html()\n update_mute_config.name = mute_config_name\n update_mute_config.description = \"Updated mute config description\"\n\n field_mask = field_mask_pb2.FieldMask(paths=[\"description\"])\n\n request = securitycenter.https://cloud.google.com/python/docs/reference/securitycenter/latest/google.cloud.securitycenter_v1.types.UpdateMuteConfigRequest.html()\n request.mute_config = update_mute_config\n # Set the update mask to specify which properties of the Mute Config should be updated.\n # If empty, all mutable fields will be updated.\n # Make sure that the mask fields match the properties changed in 'update_mute_config'.\n # For more info on constructing update mask path, see the proto or:\n # https://cloud.google.com/security-command-center/docs/reference/rest/v1/folders.muteConfigs/patch?hl=en#query-parameters\n request.update_mask = field_mask\n\n mute_config = 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_mute_config(request)\n print(f\"Updated mute rule : {mute_config}\")\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)."]]