Merge pull request #5251 from Manouchehri/oidc-improvements-20240816

(oidc): Add support for loading tokens via a file, env var, and path in env var
This commit is contained in:
Krish Dholakia 2024-08-16 19:15:31 -07:00 committed by GitHub
commit 1844e01133
3 changed files with 114 additions and 0 deletions

View file

@ -8441,6 +8441,25 @@ def get_secret(
with open(azure_federated_token_file, "r") as f:
oidc_token = f.read()
return oidc_token
elif oidc_provider == "file":
# Load token from a file
with open(oidc_aud, "r") as f:
oidc_token = f.read()
return oidc_token
elif oidc_provider == "env":
# Load token directly from an environment variable
oidc_token = os.getenv(oidc_aud)
if oidc_token is None:
raise ValueError(f"Environment variable {oidc_aud} not found")
return oidc_token
elif oidc_provider == "env_path":
# Load token from a file path specified in an environment variable
token_file_path = os.getenv(oidc_aud)
if token_file_path is None:
raise ValueError(f"Environment variable {oidc_aud} not found")
with open(token_file_path, "r") as f:
oidc_token = f.read()
return oidc_token
else:
raise ValueError("Unsupported OIDC provider")