演示如何手动取消忽略单个发现结果
深入探索
如需查看包含此代码示例的详细文档,请参阅以下内容:
代码示例
Go
如需向 Security Command Center 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证。
import (
"context"
"fmt"
"io"
securitycenter "cloud.google.com/go/securitycenter/apiv1"
"cloud.google.com/go/securitycenter/apiv1/securitycenterpb"
)
// setUnmute unmutes an individual finding.
// Unmuting a finding that isn't muted has no effect.
// Various mute states are: MUTE_UNSPECIFIED/MUTE/UNMUTE.
func setUnmute(w io.Writer, findingPath string) error {
// findingPath: The relative resource name of the finding. See:
// https://cloud.google.com/apis/design/resource_names#relative_resource_name
// Use any one of the following formats:
// - organizations/{organization_id}/sources/{source_id}/finding/{finding_id}
// - folders/{folder_id}/sources/{source_id}/finding/{finding_id}
// - projects/{project_id}/sources/{source_id}/finding/{finding_id}
// findingPath := fmt.Sprintf("projects/%s/sources/%s/finding/%s", "your-google-cloud-project-id", "source", "finding-id")
ctx := context.Background()
client, err := securitycenter.NewClient(ctx)
if err != nil {
return fmt.Errorf("securitycenter.NewClient: %w", err)
}
defer client.Close()
req := &securitycenterpb.SetMuteRequest{
Name: findingPath,
Mute: securitycenterpb.Finding_UNMUTED}
finding, err := client.SetMute(ctx, req)
if err != nil {
return fmt.Errorf("failed to set the specified mute value: %w", err)
}
fmt.Fprintf(w, "Mute value for the finding: %s is %s", finding.Name, finding.Mute)
return nil
}
Java
如需向 Security Command Center 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证。
import com.google.cloud.securitycenter.v1.Finding;
import com.google.cloud.securitycenter.v1.Finding.Mute;
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
import com.google.cloud.securitycenter.v1.SetMuteRequest;
import java.io.IOException;
public class SetUnmuteFinding {
public static void main(String[] args) throws IOException {
// TODO: Replace the variables within {}
// findingPath: The relative resource name of the finding. See:
// https://cloud.google.com/apis/design/resource_names#relative_resource_name
// Use any one of the following formats:
// - organizations/{organization_id}/sources/{source_id}/finding/{finding_id}
// - folders/{folder_id}/sources/{source_id}/finding/{finding_id}
// - projects/{project_id}/sources/{source_id}/finding/{finding_id}
String findingPath = "{path-to-the-finding}";
setUnmute(findingPath);
}
// Unmute an individual finding.
// Unmuting a finding that isn't muted has no effect.
// Various mute states are: MUTE_UNSPECIFIED/MUTE/UNMUTE.
public static Finding setUnmute(String findingPath) throws IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
try (SecurityCenterClient client = SecurityCenterClient.create()) {
SetMuteRequest setMuteRequest =
SetMuteRequest.newBuilder().setName(findingPath).setMute(Mute.UNMUTED).build();
Finding finding = client.setMute(setMuteRequest);
System.out.println(
"Mute value for the finding " + finding.getName() + " is: " + finding.getMute());
return finding;
}
}
}
Python
如需向 Security Command Center 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证。
def set_unmute_finding(finding_path: str) -> None:
"""
Unmute an individual finding.
Unmuting a finding that isn't muted has no effect.
Various mute states are: MUTE_UNSPECIFIED/MUTE/UNMUTE.
Args:
finding_path: The relative resource name of the finding. See:
https://cloud.google.com/apis/design/resource_names#relative_resource_name
Use any one of the following formats:
- organizations/{organization_id}/sources/{source_id}/finding/{finding_id},
- folders/{folder_id}/sources/{source_id}/finding/{finding_id},
- projects/{project_id}/sources/{source_id}/finding/{finding_id}.
"""
from google.cloud import securitycenter
client = securitycenter.SecurityCenterClient()
request = securitycenter.SetMuteRequest()
request.name = finding_path
request.mute = securitycenter.Finding.Mute.UNMUTED
finding = client.set_mute(request)
print(f"Mute value for the finding: {finding.mute.name}")
后续步骤
如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器。