Skip to content

Add KMS quickstart #753

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 1 commit into from
Jan 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions kms/api/README.rst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file is used to generate README.rst

product:
name: Google Cloud KMS API
short_name: Cloud KMS API
url: https://cloud.google.com/kms/docs/
description: >
The `Google Cloud KMS API`_ is a service that allows you to keep encryption
keys centrally in the cloud, for direct use by cloud services.

setup:
- auth
- install_deps

samples:
- name: Quickstart
file: quickstart.py
48 changes: 48 additions & 0 deletions kms/api/quickstart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python

# Copyright 2017 Google, Inc
#
# 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


def run_quickstart():
# [START kms_quickstart]
# Imports the Google APIs client library
from googleapiclient import discovery

# Your Google Cloud Platform project ID
project_id = 'YOUR_PROJECT_ID'

# The "global" zone lists all keys. It can be a specific zone if desired.
zone = 'global'

# Instantiates a client
kms_client = discovery.build('cloudkms', 'v1beta1')

# The resource name of the location associated with the KeyRings
parent = 'projects/{}/locations/{}'.format(project_id, zone)

# Lists key rings
request = kms_client.projects().locations().keyRings().list(parent=parent)
response = request.execute()

if 'key_rings' in response and len(response['key_rings']):
print('Key rings:')
for key_ring in response['key_rings']:
print(key_ring['name'])
else:
print('No key rings found.')
# [END kms_quickstart]


if __name__ == '__main__':
run_quickstart()
1 change: 1 addition & 0 deletions kms/api/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
google-api-python-client==1.6.0