Skip to content

Commit fa8bc81

Browse files
jmdobryJon Wayne Parrott
authored andcommitted
Add KMS quickstart (#753)
1 parent 1fa7115 commit fa8bc81

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

kms/api/README.rst.in

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file is used to generate README.rst
2+
3+
product:
4+
name: Google Cloud KMS API
5+
short_name: Cloud KMS API
6+
url: https://cloud.google.com/kms/docs/
7+
description: >
8+
The `Google Cloud KMS API`_ is a service that allows you to keep encryption
9+
keys centrally in the cloud, for direct use by cloud services.
10+
11+
setup:
12+
- auth
13+
- install_deps
14+
15+
samples:
16+
- name: Quickstart
17+
file: quickstart.py

kms/api/quickstart.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2017 Google, Inc
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
16+
17+
def run_quickstart():
18+
# [START kms_quickstart]
19+
# Imports the Google APIs client library
20+
from googleapiclient import discovery
21+
22+
# Your Google Cloud Platform project ID
23+
project_id = 'YOUR_PROJECT_ID'
24+
25+
# The "global" zone lists all keys. It can be a specific zone if desired.
26+
zone = 'global'
27+
28+
# Instantiates a client
29+
kms_client = discovery.build('cloudkms', 'v1beta1')
30+
31+
# The resource name of the location associated with the KeyRings
32+
parent = 'projects/{}/locations/{}'.format(project_id, zone)
33+
34+
# Lists key rings
35+
request = kms_client.projects().locations().keyRings().list(parent=parent)
36+
response = request.execute()
37+
38+
if 'key_rings' in response and len(response['key_rings']):
39+
print('Key rings:')
40+
for key_ring in response['key_rings']:
41+
print(key_ring['name'])
42+
else:
43+
print('No key rings found.')
44+
# [END kms_quickstart]
45+
46+
47+
if __name__ == '__main__':
48+
run_quickstart()

kms/api/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-api-python-client==1.6.0

0 commit comments

Comments
 (0)