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

Add support for RuntimeConfig API. #2485

Merged
merged 1 commit into from
Oct 25, 2016
Merged

Add support for RuntimeConfig API. #2485

merged 1 commit into from
Oct 25, 2016

Conversation

tswast
Copy link
Contributor

@tswast tswast commented Oct 3, 2016

Supports listing and getting variables, but not the other methods of the RuntimeConfig API, since
I didn't need those, yet.

First step of #2476

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 3, 2016
- `API Documentation`_

.. _Homepage: https://googlecloudplatform.github.io/google-cloud-python/
.. _API Documentation: http://googlecloudplatform.github.io/google-cloud-python/

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

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 (not yet supported
by this client library) that will watch for changes to your data and return

This comment was marked as spam.

This comment was marked as spam.

@@ -0,0 +1,20 @@
# Copyright 2014 Google Inc.

This comment was marked as spam.

This comment was marked as spam.

# limitations under the License.

"""Google Cloud Runtime Configurator API package."""
from google.cloud.runtimeconfig.client import Client

This comment was marked as spam.

"""Extract the config name from a full resource name.

>>> _config_name_from_full_name('projects/my-proj/configs/my-config')
"my-config"

This comment was marked as spam.

This comment was marked as spam.

config_name = self._callFUT(PATH)
self.assertEqual(config_name, CONFIG_NAME)

class Test_variable_name_from_full_name(unittest.TestCase):

This comment was marked as spam.

CONFIG_NAME = 'CONFIG_NAME'
PROJECT = 'my-project-1234'
PATH = 'projects/%s/configs/%s/variables/%s' % (
PROJECT, CONFIG_NAME, VARIABLE_NAME)

This comment was marked as spam.

CONFIG_NAME = 'CONFIG_NAME'
PROJECT = 'my-project-1234'
PATH = 'projects/%s/configs/%s/variables/%s' % (
PROJECT, CONFIG_NAME, VARIABLE_NAME)

This comment was marked as spam.


import httplib2
import six
from six.moves.urllib.parse import quote

This comment was marked as spam.

This comment was marked as spam.

def test_ctor(self):
client = _Client(project=self.PROJECT)
config = self._makeOne(name=self.CONFIG_NAME,
client=client)

This comment was marked as spam.

@tswast
Copy link
Contributor Author

tswast commented Oct 3, 2016

Oops, looks like I mixed tabs and spaces and didn't reach 100% coverage on variable.py. Addressing now.

@tswast
Copy link
Contributor Author

tswast commented Oct 3, 2016

Updated, please take a second look.

@tswast
Copy link
Contributor Author

tswast commented Oct 3, 2016

I'm getting a lint error

************* Module google.cloud.runtimeconfig._helpers
C: 52, 0: Line too long (89/80) (line-too-long)

The line is

                      'projects/project-name/configs/config-name/variables/variable-name'

I don't think there's anything I can do to shrink it down.

@tswast
Copy link
Contributor Author

tswast commented Oct 4, 2016

Okay, I think I finally made the linter happy. I shrunk the problematic line down by changing the "names" project-name -> proj-name, config-name -> cfg-name


# Variables are hierarchical. Each node in the hierarchy is separated by a
# / character.
return '/'.join(parts[5:])

This comment was marked as spam.

This comment was marked as spam.

:rtype: string
:returns: The full name based on project and config names.

:raises: :class:`ValueError` if the config is missing a name.

This comment was marked as spam.

This comment was marked as spam.

``None`` if the property is not set locally.
"""
value = self._properties.get('updateTime')
if value:

This comment was marked as spam.

This comment was marked as spam.

@dhermes
Copy link
Contributor

dhermes commented Oct 4, 2016

@tswast RE: a line with a string that's too long (like 'projects/project-name/configs/config-name/variables/variable-name')

You can use an implicit strong concat in Python:

my_var = ('the beginning of the string '
          'and here is some more of it')

RE: Mixing tabs and spaces, please get rid of all tabs. You can check for them via git grep -l $'\t'. If any files have tabs other than

