-
Notifications
You must be signed in to change notification settings - Fork 309
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
Allow customizing the GCE metadata service address via an env var. #148
Conversation
The goal here is to make it possible for a user of a binary that depends on this library (eg the google cloud SDK) to be able to customize where it looks for the GCE metadata service. (An adventurous user can already customize the GCE metadata service location via the existing global vars in this library.) The only bit of awkwardness here is really the test: since this is a top-level statement, reloading is the only way to ensure it works.
@craigcitro Did you want to merge in both libraries? (It's pretty unlikely |
@dhermes Yep, I purposely sent the PR for both. @jonparrott mentioned the same about oauth2client, then remembered that he had to add something silly (update the classifiers?), so it was an opportune time for me to sneak it in. 😉 |
fake_ip = '1.2.3.4' | ||
os.environ['GCE_METADATA_IP'] = fake_ip | ||
reload_module(_metadata) | ||
try: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
# This is used to ping the metadata server, it avoids the cost of a DNS | ||
# lookup. | ||
_METADATA_IP_ROOT = 'http://169.254.169.254' | ||
_METADATA_IP_ROOT = 'http://' + os.getenv('GCE_METADATA_IP', '169.254.169.254') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
OK, updated to use the constants in |
@craigcitro LGTM, but Travis is mad about you not using 4 spaces for indentation. :) |
As well he should be. Fixed. (Do you guys autosquash or should I squash?) |
Thanks, @craigcitro! |
🚗 squash |
The goal here is to make it possible for a user of a binary that depends on
this library (eg the google cloud SDK) to be able to customize where it looks
for the GCE metadata service. (An adventurous user can already customize the
GCE metadata service location via the existing global vars in this library.)
The only bit of awkwardness here is really the test: since this is a top-level
statement, reloading is the only way to ensure it works.
PTAL @jonparrott
(and why yes I DID just completely copy-paste the commit description from the oauth2client PR.)