Skip to content

Commit

Permalink
opt in using BUILD_SPECIFIC_GCLOUD_PROJECT
Browse files Browse the repository at this point in the history
  • Loading branch information
Takashi Matsuo committed Jun 2, 2020
1 parent 173df2c commit 81dece7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 17 deletions.
34 changes: 18 additions & 16 deletions dlp/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ This directory contains samples for Google Data Loss Prevention. `Google Data Lo

.. _Google Data Loss Prevention: https://cloud.google.com/dlp/docs/

To run the sample, you need to enable the API at: https://console.cloud.google.com/apis/library/dlp.googleapis.com


To run the sample, you need to have the following roles:
* `DLP Administrator`
* `DLP API Service Agent`



Setup
-------------------------------------------------------------------------------

Expand Down Expand Up @@ -58,15 +67,6 @@ Install Dependencies
.. _pip: https://pip.pypa.io/
.. _virtualenv: https://virtualenv.pypa.io/

#. For running *_test.py files, install test dependencies
.. code-block:: bash
$ pip install -r requirements-test.txt
$ pytest inspect_content_test.py
** *_test.py files are demo wrappers and make API calls. You may get rate limited for making high number of requests. **

Samples
-------------------------------------------------------------------------------

Expand All @@ -83,7 +83,7 @@ To run this sample:

.. code-block:: bash
$ python quickstart.py <project-id>
$ python quickstart.py
Inspect Content
Expand All @@ -101,15 +101,16 @@ To run this sample:
$ python inspect_content.py
usage: inspect_content.py [-h] {string,file,gcs,datastore,bigquery} ...
usage: inspect_content.py [-h] {string,table,file,gcs,datastore,bigquery} ...
Sample app that uses the Data Loss Prevention API to inspect a string, a local
file or a file on Google Cloud Storage.
positional arguments:
{string,file,gcs,datastore,bigquery}
{string,table,file,gcs,datastore,bigquery}
Select how to submit content to the API.
string Inspect a string.
table Inspect a table.
file Inspect a local file.
gcs Inspect files on Google Cloud Storage.
datastore Inspect files on Google Datastore.
Expand All @@ -135,13 +136,14 @@ To run this sample:
$ python redact.py
usage: redact.py [-h] [--project PROJECT] [--info_types INFO_TYPES]
usage: redact.py [-h] [--project PROJECT]
[--info_types INFO_TYPES [INFO_TYPES ...]]
[--min_likelihood {LIKELIHOOD_UNSPECIFIED,VERY_UNLIKELY,UNLIKELY,POSSIBLE,LIKELY,VERY_LIKELY}]
[--mime_type MIME_TYPE]
filename output_filename
Sample app that uses the Data Loss Prevent API to redact the contents of a
string or an image file.
Sample app that uses the Data Loss Prevent API to redact the contents of an
image file.
positional arguments:
filename The path to the file to inspect.
Expand All @@ -151,7 +153,7 @@ To run this sample:
-h, --help show this help message and exit
--project PROJECT The Google Cloud project id to use as a parent
resource.
--info_types INFO_TYPES
--info_types INFO_TYPES [INFO_TYPES ...]
Strings representing info types to look for. A full
list of info categories and types is available from
the API. Examples include "FIRST_NAME", "LAST_NAME",
Expand Down
8 changes: 7 additions & 1 deletion dlp/README.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ product:
name: Google Data Loss Prevention
short_name: Data Loss Prevention
url: https://cloud.google.com/dlp/docs/
description: >
description: >
`Google Data Loss Prevention`_ provides programmatic access to a powerful
detection engine for personally identifiable information and other
privacy-sensitive data in unstructured data streams.
Expand All @@ -13,6 +13,12 @@ setup:
- auth
- install_deps

required_api_url: https://console.cloud.google.com/apis/library/dlp.googleapis.com

required_roles:
- DLP Administrator
- DLP API Service Agent

samples:
- name: Quickstart
file: quickstart.py
Expand Down
37 changes: 37 additions & 0 deletions dlp/noxfile_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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': 'GCLOUD_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': {},
}
7 changes: 7 additions & 0 deletions scripts/readme-gen/templates/README.tmpl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ To run the sample, you need to enable the API at: {{required_api_url}}
To run the sample, you need to have `{{required_role}}` role.
{% endif %}

{% if required_roles %}
To run the sample, you need to have the following roles:
{% for role in required_roles %}
* `{{role}}`
{% endfor %}
{% endif %}

{{other_required_steps}}

{% if setup %}
Expand Down

0 comments on commit 81dece7

Please sign in to comment.