Pyjo.GCP.Credentials - Credentials of Google Cloud¶
from Pyjo.GCP.Credentials import Credentials
credentials = Credentials(token='ya29.a0AfH6SM...')
# Or import the module, as in Google Python Style Guide
import Pyjo.GCP.Credentials.Chain
# The Application Default Credentials, blocking
credentials = Pyjo.GCP.Credentials.Chain.new().credentials()
print(credentials.project, credentials.expiration, credentials.provider)
# Non-blocking
Pyjo.GCP.Credentials.Chain.new().credentials_p().then(lambda credentials: print(credentials.provider)).wait()
Pyjo.GCP.Credentials is the credentials of Google Cloud that
authorize a request: an access token of OAuth 2.0, which a request has as
Authorization: Bearer, with its expiration, and what the credentials
know of the project, the quota project and the universe domain. A provider
of Pyjo.GCP.Credentials.Provider gets them, as
Pyjo.GCP.Credentials.Chain gets the Application Default Credentials.
The providers are those of the credentials of google-auth, of a file of
credentials of its type, which Pyjo.GCP.Credentials.File makes
the provider of, and of the metadata server:
Credentials |
|
Provider |
|---|---|---|
a user of |
|
|
the key of a service account, with a self-signed JWT or the domain-wide delegation |
|
|
an impersonated service account, of the credentials of its source |
|
|
Workload Identity Federation of a token of a file or a URL, or of a certificate of X.509 |
|
|
Workload Identity Federation of a token of an executable |
|
|
Workload Identity Federation of AWS |
|
|
a user of a workforce pool, of
|
|
|
the service account of Compute Engine, GKE, Cloud Run and Cloud Functions |
none, the metadata server |
See also¶
Pyjo.GCP.Credentials.Provider, Pyjo.GCP.Credentials.Chain,
Pyjo.GCP.
Classes¶
- Pyjo.GCP.Credentials.CLOUD_PLATFORM = 'https://www.googleapis.com/auth/cloud-platform'¶
The scope of all the APIs of Google Cloud, of the tokens of the providers that take scopes by default.
- class Pyjo.GCP.Credentials.Pyjo_GCP_Credentials(*, token: str, expiration: datetime | None = None, project: str | None = None, quota_project: str | None = None, universe_domain: str | None = None, account: str | None = None, provider: str | None = None)[source]¶
Pyjo.GCP.Credentialsinherits all attributes and methods fromPyjo.Baseand implements the following new ones.- __init__(*, token: str, expiration: datetime | None = None, project: str | None = None, quota_project: str | None = None, universe_domain: str | None = None, account: str | None = None, provider: str | None = None) None[source]¶
credentials = Pyjo.GCP.Credentials.new(token='ya29.a0AfH6SM...')
Construct a new
Pyjo.GCP.Credentialsobject.
- __weakref__¶
list of weak references to the object
- account¶
account = credentials.account
The account of the credentials, as the email of a user or of a service account, where the provider knows it, or
None.
- copy(**changes: Any) Pyjo_GCP_Credentials[source]¶
credentials = credentials.copy(project='myproject')
A new
Pyjo.GCP.Credentialsobject of the same attributes, with the changes of the arguments.
- expiration¶
expiration = credentials.expiration
The time when the token expires, with its time zone, or
Nonefor a token whose expiration is not known.
- expires_in(now: datetime | None = None) float | None[source]¶
seconds = credentials.expires_in()
The number of seconds until the token expires, negative once it has, or
Nonefor a token whose expiration is not known.
- project¶
project = credentials.project
The project of the credentials, as the one of the key of a service account, or of the environment of
Pyjo.GCP.Credentials.Chain, orNone.
- provider¶
name = credentials.provider
The name of the provider of the credentials, as
authorized_user, orNone.
- quota_project¶
project = credentials.quota_project
The project that the quota and the billing of the requests go to, of the header
x-goog-user-project, orNone.
- token¶
token = credentials.token
The access token.
- universe_domain¶
domain = credentials.universe_domain
The universe domain of the credentials, or
Nonefor the one ofPyjo.GCP.Config.