Skip to content

Commit fa518e1

Browse files
committed
Add initial support for RuntimeConfig API.
To keep the initial review small, this includes only a minimal set of features. It supports listing and getting variables, but not the other methods of the API.
1 parent fe4cc1e commit fa518e1

20 files changed

+1604
-0
lines changed

runtimeconfig/.coveragerc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[run]
2+
branch = True
3+
4+
[report]
5+
fail_under = 100
6+
show_missing = True
7+
exclude_lines =
8+
# Re-enable the standard pragma
9+
pragma: NO COVER
10+
# Ignore debug-only repr
11+
def __repr__

runtimeconfig/MANIFEST.in

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include README.rst
2+
graft google
3+
graft unit_tests
4+
global-exclude *.pyc

runtimeconfig/README.rst

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Python Client for Google Cloud RuntimeConfig
2+
============================================
3+
4+
Python idiomatic client for `Google Cloud RuntimeConfig`_
5+
6+
.. _Google Cloud RuntimeConfig: https://cloud.google.com/deployment-manager/runtime-configurator/
7+
8+
- `Documentation`_
9+
10+
.. _Documentation: http://googlecloudplatform.github.io/google-cloud-python/
11+
12+
Quick Start
13+
-----------
14+
15+
::
16+
17+
$ pip install --upgrade google-cloud-runtimeconfig
18+
19+
Authentication
20+
--------------
21+
22+
With ``google-cloud-python`` we try to make authentication as painless as
23+
possible. Check out the `Authentication section`_ in our documentation to
24+
learn more. You may also find the `authentication document`_ shared by all
25+
the ``google-cloud-*`` libraries to be helpful.
26+
27+
.. _Authentication section: http://google-cloud-python.readthedocs.io/en/latest/google-cloud-auth.html
28+
.. _authentication document: https://github.com/GoogleCloudPlatform/gcloud-common/tree/master/authentication
29+
30+
Using the API
31+
-------------
32+
33+
The Google Cloud `RuntimeConfig`_ (`RuntimeConfig API docs`_) API enables
34+
developers to dynamically configure and expose variables through Google Cloud
35+
Platform. In addition, you can also set Watchers and Waiters that will watch
36+
for changes to your data and return based on certain conditions.
37+
38+
.. _RuntimeConfig: https://cloud.google.com/deployment-manager/runtime-configurator/
39+
.. _RuntimeConfig API docs: https://cloud.google.com/deployment-manager/runtime-configurator/reference/rest/
40+
41+
See the ``google-cloud-python`` API `runtimeconfig documentation`_ to learn
42+
how to interact with Cloud RuntimeConfig using this Client Library.
43+
44+
.. _RuntimeConfig documentation: https://google-cloud-python.readthedocs.io/en/stable/runtimeconfig-usage.html

runtimeconfig/google/__init__.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
try:
16+
import pkg_resources
17+
pkg_resources.declare_namespace(__name__)
18+
except ImportError:
19+
import pkgutil
20+
__path__ = pkgutil.extend_path(__path__, __name__)
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
try:
16+
import pkg_resources
17+
pkg_resources.declare_namespace(__name__)
18+
except ImportError:
19+
import pkgutil
20+
__path__ = pkgutil.extend_path(__path__, __name__)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Google Cloud Runtime Configurator API package."""
16+
17+
from google.cloud.runtimeconfig.client import Client
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Shared helper functions for RuntimeConfig API classes."""
16+
17+
18+
def config_name_from_full_name(full_name):
19+
"""Extract the config name from a full resource name.
20+
21+
>>> config_name_from_full_name('projects/my-proj/configs/my-config')
22+
"my-config"
23+
24+
:type full_name: str
25+
:param full_name:
26+
The full resource name of a config. The full resource name looks like
27+
``projects/project-name/configs/config-name`` and is returned as the
28+
``name`` field of a config resource. See:
29+
https://cloud.google.com/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs
30+
31+
:rtype: str
32+
:returns: The config's short name, given its full resource name.
33+
:raises: :class:`ValueError` if ``full_name`` is not the expected format
34+
"""
35+
projects, _, configs, result = full_name.split('/')
36+
if projects != 'projects' or configs != 'configs':
37+
raise ValueError(
38+
'Unexpected format of resource', full_name,
39+
'Expected "projects/{proj}/configs/{cfg}"')
40+
return result
41+
42+
43+
def variable_name_from_full_name(full_name):
44+
"""Extract the variable name from a full resource name.
45+
46+
>>> variable_name_from_full_name(
47+
'projects/my-proj/configs/my-config/variables/var-name')
48+
"var-name"
49+
>>> variable_name_from_full_name(
50+
'projects/my-proj/configs/my-config/variables/another/var/name')
51+
"another/var/name"
52+
53+
:type full_name: str
54+
:param full_name:
55+
The full resource name of a variable. The full resource name looks like
56+
``projects/prj-name/configs/cfg-name/variables/var-name`` and is
57+
returned as the ``name`` field of a variable resource. See:
58+
https://cloud.google.com/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs.variables
59+
60+
:rtype: str
61+
:returns: The variable's short name, given its full resource name.
62+
:raises: :class:`ValueError` if ``full_name`` is not the expected format
63+
"""
64+
projects, _, configs, _, variables, result = full_name.split('/', 5)
65+
if (projects != 'projects' or configs != 'configs' or
66+
variables != 'variables'):
67+
raise ValueError(
68+
'Unexpected format of resource', full_name,
69+
'Expected "projects/{proj}/configs/{cfg}/variables/..."')
70+
return result
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Client for interacting with the Google Cloud RuntimeConfig API."""
16+
17+
18+
from google.cloud.client import JSONClient
19+
from google.cloud.runtimeconfig.connection import Connection
20+
from google.cloud.runtimeconfig.config import Config
21+
22+
23+
class Client(JSONClient):
24+
"""Client to bundle configuration needed for API requests.
25+
26+
:type project: str
27+
:param project:
28+
(Optional) The project which the client acts on behalf of. If not
29+
passed, falls back to the default inferred from the environment.
30+
31+
:type credentials: :class:`oauth2client.client.OAuth2Credentials`
32+
:param credentials:
33+
(Optional) The OAuth2 Credentials to use for the connection owned by
34+
this client. If not passed (and if no ``http`` object is passed), falls
35+
back to the default inferred from the environment.
36+
37+
:type http: :class:`httplib2.Http` or class that defines ``request()``.
38+
:param http:
39+
(Optional) An HTTP object to make requests. If not passed, an ``http``
40+
object is created that is bound to the ``credentials`` for the current
41+
object.
42+
"""
43+
44+
_connection_class = Connection
45+
46+
def config(self, config_name):
47+
"""Factory constructor for config object.
48+
49+
.. note::
50+
This will not make an HTTP request; it simply instantiates
51+
a config object owned by this client.
52+
53+
:type config_name: str
54+
:param config_name: The name of the config to be instantiated.
55+
56+
:rtype: :class:`google.cloud.runtimeconfig.config.Config`
57+
:returns: The config object created.
58+
"""
59+
return Config(client=self, name=config_name)

0 commit comments

Comments
 (0)