|
| 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] |
0 commit comments