Makefile.bigtable_v2
Makefile.datastore
docs/Makefile
docs/_static/images/favicon.ico
docs/_static/images/gcp-logo-32x32.png
docs/_static/images/gcp-logo.png
system_tests/data/CloudPlatform_128px_Retina.png
system_tests/data/five-point-one-mb-file.zip
system_tests/key.json.enc

then you should find the offending lines via git grep -n $'\t' and get rid of the tabs

except NotFound:
return False

def reload(self, client=None, fields=None):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

def test_ctor_w_no_name(self):
client = _Client(project=self.PROJECT)
config = self._makeOne(name=None, client=client)
self.assertRaises(ValueError, lambda: config.full_name)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

client = _Client(project=self.PROJECT)
config = Config(name=self.CONFIG_NAME, client=client)
variable = self._makeOne(name=None, config=config)
self.assertRaises(ValueError, lambda: variable.full_name)

This comment was marked as spam.

This comment was marked as spam.

self.assertEqual(len(conn._requested), 1)
req = conn._requested[0]
self.assertEqual(req['method'], 'GET')
self.assertEqual(req['path'], '/%s' % self.CONFIG_PATH)

This comment was marked as spam.

This comment was marked as spam.

@tswast
Copy link
Contributor Author

tswast commented Oct 5, 2016

Ping. Please take a second look. I believe I have addressed all open comments.

@tswast
Copy link
Contributor Author

tswast commented Oct 13, 2016

@dhermes @jonparrott Please review. Is this ready to merge? I just rebased against the latest master.

Copy link
Contributor

@theacodes theacodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tswast there doesn't seem to be any way to create configs or variables, is this intentional because this is just the first step?

See the ``google-cloud-python`` API `RuntimeConfig documentation`_ to learn
how to analyze images using this library.

.. _Vision documentation: https://google-cloud-python.readthedocs.io/en/stable/runtimeconfig-usage.html

This comment was marked as spam.

This comment was marked as spam.

This will not make an HTTP request; it simply instantiates
a config object owned by this client.

:type config_name: string

This comment was marked as spam.

self._properties = {}

def __repr__(self):
return '<Config: %s>' % (self.name,)

This comment was marked as spam.

This comment was marked as spam.

:rtype: string
:returns: The URL path based on project and config names.
"""
return '/%s' % (self.full_name,)

This comment was marked as spam.

This will not make an HTTP request; it simply instantiates
a variable object owned by this config.

:type variable_name: string

This comment was marked as spam.

"""
if not self.name:
raise ValueError('Missing variable name.')
return '%s/variables/%s' % (self.config.full_name, self.name)

This comment was marked as spam.

:rtype: string
:returns: The URL path based on config and variable names.
"""
return '/%s' % (self.full_name,)

This comment was marked as spam.

def path(self):
"""URL path for the variable's APIs.

:rtype: string

This comment was marked as spam.

https://cloud.google.com/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs.variables#VariableState

:rtype: string or ``NoneType``
:returns: If set, one of "UPDATED", "DELETED", or

This comment was marked as spam.

"my-config"

:type full_name: string
:param full_name: the full resource name of a config. The full resource

This comment was marked as spam.

tswast added a commit to tswast/google-cloud-python that referenced this pull request Oct 20, 2016
Used the command:
ag -l 'rtype: string' | xargs sed -i .bak 's/rtype: string/rtype: str/g'

Based on this comment:
googleapis#2485 (comment)

`str` is a type, `string` is a module.
@tswast tswast force-pushed the master branch 2 times, most recently from fa518e1 to da5092b Compare October 24, 2016 16:11
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.
@tswast
Copy link
Contributor Author

tswast commented Oct 24, 2016

@jonparrott @dhermes Please take another look. I believe I have addressed all your comments.

@tswast there doesn't seem to be any way to create configs or variables, is this intentional because this is just the first step?

Yes. I wanted to keep the initial PR as small as possible to start. Plus, dpebot and the other samples I want to create will just need read access, not write access to RuntimeConfig. After this goes in, we can add creates in, if only so that we can create system tests for this. Right now I'm running the following snippets manually to verify that it does what I want:

