-
Notifications
You must be signed in to change notification settings - Fork 346
fix: detect correct auth when ADC env var is set but empty #1374
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
Merged
gcf-merge-on-green
merged 8 commits into
googleapis:main
from
mbrancato:support_adc_set_empty
Jan 9, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
34849ed
fix: detect correct auth when ADC env var set but empty
mbrancato 5486f43
Merge branch 'main' into support_adc_set_empty
mbrancato 16f5402
Merge branch 'main' into support_adc_set_empty
chalmerlowe ee3e70e
Merge branch 'main' into support_adc_set_empty
chalmerlowe 99e94f3
Merge branch 'main' into support_adc_set_empty
chalmerlowe cd6800d
Merge branch 'main' into support_adc_set_empty
chalmerlowe 8669723
updates formatting to resolve linting error
chalmerlowe d6e0c45
Merge branch 'main' into support_adc_set_empty
chalmerlowe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I like using "" to represent the empty state. That seems like it could lead to confusing situations down the line. Instead, I'd recommend:
os.environ.get(environment_vars.CREDENTIALS) or None, which will replace empty strings withNoneor
if explicit_file:in place of the checks, which will respond to None and empty strings the same way, since both are falsyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Daniel:
Thanks for this comment. I considered similar ideas when evaluating this, and this is the conclusion I came to:
The variable
explicit_fileis a local variable within_get_explicit_environ_credentials(), so no external API is changed or affected and the way the code is currently written, it must be astr. Why? Because of the default behavior of the.get()method on adictand because of the return object from.get_application_default_credentials_path()which is astr.dict .get()
Environmental variables are stored as strings AND if the
CREDENTIALSvariable is not found, we return an empty string as the default value. There is no reason to return aNone, it serves no additional purpose in the limited uses that we have for the variableexplicit_file._cloud_sdk.get_application_default_credentials_path()
This function returns a string.
In the comparision, we are checking to see IF
explicit_filewas unset AND if not, whether the path matches the path referenced bycloud_sdk_adc_path. There is no need OR reason to prefer None over the empty string.So why use the empty string?
Old Behavior: Defaulted to
Noneif unset.New Behavior: Defaults to
""if unset (viaos.environ.get(..., "")).Result: The logic now treats "unset" and "set to empty string" identically (as
""). The checkexplicit_file != ""correctly handles both cases (unset OR empty string) by skipping the file load, which prevents a crash.cloud_sdk_adc_pathalways returns a string path, so the comparison remains safe.Before I had fully worked through the above logic, I had considered something such as:
if explicit_file not in {None, ""}and feel that whileif explicit_file not in {None, ""}OR similar patterns (such as you recommend) where we look for both is a valid defensive pattern, the current PR's approach is slightly cleaner because it enforces type consistency. If we initializeexplicit_filewith a default of"", the variable is always astr, avoiding mixed types (Optional[str]). The current implementationexplicit_file != ""is correct given the initialization change.