Skip to content
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

Python KMS Apiary P1 samples #779

Merged
merged 22 commits into from
Feb 7, 2017
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9f67a99
Draft of first half of KMS samples
ryanmats Jan 31, 2017
6d82309
reversed wrong change
ryanmats Jan 31, 2017
5529d40
KMS Apiary Python samples - P1
ryanmats Feb 2, 2017
13c7c74
Merge branch 'master' of https://github.com/GoogleCloudPlatform/pytho…
ryanmats Feb 2, 2017
491b6d9
Few minor style issues
ryanmats Feb 2, 2017
21f812c
Adding back in space i accidentally deleted
ryanmats Feb 2, 2017
2a92880
Addressed all code review comments
ryanmats Feb 3, 2017
17c735c
Merge branch 'master' of https://github.com/GoogleCloudPlatform/pytho…
ryanmats Feb 3, 2017
9cf08a4
Renamed api directory to api-client
ryanmats Feb 3, 2017
d8d15db
Merge branch 'master' of https://github.com/GoogleCloudPlatform/pytho…
ryanmats Feb 6, 2017
816877a
Addressed more code review comments
ryanmats Feb 6, 2017
51ef300
Formatting change
ryanmats Feb 7, 2017
1be099c
Fix quickstart test
Feb 7, 2017
eb07c44
Merge branch 'python-kms-samples' of github.com:GoogleCloudPlatform/p…
Feb 7, 2017
8e9f3d0
Update readme
Feb 7, 2017
14fb5c0
Add readme
Feb 7, 2017
b44fdfd
Added parsers
ryanmats Feb 7, 2017
6ee4bd9
Merge branch 'python-kms-samples' of https://github.com/GoogleCloudPl…
ryanmats Feb 7, 2017
ce75417
Final minor changes to parsers
ryanmats Feb 7, 2017
842af60
Added autogenerated README
ryanmats Feb 7, 2017
599341f
Merge branch 'master' of https://github.com/GoogleCloudPlatform/pytho…
ryanmats Feb 7, 2017
1c53533
Changed snippets_test keyring name and cryptokey name
ryanmats Feb 7, 2017
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
107 changes: 107 additions & 0 deletions kms/api-client/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
.. 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] {encrypt,decrypt,other} ...

positional arguments:
{encrypt,decrypt,other}

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