|
| 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() |
0 commit comments