From 43e5289fe058c43bac7a25f96dd57b647cc1e02f Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Tue, 10 Jan 2017 14:06:42 -0800 Subject: [PATCH] Add KMS quickstart --- kms/api/README.rst.in | 17 ++++++++++++++ kms/api/quickstart.py | 48 ++++++++++++++++++++++++++++++++++++++++ kms/api/requirements.txt | 1 + 3 files changed, 66 insertions(+) create mode 100644 kms/api/README.rst.in create mode 100644 kms/api/quickstart.py create mode 100644 kms/api/requirements.txt diff --git a/kms/api/README.rst.in b/kms/api/README.rst.in new file mode 100644 index 00000000000..68901cf1154 --- /dev/null +++ b/kms/api/README.rst.in @@ -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 diff --git a/kms/api/quickstart.py b/kms/api/quickstart.py new file mode 100644 index 00000000000..d8313cabbec --- /dev/null +++ b/kms/api/quickstart.py @@ -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() diff --git a/kms/api/requirements.txt b/kms/api/requirements.txt new file mode 100644 index 00000000000..c144b50f591 --- /dev/null +++ b/kms/api/requirements.txt @@ -0,0 +1 @@ +google-api-python-client==1.6.0 \ No newline at end of file