Skip to main content

Auth Helpers for Asyncio Google Cloud Library

Project description

This library is not meant to be a standalone project, rather it is used by various gcloud-aio-* packages.

This library implements a Token class, which is used for authorizing against Google Cloud. The other gcloud-aio-* package components accept a Token instance as an argument; you can define a single token for all of these components or define one for each. Each component corresponds to a given Google Cloud service and each service requires “scopes”.

Latest PyPI Version Python Version Support

Installation

$ pip install --upgrade gcloud-aio-auth

Usage

from gcloud.aio.auth import Token

token = Token()

Additionally, the Token constructor accepts the following optional arguments:

  • service_file: path to a service account, authorized user file, or any other application credentials. Alternatively, you can pass a file-like object, like an io.StringIO instance, in case your credentials are not stored in a file but in memory. If omitted, will attempt to find one on your path or fallback to generating a token from GCE metadata.

  • session: an aiohttp.ClientSession instance to be used for all requests. If omitted, a default session will be created.

  • scopes: an optional list of GCP scopes for which to generate our token. Only valid (and required!) for service account authentication.

CLI

This project can also be used to help you manually authenticate to test GCP routes, eg. we can list our project’s uptime checks with a tool such as curl:

# using default application credentials
curl \
  -H "Authorization: Bearer $(python3 -c 'import asyncio; from gcloud.aio.auth import Token; print(asyncio.run(Token().get()))')" \
  "https://monitoring.googleapis.com/v3/projects/PROJECT_ID/uptimeCheckConfigs"

# using a service account (make sure to provide a scope!)
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service.json
curl \
  -H "Authorization: Bearer $(python3 -c 'import asyncio; from gcloud.aio.auth import Token; print(asyncio.run(Token(scopes=["'"https://www.googleapis.com/auth/cloud-platform"'"]).get()))')" \
  "https://monitoring.googleapis.com/v3/projects/PROJECT_ID/uptimeCheckConfigs"

# using legacy account credentials
export GOOGLE_APPLICATION_CREDENTIALS=~/.config/gcloud/legacy_credentials/EMAIL@DOMAIN.TLD/adc.json
curl \
  -H "Authorization: Bearer $(python3 -c 'import asyncio; from gcloud.aio.auth import Token; print(asyncio.run(Token().get()))')" \
  "https://monitoring.googleapis.com/v3/projects/PROJECT_ID/uptimeCheckConfigs"

Contributing

Please see our contributing guide.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gcloud-aio-auth-2.2.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gcloud_aio_auth-2.2.0-py2.py3-none-any.whl (12.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file gcloud-aio-auth-2.2.0.tar.gz.

File metadata

  • Download URL: gcloud-aio-auth-2.2.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.4.3 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.0

File hashes

Hashes for gcloud-aio-auth-2.2.0.tar.gz
Algorithm Hash digest
SHA256 2cd96d9fffc12b46ef7fb9903bb72bbfced6c10fc502512bb69cea2dd53e4a5a
MD5 096747ef7899ad00f1602eb8ddff1470
BLAKE2b-256 d7ccdc6049ec9a2437a5718c2bac14b20006f5d4e4b637d2be46f984cc8e16db

See more details on using hashes here.

File details

Details for the file gcloud_aio_auth-2.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: gcloud_aio_auth-2.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.4.3 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.0

File hashes

Hashes for gcloud_aio_auth-2.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a1b4a8e970de5e3f6070507f155e1cb83827cb6d8c168af4c91271e46d183213
MD5 edfddcd5fcffd0400bbcc6412c46ec6e
BLAKE2b-256 fc17db34b6a837d886e3a5d6657f26591e62dfd4f60c41f490c2567823b4920a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page