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

Commit

Permalink
Add a PolicyTagManagerClient.create_taxonomy sample
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardolsmendes committed May 29, 2020
1 parent 9fcf86f commit 1f97216
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
27 changes: 27 additions & 0 deletions samples/tests/test_create_taxonomy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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
#
# 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.


from ..v1beta1 import create_taxonomy


def test_create_taxonomy(capsys, client, project_id):

create_taxonomy.create_taxonomy(client, project_id)
out, err = capsys.readouterr()
assert (
"Created taxonomy"
" projects/{}/locations/{}/taxonomies/".format(project_id, "us")
in out
)
45 changes: 45 additions & 0 deletions samples/v1beta1/create_taxonomy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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
#
# 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.


def create_taxonomy(client, project_id):

# [START datacatalog_create_taxonomy_tag]
from google.cloud import datacatalog_v1beta1

# TODO(developer): Construct a Policy Tag Manager client object.
# client = datacatalog_v1beta1.PolicyTagManagerClient()

# TODO(developer): Set project_id to the ID of the project the
# taxonomy will belong to.
# project_id = "your-project-id"

# TODO(developer): Specify the geographic location where the
# taxonomy should reside.
location_id = "us"

# Construct a full location path to be the parent of the taxonomy.
parent = datacatalog_v1beta1.PolicyTagManagerClient.location_path(
project_id, location_id
)

# Construct a full Taxonomy object to send to the API.
taxonomy = datacatalog_v1beta1.types.Taxonomy()
taxonomy.display_name = "My Taxonomy"
taxonomy.description = "This Taxonomy represents ..."

# Send the taxonomy to the API for creation.
taxonomy = client.create_taxonomy(parent, taxonomy) # Make an API request.
print("Created taxonomy {}".format(taxonomy.name))
# [END datacatalog_create_taxonomy_tag]

0 comments on commit 1f97216

Please sign in to comment.