google-auth-library-python
google-auth-library-python copied to clipboard
Allow setting metadata environment variable `GCE_METADATA_HOST` alone
If users want to set a custom metadata server endpoint, you have to use both
GCE_METADATA_IP and GCE_METADATA_HOST.
The IP based env var is used here to ping the address of the server.
Using GCE_METADATA_IP
seems to be unique to google-auth-python while other gcp sdk libraries allows you to override with just GCE_METADATA_HOST
.
The usecase is if anyone wants to run a custom endpoint or local metadata emulator you'd have to know this specific environment variable just for python.
The suggestion is if a user set GCE_METADATA_HOST
, just use whats there.
For backwards compatibility, if the user sets both GCE_METADATA_HOST
and GCE_METADATA_IP
, the behavior is the same as now.
i think one simplistic way to get to that is to alter _metadata.py as such
if os.getenv(environment_vars.GCE_METADATA_HOST, None) is not None and os.getenv(environment_vars.GCE_METADATA_IP,None) is None:
_METADATA_IP_ROOT = "http://{}".format(_GCE_METADATA_HOST)
else:
_METADATA_IP_ROOT = "http://{}".format(
os.getenv(environment_vars.GCE_METADATA_IP, "169.254.169.254")
)
also noted here https://github.com/tensorflow/tensorflow/issues/60235#issuecomment-1497783248