Pyjo.GCP.Credentials.File - Credentials of a file

from Pyjo.GCP.Credentials.File import File

credentials = File(path='/etc/gcloud/key.json').credentials()

# Or import the module, as in Google Python Style Guide

import Pyjo.GCP.Config
import Pyjo.GCP.Credentials.File

config = Pyjo.GCP.Config.new()

# The file of gcloud auth application-default login, or None without it
provider = Pyjo.GCP.Credentials.File.new(path=config.adc_file(), optional=True, config=config)
provider.credentials_p().then(lambda credentials: print(credentials.project)).wait()

Pyjo.GCP.Credentials.File is the provider of the credentials of a file of credentials of Google Cloud, as the one of GOOGLE_APPLICATION_CREDENTIALS or of gcloud auth application-default login, of the provider of its type:

The quota project of GOOGLE_CLOUD_QUOTA_PROJECT comes over the one of the file, and the file of gcloud auth application-default login, which has no project, has the one of the configuration of gcloud, core/project, as google-auth has them.

See also

Pyjo.GCP.Credentials.Provider, Pyjo.GCP.Credentials.Chain, Pyjo.GCP.Config, https://google.aip.dev/auth/4110.

Classes

class Pyjo.GCP.Credentials.File.Pyjo_GCP_Credentials_File(*, path: str | None = None, optional: bool = False, config: Pyjo_GCP_Config | None = None, scopes: Sequence[str] | None = None, **kwargs: Any)[source]

Pyjo.GCP.Credentials.File inherits all attributes and methods from Pyjo.GCP.Credentials.Provider and implements the following new ones.

__init__(*, path: str | None = None, optional: bool = False, config: Pyjo_GCP_Config | None = None, scopes: Sequence[str] | None = None, **kwargs: Any) → None[source]
provider = Pyjo.GCP.Credentials.File.new(path='/etc/gcloud/key.json')
provider = Pyjo.GCP.Credentials.File.new(path=config.adc_file(), optional=True, config=config,
                                         scopes=['https://www.googleapis.com/auth/devstorage.read_only'])

Construct a new Pyjo.GCP.Credentials.File object, with the options of Pyjo.GCP.Credentials.Provider.

config
config = provider.config

The configuration of the quota project and of gcloud, a new Pyjo.GCP.Config object by default.

external_account_of(info: Mapping[str, Any], path: str = 'a file', *, scopes: Sequence[str] | None = None) → Pyjo_GCP_Credentials_Provider[source]
provider = provider.external_account_of(info)

A new provider of the JSON object of a file of the type external_account, of the kind of its source, as provider_of(), or a Pyjo.Exception of an invalid one.

async fetch() → Pyjo_GCP_Credentials | None[source]
credentials = await provider.fetch()

The credentials of the provider of the file, or None without path, or without the file of an optional one.

is_gcloud() → bool[source]
boolean = provider.is_gcloud()

Whether path is the file of gcloud auth application-default login of config, also of GOOGLE_APPLICATION_CREDENTIALS, as google-auth compares them.

optional
boolean = provider.optional

Whether a file that does not exist has no credentials, as the one of gcloud auth application-default login, rather than an error, as the one of GOOGLE_APPLICATION_CREDENTIALS.

path
path = provider.path

The path of the file, or None, which has no credentials, as an empty GOOGLE_APPLICATION_CREDENTIALS.

provider_of(info: Mapping[str, Any], path: str = 'a file', *, scopes: Sequence[str] | None = None) → Pyjo_GCP_Credentials_Provider[source]
source = provider.provider_of(info)

A new provider of the JSON object of a file of credentials, of its type, with the user agent and the refresh of this one, and the scopes of the argument or of scopes, or a Pyjo.Exception of a type that is not supported.

scopes
scopes = provider.scopes

The scopes of the token of the credentials that take scopes, https://www.googleapis.com/auth/cloud-platform by default.