8000 docs: Create SetMuteUndefinedFinding.java (#9443) · suztomo/java-docs-samples@ab6bf40 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab6bf40

Browse files
docs: Create SetMuteUndefinedFinding.java (GoogleCloudPlatform#9443)
* docs: Create SetMuteUndefinedFinding.java.java Create SetMuteUndefinedFinding.java.java sample * Rename SetMuteUndefinedFinding.java.java to SetMuteUndefinedFinding.java * Update security-command-center/snippets/src/main/java/muteconfig/SetMuteUndefinedFinding.java Co-authored-by: Sita Lakshmi Sangameswaran <sitalakshmi@google.com> * Update MuteFindingIT.java * Update SetMuteUndefinedFinding.java Fix kokoro failure. --------- Co-authored-by: Sita Lakshmi Sangameswaran <sitalakshmi@google.com>
1 parent 129a373 commit ab6bf40

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package muteconfig;
18+
19+
// [START securitycenter_set_mute_undefined]
20+
21+
import com.google.cloud.securitycenter.v1.Finding;
22+
import com.google.cloud.securitycenter.v1.Finding.Mute;
23+
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
24+
import com.google.cloud.securitycenter.v1.SetMuteRequest;
25+
import java.io.IOException;
26+
27+
public class SetMuteUndefinedFinding {
28+
29+
public static void main(String[] args) throws IOException {
30+
// TODO: Replace the variables within {}
31+
32+
// findingPath: The relative resource name of the finding. See:
33+
// https://cloud.google.com/apis/design/resource_names#relative_resource_name
34+
// Use any one of the following formats:
35+
// - organizations/{organization_id}/sources/{source_id}/finding/{finding_id}
36+
// - folders/{folder_id}/sources/{source_id}/finding/{finding_id}
37+
// - projects/{project_id}/sources/{source_id}/finding/{finding_id}
38+
String findingPath = "{path-to-the-finding}";
39+
setMuteUndefined(findingPath);
40+
}
41+
42+
// Reset mute state of an individual finding.
43+
// If a finding is already reset, resetting it again has no effect.
44+
// Various mute states are: MUTE_UNSPECIFIED/MUTE/UNMUTE/UNDEFINED.
45+
public static Finding setMuteUndefined(String findingPath) throws IOException {
46+
// Initialize client that will be used to send requests. This client only needs to be created
47+
// once, and can be reused for multiple requests.
48+
try (SecurityCenterClient client = SecurityCenterClient.create()) {
49+
50+
SetMuteRequest setMuteRequest =
51+
SetMuteRequest.newBuilder().setName(findingPath).setMute(Mute.UNDEFINED).build();
52+
53+
Finding finding = client.setMute(setMuteRequest);
54+
System.out.println(
55+
"Mute value for the finding " + finding.getName() + " is: " + finding.getMute());
56+
return finding;
57+
}
58+
}
59+
}
60+
// [END securitycenter_set_mute_undefined]

security-command-center/snippets/src/test/java/MuteFindingIT.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import muteconfig.GetMuteRule;
4141
import muteconfig.ListMuteRules;
4242
import muteconfig.SetMuteFinding;
43+
import muteconfig.SetMuteUndefinedFinding;
4344
import muteconfig.SetUnmuteFinding;
4445
import muteconfig.UpdateMuteRule;
4546
import org.junit.After;
@@ -225,6 +226,8 @@ public void testSetMuteFinding() throws IOException {
225226
assertThat(finding.getMute()).isEqualTo(Mute.MUTED);
226227
finding = SetUnmuteFinding.setUnmute(FINDING_1.getName());
227228
assertThat(finding.getMute()).isEqualTo(Mute.UNMUTED);
229+
finding = SetMuteUndefinedFinding.setMuteUndefined(FINDING_1.getName());
230+
assertThat(finding.getMute()).isEqualTo(Mute.UNDEFINED);
228231
}
229232

230233
@Test

0 commit comments

Comments
 (0)
0