This repository has been archived by the owner on Sep 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a PolicyTagManagerClient.create_taxonomy sample
- Loading branch information
1 parent
9fcf86f
commit 1f97216
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,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 | ||
) |
This file contains 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,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] |