This is a shared codebase for gcloud-aio-auth and gcloud-rest-auth
This library implements an IamClient class, which can be used to interact with GCP public keys and URL sign blobs.
It additionally 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”.
Installation
$ pip install --upgrade gcloud-{aio,rest}-auth
Usage
from gcloud.aio.auth import IamClient
client = IamClient()
pubkeys = await client.list_public_keys()
from gcloud.rest.auth import Token
token = Token()
print(token.get())
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. If you use the default session, you may be interested in using Token() as a context manager (async with Token(..) as token:) or explicitly calling the Token.close() method to ensure the session is cleaned up appropriately.
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 'from gcloud.rest.auth import Token; print(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 'from gcloud.rest.auth import Token; print(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 'from gcloud.rest.auth import Token; print(Token().get())')" \
"https://monitoring.googleapis.com/v3/projects/PROJECT_ID/uptimeCheckConfigs"
Contributing
Please see our contributing guide.
Metadata
Release files for gcloud-aio-auth 3.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gcloud-aio-auth-3.5.0.tar.gz | 14.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gcloud_aio_auth-3.5.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 30.9 kB
Release files / gcloud-aio-auth-3.5.0.tar.gz
| Download URL | gcloud-aio-auth-3.5.0.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f4878366c9727c820883b3b6d1b3371a2f762cc0d64b01bf185f6e6e48e9092f
|
|
BLAKE2b-256 checksum How to use checksums |
c1c8cd4aee581f0e79415a85ce94904e7d7cc60afee5b726d492c2a8060b1742
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.14.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1
|
Release files / gcloud_aio_auth-3.5.0-py2.py3-none-any.whl
| Download URL | gcloud_aio_auth-3.5.0-py2.py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
a250c36fd9b8dc5c13213ec4441a427e3dceb0c45e1322329411991fb0107a04
|
|
BLAKE2b-256 checksum How to use checksums |
bbc491c125dbf1ae7f922d07a1a4a7c86cd96bc4320bdd87e84c1de19004c077
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.14.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1
|