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. 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.0.1.tar.gz (6.3 kB view hashes)

Uploaded Source

Built Distribution

gcloud_aio_auth-2.0.1-py2.py3-none-any.whl (8.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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