查看忽略规则
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
修改 securitycenter_get_mute_config 演示了如何查看忽略规则
代码示例
Go
如需向 Security Command Center 进行身份验证,请设置应用默认凭证。
如需了解详情,请参阅为本地开发环境设置身份验证。
Java
如需向 Security Command Center 进行身份验证,请设置应用默认凭证。
如需了解详情,请参阅为本地开发环境设置身份验证。
Python
如需向 Security Command Center 进行身份验证,请设置应用默认凭证。
如需了解详情,请参阅为本地开发环境设置身份验证。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。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,["# View a mute rule\n\nEditing securitycenter_get_mute_config\nDemonstrates how to view a mute rule\n\nCode sample\n-----------\n\n### Go\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 )\n\n // getMuteRule retrieves a mute configuration given its resource name.\n func getMuteRule(w io.Writer, parent string, muteConfigId string) error {\n \t// Use any one of the following resource paths to get mute configuration:\n \t// - organizations/{organization_id}\n \t// - folders/{folder_id}\n \t// - projects/{project_id}\n \t// parent := fmt.Sprintf(\"projects/%s\", \"your-google-cloud-project-id\")\n \t//\n \t// Name of the mute config to retrieve.\n \t// muteConfigId := \"mute-config-id\"\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 \treq := &securitycenterpb.GetMuteConfigRequest{\n \t\tName: fmt.Sprintf(\"%s/muteConfigs/%s\", parent, muteConfigId),\n \t}\n\n \tmuteconfig, err := client.GetMuteConfig(ctx, req)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"Failed to retrieve Muteconfig: %w\", err)\n \t}\n \tfmt.Fprintf(w, \"Muteconfig Name: %s \", muteconfig.Name)\n \treturn nil\n }\n\n### Java\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.MuteConfigName.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 java.io.IOException;\n\n public class GetMuteRule {\n\n public static void main(String[] args) {\n // TODO(Developer): Replace the following variables\n\n // parentPath: Use any one of the following options:\n // - organizations/{organization_id}\n // - folders/{folder_id}\n // - projects/{project_id}\n String parentPath = String.format(\"projects/%s\", \"your-google-cloud-project-id\");\n\n // muteConfigId: Name of the mute config to retrieve.\n String muteConfigId = \"mute-config-id\";\n\n getMuteRule(parentPath, muteConfigId);\n }\n\n // Retrieves a mute configuration given its resource name.\n public static void getMuteRule(String projectId, String muteConfigId) {\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 client = https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.SecurityCenterClient.html.create()) {\n // Use appropriate MuteConfigName methods depending on the type of parent.\n // (org -\u003e MuteConfigName.ofOrganizationMuteConfigName()\n // folder -\u003e MuteConfigName.ofFolderMuteConfigName()\n // project -\u003e MuteConfigName.ofProjectMuteConfigName)\n https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.MuteConfig.html muteConfig =\n client.getMuteConfig(https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.MuteConfigName.html.https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.MuteConfigName.html#com_google_cloud_securitycenter_v1_MuteConfigName_ofProjectMuteConfigName_java_lang_String_java_lang_String_(projectId, muteConfigId));\n\n System.out.println(\"Retrieved the mute config: \" + muteConfig);\n } catch (IOException e) {\n System.out.println(\"Mute rule retrieval failed! \\n Exception: \" + e);\n }\n }\n }\n\n### Python\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 get_mute_rule(mute_config_name: str) -\u003e None:\n \"\"\"\n Retrieves a mute configuration given its resource name.\n Args:\n mute_config_name: Name of the mute config to retrieve.\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\n client = securitycenter.SecurityCenterClient()\n\n request = securitycenter.https://cloud.google.com/python/docs/reference/securitycenter/latest/google.cloud.securitycenter_v1.types.GetMuteConfigRequest.html()\n request.name = mute_config_name\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_get_mute_config(request)\n print(f\"Retrieved the mute rule: {mute_config.name}\")\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=securitycenter)."]]