Skip to content

Python KMS Apiary P1 samples #779

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 22 commits into from
Feb 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
14 changes: 7 additions & 7 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ def api_client_inject_project_id(cloud_config):
the project ID from cloud_config."""
import googleapiclient.http

class ProjectIdInjectingHttpRequest(googleapiclient.http.HttpRequest):
def __init__(self, http, postproc, uri, *args, **kwargs):
uri = uri.replace('YOUR_PROJECT_ID', cloud_config.project)
super(ProjectIdInjectingHttpRequest, self).__init__(
http, postproc, uri, *args, **kwargs)
old_execute = googleapiclient.http.HttpRequest.execute

def new_execute(self, http=None, num_retries=0):
self.uri = self.uri.replace('YOUR_PROJECT_ID', cloud_config.project)
return old_execute(self, http=http, num_retries=num_retries)

with mock.patch(
'googleapiclient.http.HttpRequest',
new=ProjectIdInjectingHttpRequest):
'googleapiclient.http.HttpRequest.execute',
new=new_execute):
yield
109 changes: 109 additions & 0 deletions kms/api-client/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
.. This file is automatically generated. Do not edit this file directly.

Google Cloud KMS API Python Samples
===============================================================================

This directory contains samples for Google Cloud KMS API. 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.




.. _Google Cloud KMS API: https://cloud.google.com/kms/docs/

Setup
-------------------------------------------------------------------------------


Authentication
++++++++++++++

Authentication is typically done through `Application Default Credentials`_,
which means you do not have to change the code to authenticate as long as
your environment has credentials. You have a few options for setting up
authentication:

#. When running locally, use the `Google Cloud SDK`_

.. code-block:: bash

gcloud beta auth application-default login


#. When running on App Engine or Compute Engine, credentials are already
set-up. However, you may need to configure your Compute Engine instance
with `additional scopes`_.

#. You can create a `Service Account key file`_. This file can be used to
authenticate to Google Cloud Platform services from any environment. To use
the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to
the path to the key file, for example:

.. code-block:: bash

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json

.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow
.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using
.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount

Install Dependencies
++++++++++++++++++++

#. Install `pip`_ and `virtualenv`_ if you do not already have them.

#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.

.. code-block:: bash

$ virtualenv env
$ source env/bin/activate

#. Install the dependencies needed to run the samples.

.. code-block:: bash

$ pip install -r requirements.txt

.. _pip: https://pip.pypa.io/
.. _virtualenv: https://virtualenv.pypa.io/

Samples
-------------------------------------------------------------------------------

Quickstart
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



To run this sample:

.. code-block:: bash

$ python quickstart.py


Snippets
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



To run this sample:

.. code-block:: bash

$ python snippets.py

usage: snippets.py [-h]
{create_keyring,create_cryptokey,encrypt,decrypt,disable_cryptokey_version,destroy_cryptokey_version,add_member_to_cryptokey_policy,get_keyring_policy}
...

positional arguments:
{create_keyring,create_cryptokey,encrypt,decrypt,disable_cryptokey_version,destroy_cryptokey_version,add_member_to_cryptokey_policy,get_keyring_policy}

optional arguments:
-h, --help show this help message and exit




.. _Google Cloud SDK: https://cloud.google.com/sdk/
3 changes: 3 additions & 0 deletions kms/api/README.rst.in → kms/api-client/README.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ setup:
samples:
- name: Quickstart
file: quickstart.py
- name: Snippets
file: snippets.py
show_help: True
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
# limitations under the License.


def test_quickstart(api_client_inject_project_id, capsys):
def test_quickstart(api_client_inject_project_id):
import quickstart

quickstart.run_quickstart()
out, _ = capsys.readouterr()
assert 'No key rings found' in out
File renamed without changes.
Loading