$ gcloud config configurations activate kittenbot
export GOOGLE_CLOUD_PROJECT=my-project-name
$ python

from google.cloud import runtimeconfig
client = runtimeconfig.Client()
config = client.config('kittenbot')
iterator = config.list_variables()
iterator.update_page()
variables = list(iterator.page)
print(variables)
token = iterator.next_page_token
print(token)

v = config.get_variable('slack-token')
print(v)

@tswast tswast merged commit a23ca8e into googleapis:master Oct 25, 2016
dhermes added a commit to dhermes/google-cloud-python that referenced this pull request Oct 25, 2016
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
Used the command:
ag -l 'rtype: string' | xargs sed -i .bak 's/rtype: string/rtype: str/g'

Based on this comment:
googleapis#2485 (comment)

`str` is a type, `string` is a module.
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
Add support for RuntimeConfig API.
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
plamut pushed a commit to googleapis/python-pubsub that referenced this pull request Jan 31, 2020
Used the command:
ag -l 'rtype: string' | xargs sed -i .bak 's/rtype: string/rtype: str/g'

Based on this comment:
googleapis/google-cloud-python#2485 (comment)

`str` is a type, `string` is a module.
crwilcox pushed a commit to googleapis/python-storage that referenced this pull request Jan 31, 2020
Used the command:
ag -l 'rtype: string' | xargs sed -i .bak 's/rtype: string/rtype: str/g'

Based on this comment:
googleapis/google-cloud-python#2485 (comment)

`str` is a type, `string` is a module.
busunkim96 pushed a commit to googleapis/python-dns that referenced this pull request Jan 31, 2020
Used the command:
ag -l 'rtype: string' | xargs sed -i .bak 's/rtype: string/rtype: str/g'

Based on this comment:
googleapis/google-cloud-python#2485 (comment)

`str` is a type, `string` is a module.
plamut pushed a commit to googleapis/python-bigquery that referenced this pull request Feb 4, 2020
Used the command:
ag -l 'rtype: string' | xargs sed -i .bak 's/rtype: string/rtype: str/g'

Based on this comment:
googleapis/google-cloud-python#2485 (comment)

`str` is a type, `string` is a module.
plamut pushed a commit to googleapis/python-monitoring that referenced this pull request Feb 5, 2020
Used the command:
ag -l 'rtype: string' | xargs sed -i .bak 's/rtype: string/rtype: str/g'

Based on this comment:
googleapis/google-cloud-python#2485 (comment)

`str` is a type, `string` is a module.
crwilcox pushed a commit to googleapis/python-datastore that referenced this pull request Feb 6, 2020
Used the command:
ag -l 'rtype: string' | xargs sed -i .bak 's/rtype: string/rtype: str/g'

Based on this comment:
googleapis/google-cloud-python#2485 (comment)

`str` is a type, `string` is a module.
busunkim96 pushed a commit to googleapis/python-cloud-core that referenced this pull request Feb 7, 2020
Used the command:
ag -l 'rtype: string' | xargs sed -i .bak 's/rtype: string/rtype: str/g'

Based on this comment:
googleapis/google-cloud-python#2485 (comment)

`str` is a type, `string` is a module.
cojenco pushed a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
Used the command:
ag -l 'rtype: string' | xargs sed -i .bak 's/rtype: string/rtype: str/g'

Based on this comment:
googleapis/google-cloud-python#2485 (comment)

`str` is a type, `string` is a module.
cojenco pushed a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
Used the command:
ag -l 'rtype: string' | xargs sed -i .bak 's/rtype: string/rtype: str/g'

Based on this comment:
googleapis/google-cloud-python#2485 (comment)

`str` is a type, `string` is a module.
parthea pushed a commit that referenced this pull request Oct 21, 2023
Used the command:
ag -l 'rtype: string' | xargs sed -i .bak 's/rtype: string/rtype: str/g'

Based on this comment:
#2485 (comment)

`str` is a type, `string` is a module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants