-
Notifications
You must be signed in to change notification settings - Fork 6.6k
migrate code from googleapis/python-securitycenter #8493
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
Merged
Merged
Changes from all commits
Commits
Show all changes
111 commits
Select commit
Hold shift + click to select a range
160aff4
chore(samples): move samples and use standard templates for testing (…
busunkim96 288e035
chore(deps): update dependency google-cloud-pubsub to v1.7.0 (#42)
renovate-bot fb71400
docs: Update Security Command Center UpdateNotificationConfig sample,…
hannah-tsai 9127d9c
feat: add field severity to findings; update retry configs (#53)
yoshi-automation 0c27bf8
fix(sample): fix a broken test (#63)
02def84
chore(deps): update dependency google-cloud-securitycenter to v0.7.1 …
renovate-bot 52b3040
chore(deps): update dependency google-cloud-pubsub to v2 (#61)
renovate-bot 21e6a58
feat!: generate with microgenerator (#49)
busunkim96 fdd8f94
chore(deps): update dependency google-cloud-securitycenter to v1 (#70)
renovate-bot 15815bb
docs: update snippets_findings tags (#78)
Pglinsman 8024423
docs: update snippets_list_assets tags (#77)
Pglinsman 21a7879
chore(deps): update dependency google-cloud-pubsub to v2.2.0 (#84)
renovate-bot 8bce842
docs: add securitycenter prefix to samples, wrap published samples an…
Strykrol 4315441
chore(deps): update dependency google-cloud-securitycenter to v1.1.0 …
renovate-bot 7523bbb
chore: update templates (#88)
yoshi-automation dce59da
chore(deps): update dependency google-cloud-pubsub to v2.3.0 (#102)
renovate-bot 40fee09
docs: standardize new tag with existing tags from other languages (#104)
5f50a2d
chore(deps): update dependency google-cloud-pubsub to v2.4.0 (#107)
renovate-bot 98165b9
docs: Fix conflict tag introduced in PR 104 (#106)
b568a86
fix: fix retry deadlines (#116)
yoshi-automation aabac32
chore(deps): update dependency google-cloud-pubsub to v2.4.1 (#119)
renovate-bot a2a3061
chore: migrate to owlbot (#129)
parthea 6a3b706
chore(deps): update dependency google-cloud-securitycenter to v1.2.0 …
renovate-bot 1f25195
test: log message.data for debugging (#126)
dandhlee 3d88ea6
chore(deps): update dependency google-cloud-pubsub to v2.5.0 (#138)
renovate-bot 264fc19
docs: remove unused region tags (#108)
5e74c01
chore: new owl bot post processor docker image (#155)
gcf-owl-bot[bot] 21da4bc
chore(deps): update dependency google-cloud-securitycenter to v1.3.0 …
renovate-bot ee6df16
chore(deps): update dependency google-cloud-securitycenter to v1.3.1 …
renovate-bot 552a6a1
chore(deps): update dependency google-cloud-pubsub to v2.6.0 (#168)
renovate-bot 8202aea
chore(deps): update dependency google-cloud-pubsub to v2.6.1 (#175)
renovate-bot 2683324
chore(deps): update dependency google-cloud-securitycenter to v1.4.0 …
renovate-bot f1ac850
feat: add Samples section to CONTRIBUTING.rst (#195)
gcf-owl-bot[bot] 8396af5
chore(deps): update dependency google-cloud-securitycenter to v1.5.0 …
renovate-bot 0fcc028
chore(deps): update dependency google-cloud-pubsub to v2.7.0 (#203)
renovate-bot eac0296
chore: fix INSTALL_LIBRARY_FROM_SOURCE in noxfile.py (#205)
gcf-owl-bot[bot] 1c668cb
chore: drop mention of Python 2.7 from templates (#207)
gcf-owl-bot[bot] d11c7c2
chore(samples): use timezone aware datetimes (#208)
busunkim96 8bec4dc
chore(deps): update dependency google-cloud-pubsub to v2.8.0 (#216)
renovate-bot e1590d7
chore: blacken samples noxfile template (#218)
gcf-owl-bot[bot] a2271a7
chore(deps): update dependency google-cloud-securitycenter to v1.5.1 …
renovate-bot 0afba93
chore: fail samples nox session if python version is missing (#226)
gcf-owl-bot[bot] bcaa465
chore(deps): update dependency google-cloud-securitycenter to v1.5.2 …
renovate-bot ba98724
chore(deps): update dependency google-cloud-securitycenter to v1.6.0 …
renovate-bot 86213ab
chore(python): Add kokoro configs for python 3.10 samples testing (#234)
gcf-owl-bot[bot] c45994a
chore(deps): update dependency google-cloud-securitycenter to v1.7.0 …
renovate-bot bf7a61f
feat: add support for python 3.10 (#238)
parthea 3801f2f
chore(deps): update dependency google-cloud-pubsub to v2.9.0 (#251)
renovate-bot 5881049
chore(python): add .github/CODEOWNERS as a templated file (#252)
gcf-owl-bot[bot] 5078179
chore(samples): Add check for tests in directory (#264)
gcf-owl-bot[bot] 15ee3c4
chore(deps): update dependency google-cloud-securitycenter to v1.8.0 …
renovate-bot c0c0b63
chore(python): Noxfile recognizes that tests can live in a folder (#270)
gcf-owl-bot[bot] 6811864
chore(deps): update all dependencies (#286)
renovate-bot 0186b1a
chore: Adding support for pytest-xdist and pytest-parallel (#295)
gcf-owl-bot[bot] af74c17
chore(deps): update dependency google-cloud-pubsub to v2.10.0 (#297)
renovate-bot a7e9b82
chore(deps): update dependency google-cloud-securitycenter to v1.10.0…
renovate-bot 3248759
chore(deps): update dependency google-cloud-pubsub to v2.11.0 (#299)
renovate-bot 01653f4
docs(samples): added mute config samples (#276)
Sita04 6444a15
chore(python): use black==22.3.0 (#307)
gcf-owl-bot[bot] 952308a
docs(samples): included snippet for unmute finding (#308)
Sita04 99a2a6f
chore(deps): update dependency google-cloud-pubsub to v2.12.0 (#318)
renovate-bot 9f8100f
chore(python): add nox session to sort python imports (#324)
gcf-owl-bot[bot] 517104d
docs(samples): add bigquery export samples (#315)
Sita04 9629a04
chore(deps): update all dependencies (#327)
renovate-bot a2f239e
chore(deps): update dependency google-cloud-securitycenter to v1.11.0…
renovate-bot 2b03dd3
chore(deps): update dependency google-cloud-bigquery to v3.1.0 (#332)
renovate-bot c5e53a9
chore(deps): update dependency google-cloud-pubsub to v2.12.1 (#333)
renovate-bot ff62ae4
fix: require python 3.7+ (#349)
gcf-owl-bot[bot] 89ab1ac
chore(deps): update all dependencies (#342)
renovate-bot 827589d
chore(deps): update all dependencies (#357)
renovate-bot 66264df
chore(deps): update all dependencies (#359)
renovate-bot 25c7217
chore(deps): update dependency google-cloud-pubsub to v2.13.5 (#361)
renovate-bot 8ba7e2f
chore(deps): update dependency google-cloud-pubsub to v2.13.6 (#363)
renovate-bot bd51fdb
chore(deps): update dependency google-cloud-securitycenter to v1.13.0…
renovate-bot 332b5c4
chore(deps): update dependency google-cloud-bigquery to v3.3.2 (#366)
renovate-bot 8d8a3d3
chore(deps): update dependency google-cloud-securitycenter to v1.14.0…
renovate-bot 476786f
chore(deps): update dependency google-cloud-securitycenter to v1.15.0…
renovate-bot 781b387
chore(deps): update dependency pytest to v7.1.3 (#384)
renovate-bot 0ed25e1
chore: detect samples tests in nested directories (#389)
gcf-owl-bot[bot] 1c4e4ec
chore(deps): update dependency google-cloud-securitycenter to v1.16.0…
renovate-bot 4203f60
chore(deps): update dependency google-cloud-pubsub to v2.13.7 (#393)
renovate-bot 1f29105
chore(deps): update dependency google-cloud-bigquery to v3.3.3 (#396)
renovate-bot 49fa28a
chore(deps): update dependency google-cloud-securitycenter to v1.16.1…
renovate-bot 839d305
chore(deps): update dependency google-cloud-securitycenter to v1.16.2…
renovate-bot 20e5f3f
chore(deps): update all dependencies (#402)
renovate-bot 22b343b
chore(deps): update dependency pytest to v7.2.0 (#406)
renovate-bot c451317
docs(samples): update samples to include new parent levels (folder an…
Sita04 3648683
Merge remote-tracking branch 'migration/main' into python-securitycen…
donmccasland c9196d8
removing noxfile.py
donmccasland 7f90301
Update securitycenter/snippets/noxfile_config.py
dandhlee 7e6cfc5
revert noxfile config test
dandhlee 50e6888
Merge branch 'main' into python-securitycenter-migration
dandhlee 3b9c4ea
Merge branch 'main' into python-securitycenter-migration
donmccasland cccd33f
Adding CODEOWNERS and blunderbuss config
donmccasland c6b218c
updting noxfile to use old securitycenter test project
donmccasland b15434c
fixing noxfile config
donmccasland ed6f205
fixing noxfile config
donmccasland dd25c5b
Update securitycenter/snippets/noxfile_config.py
leahecole 1cc7b7e
Merge branch 'main' into python-securitycenter-migration
donmccasland 260943b
Merge branch 'main' into python-securitycenter-migration
Sita04 c308722
Merge branch 'main' into python-securitycenter-migration
donmccasland c823bc0
Merge branch 'main' into python-securitycenter-migration
donmccasland a76d04b
Merge branch 'main' into python-securitycenter-migration
Sita04 5b9c716
Merge branch 'main' into python-securitycenter-migration
Sita04 316cd0d
Merge branch 'main' into python-securitycenter-migration
Sita04 4df1c9f
Merge branch 'main' into python-securitycenter-migration
Sita04 b5b63b0
Merge branch 'main' into python-securitycenter-migration
Sita04 60ca150
Merge branch 'main' into python-securitycenter-migration
Sita04 0b26c3d
Merge branch 'main' into python-securitycenter-migration
Sita04 8139c00
Merge branch 'main' into python-securitycenter-migration
Sita04 95bef4f
Merge branch 'main' into python-securitycenter-migration
Sita04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/CONTRIBUTING.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright 2020 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. | ||
|
||
# Default TEST_CONFIG_OVERRIDE for python repos. | ||
|
||
# You can copy this file into your directory, then it will be inported from | ||
# the noxfile.py. | ||
|
||
# The source of truth: | ||
# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py | ||
|
||
TEST_CONFIG_OVERRIDE = { | ||
# You can opt out from the test for specific Python versions. | ||
"ignored_versions": ["2.7"], | ||
# An envvar key for determining the project id to use. Change it | ||
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a | ||
# build specific Cloud project. You can also use your own string | ||
# to use your own Cloud project. | ||
# 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', | ||
"gcloud_project_env": "BUILD_SPECIFIC_GCLOUD_PROJECT", | ||
# A dictionary you want to inject into your test. Don't put any | ||
# secrets here. These values will override predefined values. | ||
"envs": { | ||
"GCLOUD_ORGANIZATION": "1081635000895", | ||
"GCLOUD_PROJECT": "project-a-id", | ||
"GCLOUD_PUBSUB_TOPIC": "projects/project-a-id/topics/notifications-sample-topic", | ||
"GCLOUD_PUBSUB_SUBSCRIPTION": "notification-sample-subscription", | ||
}, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pytest==7.2.0 | ||
google-cloud-bigquery==3.3.5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
google-cloud-pubsub==2.13.10 | ||
google-cloud-securitycenter==1.16.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2022 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 | ||
# | ||
# https://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. | ||
|
||
"""Snippets on exporting findings from Security Command Center to BigQuery.""" | ||
|
||
|
||
# [START securitycenter_create_bigquery_export] | ||
|
||
|
||
def create_bigquery_export( | ||
parent: str, export_filter: str, bigquery_dataset_id: str, bigquery_export_id: str | ||
): | ||
|
||
from google.cloud import securitycenter | ||
|
||
""" | ||
Create export configuration to export findings from a project to a BigQuery dataset. | ||
Optionally specify filter to export certain findings only. | ||
|
||
Args: | ||
parent: Use any one of the following resource paths: | ||
- organizations/{organization_id} | ||
- folders/{folder_id} | ||
- projects/{project_id} | ||
export_filter: Expression that defines the filter to apply across create/update events of findings. | ||
bigquery_dataset_id: The BigQuery dataset to write findings' updates to. | ||
bigquery_export_id: Unique identifier provided by the client. | ||
- example id: f"default-{str(uuid.uuid4()).split('-')[0]}" | ||
For more info, see: | ||
https://cloud.google.com/security-command-center/docs/how-to-analyze-findings-in-big-query#export_findings_from_to | ||
""" | ||
client = securitycenter.SecurityCenterClient() | ||
|
||
# Create the BigQuery export configuration. | ||
bigquery_export = securitycenter.BigQueryExport() | ||
bigquery_export.description = "Export low and medium findings if the compute resource has an IAM anomalous grant" | ||
bigquery_export.filter = export_filter | ||
bigquery_export.dataset = f"{parent}/datasets/{bigquery_dataset_id}" | ||
|
||
request = securitycenter.CreateBigQueryExportRequest() | ||
request.parent = parent | ||
request.big_query_export = bigquery_export | ||
request.big_query_export_id = bigquery_export_id | ||
|
||
# Create the export request. | ||
response = client.create_big_query_export(request) | ||
|
||
print(f"BigQuery export request created successfully: {response.name}\n") | ||
|
||
|
||
# [END securitycenter_create_bigquery_export] | ||
|
||
|
||
# [START securitycenter_get_bigquery_export] | ||
def get_bigquery_export(parent: str, bigquery_export_id: str): | ||
from google.cloud import securitycenter | ||
|
||
""" | ||
Retrieve an existing BigQuery export. | ||
Args: | ||
parent: Use any one of the following resource paths: | ||
- organizations/{organization_id} | ||
- folders/{folder_id} | ||
- projects/{project_id} | ||
bigquery_export_id: Unique identifier that is used to identify the export. | ||
""" | ||
|
||
client = securitycenter.SecurityCenterClient() | ||
|
||
request = securitycenter.GetBigQueryExportRequest() | ||
request.name = f"{parent}/bigQueryExports/{bigquery_export_id}" | ||
|
||
response = client.get_big_query_export(request) | ||
print(f"Retrieved the BigQuery export: {response.name}") | ||
|
||
|
||
# [END securitycenter_get_bigquery_export] | ||
|
||
|
||
# [START securitycenter_list_bigquery_export] | ||
def list_bigquery_exports(parent: str): | ||
from google.cloud import securitycenter | ||
|
||
""" | ||
List BigQuery exports in the given parent. | ||
Args: | ||
parent: The parent which owns the collection of BigQuery exports. | ||
Use any one of the following resource paths: | ||
- organizations/{organization_id} | ||
- folders/{folder_id} | ||
- projects/{project_id} | ||
""" | ||
|
||
client = securitycenter.SecurityCenterClient() | ||
|
||
request = securitycenter.ListBigQueryExportsRequest() | ||
request.parent = parent | ||
|
||
response = client.list_big_query_exports(request) | ||
|
||
print("Listing BigQuery exports:") | ||
for bigquery_export in response: | ||
print(bigquery_export.name) | ||
|
||
|
||
# [END securitycenter_list_bigquery_export] | ||
|
||
|
||
# [START securitycenter_update_bigquery_export] | ||
def update_bigquery_export(parent: str, export_filter: str, bigquery_export_id: str): | ||
""" | ||
Updates an existing BigQuery export. | ||
Args: | ||
parent: Use any one of the following resource paths: | ||
- organizations/{organization_id} | ||
- folders/{folder_id} | ||
- projects/{project_id} | ||
export_filter: Expression that defines the filter to apply across create/update events of findings. | ||
bigquery_export_id: 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 | ||
""" | ||
from google.cloud import securitycenter | ||
from google.protobuf import field_mask_pb2 | ||
|
||
client = securitycenter.SecurityCenterClient() | ||
|
||
# Set the new values for export configuration. | ||
bigquery_export = securitycenter.BigQueryExport() | ||
bigquery_export.name = f"{parent}/bigQueryExports/{bigquery_export_id}" | ||
bigquery_export.filter = export_filter | ||
|
||
# Field mask to only update the export filter. | ||
# 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://googleapis.dev/python/protobuf/latest/google/protobuf/field_mask_pb2.html | ||
field_mask = field_mask_pb2.FieldMask(paths=["filter"]) | ||
|
||
request = securitycenter.UpdateBigQueryExportRequest() | ||
request.big_query_export = bigquery_export | ||
request.update_mask = field_mask | ||
|
||
response = client.update_big_query_export(request) | ||
|
||
if response.filter != export_filter: | ||
print("Failed to update BigQueryExport!") | ||
return | ||
print("BigQueryExport updated successfully!") | ||
|
||
|
||
# [END securitycenter_update_bigquery_export] | ||
|
||
|
||
# [START securitycenter_delete_bigquery_export] | ||
def delete_bigquery_export(parent: str, bigquery_export_id: str): | ||
""" | ||
Delete an existing BigQuery export. | ||
Args: | ||
parent: Use any one of the following resource paths: | ||
- organizations/{organization_id} | ||
- folders/{folder_id} | ||
- projects/{project_id} | ||
bigquery_export_id: Unique identifier that is used to identify the export. | ||
""" | ||
from google.cloud import securitycenter | ||
|
||
client = securitycenter.SecurityCenterClient() | ||
|
||
request = securitycenter.DeleteBigQueryExportRequest() | ||
request.name = f"{parent}/bigQueryExports/{bigquery_export_id}" | ||
|
||
client.delete_big_query_export(request) | ||
print(f"BigQuery export request deleted successfully: {bigquery_export_id}") | ||
|
||
|
||
# [END securitycenter_delete_bigquery_export] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2022 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 | ||
# | ||
# https://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. | ||
|
||
|
||
# TODO(developer): Replace these variables before running the sample. | ||
import os | ||
import re | ||
import uuid | ||
|
||
from _pytest.capture import CaptureFixture | ||
import pytest | ||
|
||
import snippets_bigquery_export | ||
|
||
PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"] | ||
GOOGLE_APPLICATION_CREDENTIALS = os.environ["GOOGLE_APPLICATION_CREDENTIALS"] | ||
BIGQUERY_DATASET_ID = f"sampledataset{str(uuid.uuid4()).split('-')[0]}" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def bigquery_export_id(): | ||
bigquery_export_id = f"default-{str(uuid.uuid4()).split('-')[0]}" | ||
|
||
create_bigquery_dataset(BIGQUERY_DATASET_ID) | ||
export_filter = 'severity="LOW" OR severity="MEDIUM"' | ||
snippets_bigquery_export.create_bigquery_export( | ||
f"projects/{PROJECT_ID}", export_filter, BIGQUERY_DATASET_ID, bigquery_export_id | ||
) | ||
|
||
yield bigquery_export_id | ||
|
||
snippets_bigquery_export.delete_bigquery_export( | ||
f"projects/{PROJECT_ID}", bigquery_export_id | ||
) | ||
delete_bigquery_dataset(BIGQUERY_DATASET_ID) | ||
|
||
|
||
def create_bigquery_dataset(dataset_id: str): | ||
from google.cloud import bigquery | ||
|
||
bigquery_client = bigquery.Client() | ||
|
||
dataset_id_full = "{}.{}".format(PROJECT_ID, dataset_id) | ||
dataset = bigquery.Dataset(dataset_id_full) | ||
|
||
dataset = bigquery_client.create_dataset(dataset) | ||
print("Dataset {} created.".format(dataset.dataset_id)) | ||
|
||
|
||
def delete_bigquery_dataset(dataset_id: str): | ||
from google.cloud import bigquery | ||
|
||
bigquery_client = bigquery.Client() | ||
bigquery_client.delete_dataset(dataset_id) | ||
print("Dataset {} deleted.".format(dataset_id)) | ||
|
||
|
||
def test_get_bigquery_export(capsys: CaptureFixture, bigquery_export_id: str): | ||
snippets_bigquery_export.get_bigquery_export( | ||
f"projects/{PROJECT_ID}", bigquery_export_id | ||
) | ||
out, _ = capsys.readouterr() | ||
assert re.search( | ||
"Retrieved the BigQuery export", | ||
out, | ||
) | ||
assert re.search(f"bigQueryExports/{bigquery_export_id}", out) | ||
|
||
|
||
def test_list_bigquery_exports(capsys: CaptureFixture, bigquery_export_id: str): | ||
snippets_bigquery_export.list_bigquery_exports(f"projects/{PROJECT_ID}") | ||
out, _ = capsys.readouterr() | ||
assert re.search("Listing BigQuery exports:", out) | ||
assert re.search(bigquery_export_id, out) | ||
|
||
|
||
def test_update_bigquery_exports(capsys: CaptureFixture, bigquery_export_id: str): | ||
export_filter = 'severity="MEDIUM"' | ||
snippets_bigquery_export.update_bigquery_export( | ||
f"projects/{PROJECT_ID}", export_filter, bigquery_export_id | ||
) | ||
out, _ = capsys.readouterr() | ||
assert re.search("BigQueryExport updated successfully!", out) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.