Skip to content

Commit

Permalink
Merge pull request googleapis#2485 from tswast/master
Browse files Browse the repository at this point in the history
Add support for RuntimeConfig API.
  • Loading branch information
tswast authored Oct 25, 2016
2 parents ebff66f + c7f5b48 commit 0258fb7
Show file tree
Hide file tree
Showing 20 changed files with 1,604 additions and 0 deletions.
11 changes: 11 additions & 0 deletions runtimeconfig/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[run]
branch = True

[report]
fail_under = 100
show_missing = True
exclude_lines =
# Re-enable the standard pragma
pragma: NO COVER
# Ignore debug-only repr
def __repr__
4 changes: 4 additions & 0 deletions runtimeconfig/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include README.rst
graft google
graft unit_tests
global-exclude *.pyc
44 changes: 44 additions & 0 deletions runtimeconfig/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Python Client for Google Cloud RuntimeConfig
============================================

Python idiomatic client for `Google Cloud RuntimeConfig`_

.. _Google Cloud RuntimeConfig: https://cloud.google.com/deployment-manager/runtime-configurator/

- `Documentation`_

.. _Documentation: http://googlecloudplatform.github.io/google-cloud-python/

Quick Start
-----------

::

$ pip install --upgrade google-cloud-runtimeconfig

Authentication
--------------

With ``google-cloud-python`` we try to make authentication as painless as
possible. Check out the `Authentication section`_ in our documentation to
learn more. You may also find the `authentication document`_ shared by all
the ``google-cloud-*`` libraries to be helpful.

.. _Authentication section: http://google-cloud-python.readthedocs.io/en/latest/google-cloud-auth.html
.. _authentication document: https://github.com/GoogleCloudPlatform/gcloud-common/tree/master/authentication

Using the API
-------------

The Google Cloud `RuntimeConfig`_ (`RuntimeConfig API docs`_) API enables
developers to dynamically configure and expose variables through Google Cloud
Platform. In addition, you can also set Watchers and Waiters that will watch
for changes to your data and return based on certain conditions.

.. _RuntimeConfig: https://cloud.google.com/deployment-manager/runtime-configurator/
.. _RuntimeConfig API docs: https://cloud.google.com/deployment-manager/runtime-configurator/reference/rest/

See the ``google-cloud-python`` API `runtimeconfig documentation`_ to learn
how to interact with Cloud RuntimeConfig using this Client Library.

.. _RuntimeConfig documentation: https://google-cloud-python.readthedocs.io/en/stable/runtimeconfig-usage.html
20 changes: 20 additions & 0 deletions runtimeconfig/google/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2016 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
# limitations under the License.

try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
20 changes: 20 additions & 0 deletions runtimeconfig/google/cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2016 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
# limitations under the License.

try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
17 changes: 17 additions & 0 deletions runtimeconfig/google/cloud/runtimeconfig/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2016 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
# limitations under the License.

"""Google Cloud Runtime Configurator API package."""

from google.cloud.runtimeconfig.client import Client
70 changes: 70 additions & 0 deletions runtimeconfig/google/cloud/runtimeconfig/_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2016 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
# limitations under the License.

"""Shared helper functions for RuntimeConfig API classes."""


def config_name_from_full_name(full_name):
"""Extract the config name from a full resource name.
>>> config_name_from_full_name('projects/my-proj/configs/my-config')
"my-config"
:type full_name: str
:param full_name:
The full resource name of a config. The full resource name looks like
``projects/project-name/configs/config-name`` and is returned as the
``name`` field of a config resource. See:
https://cloud.google.com/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs
:rtype: str
:returns: The config's short name, given its full resource name.
:raises: :class:`ValueError` if ``full_name`` is not the expected format
"""
projects, _, configs, result = full_name.split('/')
if projects != 'projects' or configs != 'configs':
raise ValueError(
'Unexpected format of resource', full_name,
'Expected "projects/{proj}/configs/{cfg}"')
return result


def variable_name_from_full_name(full_name):
"""Extract the variable name from a full resource name.
>>> variable_name_from_full_name(
'projects/my-proj/configs/my-config/variables/var-name')
"var-name"
>>> variable_name_from_full_name(
'projects/my-proj/configs/my-config/variables/another/var/name')
"another/var/name"
:type full_name: str
:param full_name:
The full resource name of a variable. The full resource name looks like
``projects/prj-name/configs/cfg-name/variables/var-name`` and is
returned as the ``name`` field of a variable resource. See:
https://cloud.google.com/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs.variables
:rtype: str
:returns: The variable's short name, given its full resource name.
:raises: :class:`ValueError` if ``full_name`` is not the expected format
"""
projects, _, configs, _, variables, result = full_name.split('/', 5)
if (projects != 'projects' or configs != 'configs' or
variables != 'variables'):
raise ValueError(
'Unexpected format of resource', full_name,
'Expected "projects/{proj}/configs/{cfg}/variables/..."')
return result
59 changes: 59 additions & 0 deletions runtimeconfig/google/cloud/runtimeconfig/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2016 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
# limitations under the License.

"""Client for interacting with the Google Cloud RuntimeConfig API."""


from google.cloud.client import JSONClient
from google.cloud.runtimeconfig.connection import Connection
from google.cloud.runtimeconfig.config import Config


class Client(JSONClient):
"""Client to bundle configuration needed for API requests.
:type project: str
:param project:
(Optional) The project which the client acts on behalf of. If not
passed, falls back to the default inferred from the environment.
:type credentials: :class:`oauth2client.client.OAuth2Credentials`
:param credentials:
(Optional) The OAuth2 Credentials to use for the connection owned by
this client. If not passed (and if no ``http`` object is passed), falls
back to the default inferred from the environment.
:type http: :class:`httplib2.Http` or class that defines ``request()``.
:param http:
(Optional) An HTTP object to make requests. If not passed, an ``http``
object is created that is bound to the ``credentials`` for the current
object.
"""

_connection_class = Connection

def config(self, config_name):
"""Factory constructor for config object.
.. note::
This will not make an HTTP request; it simply instantiates
a config object owned by this client.
:type config_name: str
:param config_name: The name of the config to be instantiated.
:rtype: :class:`google.cloud.runtimeconfig.config.Config`
:returns: The config object created.
"""
return Config(client=self, name=config_name)
Loading

0 comments on commit 0258fb7

Please sign in to comment.