숨기기 규칙을 업데이트하는 방법을 보여줍니다.
더 살펴보기
이 코드 샘플이 포함된 자세한 문서는 다음을 참조하세요.
코드 샘플
Go
Security Command Center에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
import (
"context"
"fmt"
"io"
securitycenter "cloud.google.com/go/securitycenter/apiv1"
"cloud.google.com/go/securitycenter/apiv1/securitycenterpb"
"google.golang.org/protobuf/types/known/fieldmaskpb"
)
// updateMuteRule Updates an existing mute configuration.
// The following can be updated in a mute config: description and filter.
func updateMuteRule(w io.Writer, muteConfigName string) error {
// Specify the name of the mute config to delete.
// muteConfigName: Use any one of the following formats:
// - organizations/{organization}/muteConfigs/{config_id}
// - folders/{folder}/muteConfigs/{config_id}
// - projects/{project}/muteConfigs/{config_id}
// muteConfigName := fmt.Sprintf("projects/%s/muteConfigs/%s", "project-id", "mute-config")
ctx := context.Background()
client, err := securitycenter.NewClient(ctx)
if err != nil {
return fmt.Errorf("securitycenter.NewClient: %w", err)
}
defer client.Close()
updateMuteConfig := &securitycenterpb.MuteConfig{
Name: muteConfigName,
Description: "Updated mute config description",
}
req := &securitycenterpb.UpdateMuteConfigRequest{
MuteConfig: updateMuteConfig,
// Set the update mask to specify which properties of the mute config should be
// updated.
// If empty, all mutable fields will be updated.
// Make sure that the mask fields match the properties changed in 'updateMuteConfig'.
// For more info on constructing update mask path, see the proto or:
// https://cloud.google.com/security-command-center/docs/reference/rest/v1/folders.muteConfigs/patch?hl=en#query-parameters
UpdateMask: &fieldmaskpb.FieldMask{
Paths: []string{
"description",
},
},
}
response, err := client.UpdateMuteConfig(ctx, req)
if err != nil {
return fmt.Errorf("mute rule update failed! %v", err)
}
fmt.Fprintf(w, "Mute rule updated %s", response.Name)
return nil
}
Java
Security Command Center에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
import com.google.cloud.securitycenter.v1.MuteConfig;
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
import com.google.cloud.securitycenter.v1.UpdateMuteConfigRequest;
import com.google.protobuf.FieldMask;
import java.io.IOException;
public class UpdateMuteRule {
public static void main(String[] args) {
// TODO: Replace the variables within {}
// Specify the name of the mute config to delete.
// muteConfigName: Use any one of the following formats:
// - organizations/{organization}/muteConfigs/{config_id}
// - folders/{folder}/muteConfigs/{config_id}
// - projects/{project}/muteConfigs/{config_id}
String muteConfigName = "{any-one-of-the-above-formats}";
updateMuteRule(muteConfigName);
}
// Updates an existing mute configuration.
// The following can be updated in a mute config: description and filter.
public static void updateMuteRule(String muteConfigName) {
// 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 securityCenterClient = SecurityCenterClient.create()) {
MuteConfig updateMuteConfig =
MuteConfig.newBuilder()
.setName(muteConfigName)
.setDescription("Updated mute config description")
.build();
UpdateMuteConfigRequest updateMuteConfigRequest =
UpdateMuteConfigRequest.newBuilder()
.setMuteConfig(updateMuteConfig)
// Set the update mask to specify which properties of the mute config should be
// updated.
// If empty, all mutable fields will be updated.
// Make sure that the mask fields match the properties changed in 'updateMuteConfig'.
// For more info on constructing update mask path, see the proto or:
// https://cloud.google.com/security-command-center/docs/reference/rest/v1/folders.muteConfigs/patch?hl=en#query-parameters
.setUpdateMask(FieldMask.newBuilder().addPaths("description").build())
.build();
MuteConfig response = securityCenterClient.updateMuteConfig(updateMuteConfigRequest);
System.out.println(response);
} catch (IOException e) {
System.out.println("Mute rule update failed! \n Exception: " + e);
}
}
}
Python
Security Command Center에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
def update_mute_rule(mute_config_name: str) -> None:
"""
Updates an existing mute configuration.
The following can be updated in a mute config: description, and filter/ mute rule.
Args:
mute_config_name: Specify the name of the mute config to delete.
Use any one of the following formats:
- organizations/{organization}/muteConfigs/{config_id}
- folders/{folder}/muteConfigs/{config_id}
- projects/{project}/muteConfigs/{config_id}
"""
from google.cloud import securitycenter
from google.protobuf import field_mask_pb2
client = securitycenter.SecurityCenterClient()
update_mute_config = securitycenter.MuteConfig()
update_mute_config.name = mute_config_name
update_mute_config.description = "Updated mute config description"
field_mask = field_mask_pb2.FieldMask(paths=["description"])
request = securitycenter.UpdateMuteConfigRequest()
request.mute_config = update_mute_config
# Set the update mask to specify which properties of the Mute Config should be updated.
# If empty, all mutable fields will be updated.
# Make sure that the mask fields match the properties changed in 'update_mute_config'.
# For more info on constructing update mask path, see the proto or:
# https://cloud.google.com/security-command-center/docs/reference/rest/v1/folders.muteConfigs/patch?hl=en#query-parameters
request.update_mask = field_mask
mute_config = client.update_mute_config(request)
print(f"Updated mute rule : {mute_config}")
다음 단계
다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.