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 compute engine metadata client #11

Merged
merged 7 commits into from Oct 7, 2016
Merged

Add compute engine metadata client #11

merged 7 commits into from Oct 7, 2016

Conversation

theacodes
Copy link
Contributor

/cc @elibixby (original author)

@theacodes theacodes added this to the 1.0.0 milestone Oct 6, 2016

def update_query(url, params):
"""Updates a URL's query parameters
Replaces any current values if they are already present in the URL.

This comment was marked as spam.

This comment was marked as spam.

# Parse the query string.
query_params = urllib.parse.parse_qs(parts.query)
# Update the query parameters with the new parameters.
query_params.update(params)

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.

query_params = {
key: value for key, value
in six.iteritems(query_params)
if value is not 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.

# Re-encoded the query string.
new_query = urllib.parse.urlencode(query_params, doseq=True)
# Unsplit the url.
new_parts = parts[:4] + (new_query,) + parts[5:]

This comment was marked as spam.

This comment was marked as spam.

metadata_flavor == _METADATA_FLAVOR_VALUE)

except exceptions.TransportError:
# logger.info('Timeout attempting to reach GCE metadata service.')

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

if response.status == http_client.OK:
content = _helpers.from_bytes(response.data)
if response.headers['content-type'] == 'application/json':
return json.loads(content)

This comment was marked as spam.

This comment was marked as spam.

method='GET',
url=_metadata._METADATA_ROOT + PATH,
headers=_metadata._METADATA_HEADERS)
assert result['foo'] == 'bar'

This comment was marked as spam.

This comment was marked as spam.

headers=_metadata._METADATA_HEADERS)


@mock.patch('google.auth._helpers.utcnow', return_value=datetime.datetime.min)

This comment was marked as spam.

This comment was marked as spam.

url=_metadata._METADATA_ROOT + PATH + '/token',
headers=_metadata._METADATA_HEADERS)
assert token == 'token'
assert expiry == utcnow() + datetime.timedelta(seconds=500)

This comment was marked as spam.

This comment was marked as spam.

url=_metadata._METADATA_ROOT + PATH + '/?recursive=True',
headers=_metadata._METADATA_HEADERS)

assert info['foo'] == 'bar'

This comment was marked as spam.

This comment was marked as spam.

good-names = i, j, k, ex, Run, _,
fh,
fh, foo, bar

This comment was marked as spam.

This comment was marked as spam.



def test_get_success_json(mock_request):
foo, bar = 'foo', 'bar'

This comment was marked as spam.

This comment was marked as spam.

http://example.com?a=2
>>> update_query(url, {'b': '3'})
http://example.com?a=1&b=3
>> update_query(url, {'a': None, 'b': '3'})

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Copy link
Contributor

@dhermes dhermes left a comment

Choose a reason for hiding this comment

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

LGTM

@theacodes theacodes merged commit 64a9d6e into master Oct 7, 2016
@theacodes theacodes deleted the gce-metadata branch October 7, 2016 21:02
@theacodes theacodes mentioned this pull request Oct 21, 2016
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants