Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding API v2 Bigquery export samples #9291

Closed
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
cf1c00c
chore: bigquery export samples
rafaelMurata Apr 11, 2024
59bfc7a
add unit test
rafaelMurata Apr 11, 2024
8444a31
improve readability
rafaelMurata Apr 12, 2024
e1cf1fb
reverting files from BigQueryExport v1
rafaelMurata Apr 18, 2024
90b1b0c
change BigQuery create dataset method
rafaelMurata Apr 30, 2024
471722c
Update security-command-center/snippets/src/main/java/vtwo/bigquery/C…
rafaelMurata May 7, 2024
3675818
Update security-command-center/snippets/src/main/java/vtwo/bigquery/U…
rafaelMurata May 7, 2024
0d6f9c9
chore(deps): update micronaut packages to v3.10.4 (#9275)
renovate-bot Apr 1, 2024
eb3a816
feat: Elastic Text-Embedding demo. (#9271)
lee1premium Apr 6, 2024
888c497
fix: Elastic Text-Embedding demo. (#9280)
lee1premium Apr 8, 2024
eced334
@ignore tests due to https://github.com/GoogleCloudPlatform/java-docs…
lee1premium Apr 8, 2024
1ee3f1c
feat: Text-embedding model tuning demo. (#9272)
lee1premium Apr 8, 2024
a97559a
fix(healthcare): don't store DICOM instance before each DICOMweb test…
noerog Apr 17, 2024
8dda031
storageinsights: update edit inventory report config sample (#9283)
JesseLovelace Apr 18, 2024
e660fff
fix: Adding missing grpc dependency (#9294)
surbhigarg92 Apr 21, 2024
393f4f8
api platform updated version form v1beta to v1 (#9289)
ssvir Apr 22, 2024
1896333
chore: api v2 notifications samples (#9276)
rafaelMurata Apr 24, 2024
925f88d
refactor(iam): update service account samples to use GAPIC library (#…
ssvir Apr 25, 2024
32ea46c
Unignore SnippetsIT.testSetUsageBucketExportCustomPrefix cause can't …
ssvir Apr 29, 2024
d526a3b
refactor(iam): update IAM policy samples to use GAPIC library (#9290)
ssvir Apr 30, 2024
f461873
feat: Adding API v2 IAM samples (#9285)
rafaelMurata Apr 30, 2024
1c2b557
test(vertexai): enable sample tests (#9303)
Sita04 Apr 30, 2024
dc29841
Gemini 1.5 multimodal snippets (#9302)
glaforge Apr 30, 2024
082e16c
Unignore SearchIT.testSearchAllResourcesExample cause problems with t…
ssvir May 1, 2024
bc36d31
unignore test class, added try with resources (#9304)
ssvir May 1, 2024
63d76f5
feat: Adding disable role snippet (#9295)
msilc May 2, 2024
3c878b1
chore(vertexai): update to the latest version of the libraries-bom (a…
glaforge May 2, 2024
218984c
chore(deps): update eclipse-temurin docker tag to v17.0.11_9-jre-alpi…
renovate-bot May 6, 2024
79f6310
Update Gemini model versions (#9309)
katiemn May 7, 2024
0acb3db
feat: Add API v2 finding samples (#9284)
rafaelMurata May 7, 2024
0c3971d
feat: add gemini code sample and test for text-only input (#9310)
irataxy May 7, 2024
c60b9a4
feat: override 003 model to 004 (#9313)
kewent May 8, 2024
887ab26
chore(fixit): remove redundant region tags (#9315)
briandorsey May 8, 2024
e20cee3
fixit: remove redundant region tags (#9312)
glasnt May 8, 2024
639ba5d
feat: add marks samples (#9311)
rafaelMurata May 9, 2024
0fbc3d7
fixit: remove redundant region tags (#9316)
glasnt May 9, 2024
3247638
feat: update text-only input sample to use a generic review (#9317)
irataxy May 9, 2024
def983d
chore(cloudrun): Cleanup deprecated sample Cloud Run Filesystem (#9321)
grayside May 10, 2024
d16f84f
feat: refactor text-only Gemini prompt (#9322)
irataxy May 11, 2024
9524771
refactor(iam): update service account samples to use GAPIC library (#…
msilc May 13, 2024
711ee97
unignore tests, rerun 5 times without failings (#9329)
ssvir May 15, 2024
063db2f
feat(vertexai): support system instruction (#9330)
glaforge May 15, 2024
70f3df1
spanner/r2dbc test(s) are failing #8978 (#9318)
ssvir May 15, 2024
89c487e
chore(deps): update eclipse-temurin docker tag to v17.0.11_9-jre (#9327)
renovate-bot May 16, 2024
f97340d
moved files from "update IAM policy samples to use GAPIC library" PR …
ssvir May 16, 2024
6501c8b
chore: comment about how to instantiate logger variable in Cloud Run …
suztomo May 22, 2024
608d980
fix: remove unused region tag eventarc_pubsub_dockerfile (#9328)
glasnt May 23, 2024
4801c50
feat: Adding API v2 Source samples (#9299)
rafaelMurata May 23, 2024
d0af378
Joint String output variable declaration and use in Vertex AI TextInp…
vorburger May 23, 2024
cfc22c6
fix(aiplatform): Update NVIDIA_TESLA_K80 to NVIDIA_TESLA_T4 (#9342)
Sita04 May 23, 2024
0d06414
add region tag for QuestionAnswer.java (#9335)
LukeSchlangen May 23, 2024
0c24b56
Update embedding tuning sample to use the v1.1.3 pipeline. (#9333)
skarukas May 23, 2024
d0b24dd
fix: Use Alphabet 10k sample dataset. (#9337)
lee1premium May 23, 2024
abb262a
feat(vertexai): Update to gemini-1.5-flash-001 (#9344)
glaforge May 24, 2024
e4c9c6a
add mockito
rafaelMurata May 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package vtwo.bigquery;

// [START securitycenter_create_bigquery_export_v2]

import com.google.cloud.securitycenter.v2.BigQueryExport;
import com.google.cloud.securitycenter.v2.CreateBigQueryExportRequest;
import com.google.cloud.securitycenter.v2.OrganizationLocationName;
import com.google.cloud.securitycenter.v2.SecurityCenterClient;
import java.io.IOException;
import java.util.UUID;

public class CreateBigQueryExport {

public static void main(String[] args) throws IOException {
// TODO(Developer): Modify the following variable values.
// organizationId: Google Cloud Organization id.
String organizationId = "{google-cloud-organization-id}";

String projectId = "{your-project}";

// Specify the location.
String location = "global";

// filter: Expression that defines the filter to apply across create/update events of findings.
String filter = "severity=\"LOW\" OR severity=\"MEDIUM\"";

// bigQueryDatasetId: The BigQuery dataset to write findings' updates to.
String bigQueryDatasetId = "{bigquery-dataset-id}";

// bigQueryExportId: Unique identifier provided by the client.
// For more info, see:
// https://cloud.google.com/security-command-center/docs/how-to-analyze-findings-in-big-query#export_findings_from_to
String bigQueryExportId = "default-" + UUID.randomUUID().toString().split("-")[0];

createBigQueryExport(organizationId, location, projectId, filter, bigQueryDatasetId,
bigQueryExportId);
}

// Create export configuration to export findings from a project to a BigQuery dataset.
// Optionally specify filter to export certain findings only.
public static void createBigQueryExport(String organizationId, String location,
String projectId, String filter, String bigQueryDatasetId, String bigQueryExportId)
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.
rafaelMurata marked this conversation as resolved.
Show resolved Hide resolved
try (SecurityCenterClient client = SecurityCenterClient.create()) {
OrganizationLocationName organizationName = OrganizationLocationName.of(organizationId,
location);
// Create the BigQuery export configuration.
BigQueryExport bigQueryExport =
BigQueryExport.newBuilder()
.setDescription(
"Export low and medium findings if the compute resource "
+ "has an IAM anomalous grant")
.setFilter(filter)
.setDataset(String.format("projects/%s/datasets/%s", projectId, bigQueryDatasetId))
.build();

CreateBigQueryExportRequest bigQueryExportRequest =
CreateBigQueryExportRequest.newBuilder()
.setParent(organizationName.toString())
.setBigQueryExport(bigQueryExport)
.setBigQueryExportId(bigQueryExportId)
.build();

// Create the export request.
BigQueryExport response = client.createBigQueryExport(bigQueryExportRequest);

System.out.printf("BigQuery export request created successfully: %s\n", response.getName());
}
}
}
// [END securitycenter_create_bigquery_export_v2]
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package vtwo.bigquery;

// [START securitycenter_delete_bigquery_export_v2]

import com.google.cloud.securitycenter.v2.BigQueryExportName;
import com.google.cloud.securitycenter.v2.DeleteBigQueryExportRequest;
import com.google.cloud.securitycenter.v2.SecurityCenterClient;
import java.io.IOException;

public class DeleteBigQueryExport {

public static void main(String[] args) throws IOException {
// TODO(Developer): Modify the following variable values.
// organizationId: Google Cloud Organization id.
String organizationId = "{google-cloud-organization-id}";

// Specify the location to list the findings.
String location = "global";

// bigQueryExportId: Unique identifier that is used to identify the export.
String bigQueryExportId = "{bigquery-export-id}";

deleteBigQueryExport(organizationId, location, bigQueryExportId);
}

// Delete an existing BigQuery export.
public static void deleteBigQueryExport(String organizationId, String location,
String bigQueryExportId)
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()) {
// optionally BigQueryExportName or String can be used
// String bigQueryExportName = String.format("organizations/%s/locations/%s
// /bigQueryExports/%s",organizationId,location, bigQueryExportId);
BigQueryExportName bigQueryExportName = BigQueryExportName.of(organizationId, location,
bigQueryExportId);

DeleteBigQueryExportRequest bigQueryExportRequest =
DeleteBigQueryExportRequest.newBuilder()
.setName(bigQueryExportName.toString())
.build();

client.deleteBigQueryExport(bigQueryExportRequest);
System.out.printf("BigQuery export request deleted successfully: %s", bigQueryExportId);
}
}
}
// [END securitycenter_delete_bigquery_export_v2]
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package vtwo.bigquery;

// [START securitycenter_get_bigquery_export_v2]

import com.google.cloud.securitycenter.v2.BigQueryExport;
import com.google.cloud.securitycenter.v2.BigQueryExportName;
import com.google.cloud.securitycenter.v2.GetBigQueryExportRequest;
import com.google.cloud.securitycenter.v2.SecurityCenterClient;
import java.io.IOException;

public class GetBigQueryExport {

public static void main(String[] args) throws IOException {
// TODO(Developer): Modify the following variable values.
// organizationId: Google Cloud Organization id.
String organizationId = "{google-cloud-organization-id}";

// Specify the location to list the findings.
String location = "global";

// bigQueryExportId: Unique identifier that is used to identify the export.
String bigQueryExportId = "{bigquery-export-id}";

getBigQueryExport(organizationId, location, bigQueryExportId);
}

// Retrieve an existing BigQuery export.
public static void getBigQueryExport(String organizationId, String location,
String bigQueryExportId) 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()) {

BigQueryExportName bigQueryExportName = BigQueryExportName.of(organizationId, location,
bigQueryExportId);

GetBigQueryExportRequest bigQueryExportRequest =
GetBigQueryExportRequest.newBuilder()
.setName(bigQueryExportName.toString())
.build();

BigQueryExport response = client.getBigQueryExport(bigQueryExportRequest);
System.out.printf("Retrieved the BigQuery export: %s", response.getName());
}
}
}
// [END securitycenter_get_bigquery_export_v2]
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package vtwo.bigquery;

// [START securitycenter_list_bigquery_export_v2]

import com.google.cloud.securitycenter.v2.BigQueryExport;
import com.google.cloud.securitycenter.v2.ListBigQueryExportsRequest;
import com.google.cloud.securitycenter.v2.OrganizationLocationName;
import com.google.cloud.securitycenter.v2.SecurityCenterClient;
import com.google.cloud.securitycenter.v2.SecurityCenterClient.ListBigQueryExportsPagedResponse;
import java.io.IOException;

public class ListBigQueryExports {

public static void main(String[] args) throws IOException {
// TODO(Developer): Modify the following variable values.
// organizationId: Google Cloud Organization id.
String organizationId = "{google-cloud-organization-id}";

// Specify the location to list the findings.
String location = "global";

listBigQueryExports(organizationId, location);
}

// List BigQuery exports in the given parent.
public static void listBigQueryExports(String organizationId, String location)
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()) {
OrganizationLocationName organizationName = OrganizationLocationName.of(organizationId,
location);

ListBigQueryExportsRequest request = ListBigQueryExportsRequest.newBuilder()
.setParent(organizationName.toString())
.build();

ListBigQueryExportsPagedResponse response = client.listBigQueryExports(request);

System.out.println("Listing BigQuery exports:");
for (BigQueryExport bigQueryExport : response.iterateAll()) {
System.out.println(bigQueryExport.getName());
}
}
}
}
// [END securitycenter_list_bigquery_export_v2]
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package vtwo.bigquery;

// [START securitycenter_update_bigquery_export_v2]

import com.google.cloud.securitycenter.v2.BigQueryExport;
import com.google.cloud.securitycenter.v2.BigQueryExportName;
import com.google.cloud.securitycenter.v2.SecurityCenterClient;
import com.google.cloud.securitycenter.v2.UpdateBigQueryExportRequest;
import com.google.protobuf.FieldMask;
import java.io.IOException;

public class UpdateBigQueryExport {

public static void main(String[] args) throws IOException {
// TODO(Developer): Modify the following variable values.
// organizationId: Google Cloud Organization id.
String organizationId = "{google-cloud-organization-id}";

// Specify the location to list the findings.
String location = "global";

// filter: Expression that defines the filter to apply across create/update events of findings.
String filter =
"severity=\"LOW\" OR severity=\"MEDIUM\" AND "
+ "category=\"Persistence: IAM Anomalous Grant\" AND "
+ "-resource.type:\"compute\"";

// bigQueryExportId: Unique identifier provided by the client.
// For more info, see:
// https://cloud.google.com/security-command-center/docs/how-to-analyze-findings-in-big-query#export_findings_from_to
String bigQueryExportId = "{bigquery-export-id}";

updateBigQueryExport(organizationId, location, filter, bigQueryExportId);
}

// Updates an existing BigQuery export.
public static void updateBigQueryExport(String organizationId, String location, String filter,
String bigQueryExportId)
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()) {
// optionally BigQueryExportName or String can be used
rafaelMurata marked this conversation as resolved.
Show resolved Hide resolved
// String bigQueryExportName = String.format("organizations/%s/locations/%s
// /bigQueryExports/%s",organizationId,location, bigQueryExportId);
BigQueryExportName bigQueryExportName = BigQueryExportName.of(organizationId, location,
bigQueryExportId);

// Set the new values for export configuration.
BigQueryExport bigQueryExport =
BigQueryExport.newBuilder()
.setName(bigQueryExportName.toString())
.setDescription("Updated description.")
.setFilter(filter)
.build();

UpdateBigQueryExportRequest request =
UpdateBigQueryExportRequest.newBuilder()
.setBigQueryExport(bigQueryExport)
// Set the update mask to specify which properties should be updated.
// If empty, all mutable fields will be updated.
// For more info on constructing field mask path, see the proto or:
// https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.FieldMask
.setUpdateMask(FieldMask.newBuilder()
.addPaths("filter")
.addPaths("description").build())
.build();

BigQueryExport response = client.updateBigQueryExport(request);
if (!response.getFilter().equalsIgnoreCase(filter)) {
System.out.println("Failed to update BigQueryExport!");
return;
}
System.out.println("BigQueryExport updated successfully!");
}
}
}
// [END securitycenter_update_bigquery_export_v2]
Loading