Pyjo.GCP.Credentials.Chain - Application Default Credentials¶
from Pyjo.GCP.Credentials.Chain import Chain
credentials = Chain().credentials()
print(credentials.project)
# Or import the module, as in Google Python Style Guide
import Pyjo.GCP.Config
import Pyjo.GCP.Credentials.Chain
import Pyjo.GCP.Credentials.File
chain = Pyjo.GCP.Credentials.Chain.new(scopes=['https://www.googleapis.com/auth/devstorage.read_only'])
chain.credentials_p().then(lambda credentials: print(credentials.provider)).wait()
chain = Pyjo.GCP.Credentials.Chain.new(providers=[Pyjo.GCP.Credentials.File.new(path='/etc/gcloud/key.json')])
Pyjo.GCP.Credentials.Chain is the provider of the Application
Default Credentials, the credentials of the first of its providers that has
them, in the order of AIP-4110 by default:
the file of the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable, ofPyjo.GCP.Credentials.File,the file of
gcloud auth application-default login, ofPyjo.GCP.Credentials.File,the metadata server of Compute Engine, GKE, Cloud Run and Cloud Functions, of
Pyjo.GCP.Credentials.Metadata.
The project of the GOOGLE_CLOUD_PROJECT environment variable, or of
GCLOUD_PROJECT, comes over the one of the credentials, as google-auth has
it.
A provider that is not configured passes on to the next one, and the error
of one that is configured ends the chain, as google-auth does, so that a
broken file of GOOGLE_APPLICATION_CREDENTIALS is not hidden by other
credentials.
See also¶
Pyjo.GCP.Credentials.Provider, Pyjo.GCP.Credentials,
Pyjo.GCP.Config, https://google.aip.dev/auth/4110.
Classes¶
- class Pyjo.GCP.Credentials.Chain.Pyjo_GCP_Credentials_Chain(*, providers: Sequence[Pyjo_GCP_Credentials_Provider] | None = None, config: Pyjo_GCP_Config | None = None, scopes: Sequence[str] | None = None, **kwargs: Any)[source]¶
Pyjo.GCP.Credentials.Chaininherits all attributes and methods fromPyjo.GCP.Credentials.Providerand implements the following new ones.- __init__(*, providers: Sequence[Pyjo_GCP_Credentials_Provider] | None = None, config: Pyjo_GCP_Config | None = None, scopes: Sequence[str] | None = None, **kwargs: Any) None[source]¶
chain = Pyjo.GCP.Credentials.Chain.new() chain = Pyjo.GCP.Credentials.Chain.new(scopes=['https://www.googleapis.com/auth/devstorage.read_only']) chain = Pyjo.GCP.Credentials.Chain.new(providers=[Pyjo.GCP.Credentials.File.new(path=path)])
Construct a new
Pyjo.GCP.Credentials.Chainobject, with the options ofPyjo.GCP.Credentials.Provider, and the providers of the Application Default Credentials, withconfigandscopes, by default.
- config¶
config = chain.config
The configuration of the default providers and of the project, a new
Pyjo.GCP.Configobject by default.
- default_providers() list[Pyjo_GCP_Credentials_Provider][source]¶
providers = chain.default_providers()
New providers of the Application Default Credentials, with
config,scopesand the user agent of the chain, in their order, but the metadata server, which has a user agent of its own, with a short timeout.
- async fetch() Pyjo_GCP_Credentials | None[source]¶
credentials = await chain.fetch()
The credentials of the first provider that has them, with the project of the environment, or
None.
- providers: list[Pyjo_GCP_Credentials_Provider]¶
providers = chain.providers
The providers, in their order.
- scopes¶
scopes = chain.scopes
The scopes of the token of the default providers that take scopes,
https://www.googleapis.com/auth/cloud-platformby default.