Skip to content
This repository was archived by the owner on Sep 16, 2023. It is now read-only.

Commit 279624f

Browse files
docs(samples): added samples and tests for BigQuery export RPCs (#782)
* docs(samples): added samples and tests for BigQuery export RPCs * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * docs(samples): updated acc to review comments * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * update to latest version of bom * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * docs(samples): updated pom.xml with bigquery * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * including test project specific secrets * docs(samples): lint fix * docs(samples): lint fix * modified project id for testing * Update BigQueryExportIT.java Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent f1d6671 commit 279624f

10 files changed

Lines changed: 534 additions & 2 deletions

File tree

.kokoro/presubmit/samples.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ env_vars: {
2929

3030
env_vars: {
3131
key: "SECRET_MANAGER_KEYS"
32-
value: "java-docs-samples-service-account"
33-
}
32+
value: "java-docs-samples-service-account,java-scc-samples-secrets"
33+
}

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file
3838
<artifactId>google-cloud-pubsub</artifactId>
3939
</dependency>
4040

41+
<dependency>
42+
<groupId>com.google.cloud</groupId>
43+
<artifactId>google-cloud-bigquery</artifactId>
44+
</dependency>
45+
4146
```
4247

4348
If you are using Maven without BOM, add this to your dependencies:
@@ -118,6 +123,11 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-securitycente
118123
| List Notification Config Snippets | [source code](https://github.com/googleapis/java-securitycenter/blob/main/samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/ListNotificationConfigSnippets.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-securitycenter&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/ListNotificationConfigSnippets.java) |
119124
| Notification Receiver | [source code](https://github.com/googleapis/java-securitycenter/blob/main/samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/NotificationReceiver.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-securitycenter&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/NotificationReceiver.java) |
120125
| Update Notification Config Snippets | [source code](https://github.com/googleapis/java-securitycenter/blob/main/samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/UpdateNotificationConfigSnippets.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-securitycenter&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/UpdateNotificationConfigSnippets.java) |
126+
| Create Big Query Export | [source code](https://github.com/googleapis/java-securitycenter/blob/main/samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/bigqueryexport/CreateBigQueryExport.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-securitycenter&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/bigqueryexport/CreateBigQueryExport.java) |
127+
| Delete Big Query Export | [source code](https://github.com/googleapis/java-securitycenter/blob/main/samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/bigqueryexport/DeleteBigQueryExport.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-securitycenter&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/bigqueryexport/DeleteBigQueryExport.java) |
128+
| Get Big Query Export | [source code](https://github.com/googleapis/java-securitycenter/blob/main/samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/bigqueryexport/GetBigQueryExport.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-securitycenter&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/bigqueryexport/GetBigQueryExport.java) |
129+
| List Big Query Exports | [source code](https://github.com/googleapis/java-securitycenter/blob/main/samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/bigqueryexport/ListBigQueryExports.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-securitycenter&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/bigqueryexport/ListBigQueryExports.java) |
130+
| Update Big Query Export | [source code](https://github.com/googleapis/java-securitycenter/blob/main/samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/bigqueryexport/UpdateBigQueryExport.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-securitycenter&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/bigqueryexport/UpdateBigQueryExport.java) |
121131
| Bulk Mute Findings | [source code](https://github.com/googleapis/java-securitycenter/blob/main/samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/muteconfig/BulkMuteFindings.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-securitycenter&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/muteconfig/BulkMuteFindings.java) |
122132
| Create Mute Rule | [source code](https://github.com/googleapis/java-securitycenter/blob/main/samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/muteconfig/CreateMuteRule.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-securitycenter&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/muteconfig/CreateMuteRule.java) |
123133
| Delete Mute Rule | [source code](https://github.com/googleapis/java-securitycenter/blob/main/samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/muteconfig/DeleteMuteRule.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-securitycenter&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/examples/securitycenter/snippets/muteconfig/DeleteMuteRule.java) |

samples/snapshot/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
<version>1.1.3</version>
5656
<scope>test</scope>
5757
</dependency>
58+
<dependency>
59+
<groupId>com.google.cloud</groupId>
60+
<artifactId>google-cloud-bigquery</artifactId>
61+
<version>2.9.3</version>
62+
<scope>test</scope>
63+
</dependency>
5864
</dependencies>
5965
<!-- {x-version-update-end} -->
6066

samples/snippets/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
<groupId>com.google.cloud</groupId>
4949
<artifactId>google-cloud-pubsub</artifactId>
5050
</dependency>
51+
52+
<dependency>
53+
<groupId>com.google.cloud</groupId>
54+
<artifactId>google-cloud-bigquery</artifactId>
55+
</dependency>
5156
<!-- [END securitycenter_install_with_bom] -->
5257

5358
<dependency>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright 2022 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 com.google.cloud.examples.securitycenter.snippets.bigqueryexport;
18+
19+
// [START securitycenter_create_bigquery_export]
20+
21+
import com.google.cloud.securitycenter.v1.BigQueryExport;
22+
import com.google.cloud.securitycenter.v1.CreateBigQueryExportRequest;
23+
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
24+
import java.io.IOException;
25+
import java.util.UUID;
26+
27+
public class CreateBigQueryExport {
28+
29+
public static void main(String[] args) throws IOException {
30+
// TODO(Developer): Modify the following variable values.
31+
32+
// parent: Use any one of the following resource paths:
33+
// - organizations/{organization_id}
34+
// - folders/{folder_id}
35+
// - projects/{project_id}
36+
String parent = String.format("projects/%s", "your-google-cloud-project-id");
37+
38+
// filter: Expression that defines the filter to apply across create/update events of findings.
39+
String filter =
40+
"severity=\"LOW\" OR severity=\"MEDIUM\" AND "
41+
+ "category=\"Persistence: IAM Anomalous Grant\" AND "
42+
+ "-resource.type:\"compute\"";
43+
44+
// bigQueryDatasetId: The BigQuery dataset to write findings' updates to.
45+
String bigQueryDatasetId = "your-bigquery-dataset-id";
46+
47+
// bigQueryExportId: Unique identifier provided by the client.
48+
// For more info, see:
49+
// https://cloud.google.com/security-command-center/docs/how-to-analyze-findings-in-big-query#export_findings_from_to
50+
String bigQueryExportId = "default-" + UUID.randomUUID().toString().split("-")[0];
51+
52+
createBigQueryExport(parent, filter, bigQueryDatasetId, bigQueryExportId);
53+
}
54+
55+
// Create export configuration to export findings from a project to a BigQuery dataset.
56+
// Optionally specify filter to export certain findings only.
57+
public static void createBigQueryExport(
58+
String parent, String filter, String bigQueryDatasetId, String bigQueryExportId)
59+
throws IOException {
60+
// Initialize client that will be used to send requests. This client only needs to be created
61+
// once, and can be reused for multiple requests. After completing all of your requests, call
62+
// the "close" method on the client to safely clean up any remaining background resources.
63+
try (SecurityCenterClient client = SecurityCenterClient.create()) {
64+
65+
// Create the BigQuery export configuration.
66+
BigQueryExport bigQueryExport =
67+
BigQueryExport.newBuilder()
68+
.setDescription(
69+
"Export low and medium findings if the compute resource "
70+
+ "has an IAM anomalous grant")
71+
.setFilter(filter)
72+
.setDataset(String.format("%s/datasets/%s", parent, bigQueryDatasetId))
73+
.build();
74+
75+
CreateBigQueryExportRequest bigQueryExportRequest =
76+
CreateBigQueryExportRequest.newBuilder()
77+
.setParent(parent)
78+
.setBigQueryExport(bigQueryExport)
79+
.setBigQueryExportId(bigQueryExportId)
80+
.build();
81+
82+
// Create the export request.
83+
BigQueryExport response = client.createBigQueryExport(bigQueryExportRequest);
84+
85+
System.out.printf("BigQuery export request created successfully: %s\n", response.getName());
86+
}
87+
}
88+
}
89+
// [END securitycenter_create_bigquery_export]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2022 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 com.google.cloud.examples.securitycenter.snippets.bigqueryexport;
18+
19+
// [START securitycenter_delete_bigquery_export]
20+
21+
import com.google.cloud.securitycenter.v1.DeleteBigQueryExportRequest;
22+
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
23+
import java.io.IOException;
24+
25+
public class DeleteBigQueryExport {
26+
27+
public static void main(String[] args) throws IOException {
28+
// TODO(Developer): Modify the following variable values.
29+
30+
// parent: Use any one of the following resource paths:
31+
// - organizations/{organization_id}
32+
// - folders/{folder_id}
33+
// - projects/{project_id}
34+
String parent = String.format("projects/%s", "your-google-cloud-project-id");
35+
36+
// bigQueryExportId: Unique identifier that is used to identify the export.
37+
String bigQueryExportId = "export-id";
38+
39+
deleteBigQueryExport(parent, bigQueryExportId);
40+
}
41+
42+
// Delete an existing BigQuery export.
43+
public static void deleteBigQueryExport(String parent, String bigQueryExportId)
44+
throws IOException {
45+
// Initialize client that will be used to send requests. This client only needs to be created
46+
// once, and can be reused for multiple requests. After completing all of your requests, call
47+
// the "close" method on the client to safely clean up any remaining background resources.
48+
try (SecurityCenterClient client = SecurityCenterClient.create()) {
49+
50+
DeleteBigQueryExportRequest bigQueryExportRequest =
51+
DeleteBigQueryExportRequest.newBuilder()
52+
.setName(String.format("%s/bigQueryExports/%s", parent, bigQueryExportId))
53+
.build();
54+
55+
client.deleteBigQueryExport(bigQueryExportRequest);
56+
System.out.printf("BigQuery export request deleted successfully: %s", bigQueryExportId);
57+
}
58+
}
59+
}
60+
// [END securitycenter_delete_bigquery_export]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2022 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 com.google.cloud.examples.securitycenter.snippets.bigqueryexport;
18+
19+
// [START securitycenter_get_bigquery_export]
20+
21+
import com.google.cloud.securitycenter.v1.BigQueryExport;
22+
import com.google.cloud.securitycenter.v1.GetBigQueryExportRequest;
23+
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
24+
import java.io.IOException;
25+
26+
public class GetBigQueryExport {
27+
28+
public static void main(String[] args) throws IOException {
29+
// TODO(Developer): Modify the following variable values.
30+
31+
// parent: Use any one of the following resource paths:
32+
// - organizations/{organization_id}
33+
// - folders/{folder_id}
34+
// - projects/{project_id}
35+
String parent = String.format("projects/%s", "your-google-cloud-project-id");
36+
37+
// bigQueryExportId: Unique identifier that is used to identify the export.
38+
String bigQueryExportId = "export-id";
39+
40+
getBigQueryExport(parent, bigQueryExportId);
41+
}
42+
43+
// Retrieve an existing BigQuery export.
44+
public static void getBigQueryExport(String parent, String bigQueryExportId) throws IOException {
45+
// Initialize client that will be used to send requests. This client only needs to be created
46+
// once, and can be reused for multiple requests. After completing all of your requests, call
47+
// the "close" method on the client to safely clean up any remaining background resources.
48+
try (SecurityCenterClient client = SecurityCenterClient.create()) {
49+
50+
GetBigQueryExportRequest bigQueryExportRequest =
51+
GetBigQueryExportRequest.newBuilder()
52+
.setName(String.format("%s/bigQueryExports/%s", parent, bigQueryExportId))
53+
.build();
54+
55+
BigQueryExport response = client.getBigQueryExport(bigQueryExportRequest);
56+
System.out.printf("Retrieved the BigQuery export: %s", response.getName());
57+
}
58+
}
59+
}
60+
// [END securitycenter_get_bigquery_export]
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2022 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 com.google.cloud.examples.securitycenter.snippets.bigqueryexport;
18+
19+
// [START securitycenter_list_bigquery_export]
20+
21+
import com.google.cloud.securitycenter.v1.BigQueryExport;
22+
import com.google.cloud.securitycenter.v1.ListBigQueryExportsRequest;
23+
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
24+
import com.google.cloud.securitycenter.v1.SecurityCenterClient.ListBigQueryExportsPagedResponse;
25+
import java.io.IOException;
26+
27+
public class ListBigQueryExports {
28+
29+
public static void main(String[] args) throws IOException {
30+
// TODO(Developer): Modify the following variable values.
31+
32+
// parent: The parent, which owns the collection of BigQuery exports.
33+
// Use any one of the following resource paths:
34+
// - organizations/{organization_id}
35+
// - folders/{folder_id}
36+
// - projects/{project_id}
37+
String parent = String.format("projects/%s", "your-google-cloud-project-id");
38+
39+
listBigQueryExports(parent);
40+
}
41+
42+
// List BigQuery exports in the given parent.
43+
public static void listBigQueryExports(String parent) throws IOException {
44+
// Initialize client that will be used to send requests. This client only needs to be created
45+
// once, and can be reused for multiple requests. After completing all of your requests, call
46+
// the "close" method on the client to safely clean up any remaining background resources.
47+
try (SecurityCenterClient client = SecurityCenterClient.create()) {
48+
49+
ListBigQueryExportsRequest request =
50+
ListBigQueryExportsRequest.newBuilder().setParent(parent).build();
51+
52+
ListBigQueryExportsPagedResponse response = client.listBigQueryExports(request);
53+
54+
System.out.println("Listing BigQuery exports:");
55+
for (BigQueryExport bigQueryExport : response.iterateAll()) {
56+
System.out.println(bigQueryExport.getName());
57+
}
58+
}
59+
}
60+
}
61+
// [END securitycenter_list_bigquery_export]

0 commit comments

Comments
 (0)