用于Google Cloud Auth的Python客户端
gcloud-rest-auth的Python项目详细描述
This is a shared codebase for ^{tt1}$ and ^{tt1}$
这个库实现了一个IamClient类,可用于交互 使用GCP公钥和URL签名blob。在
它还实现了一个用于授权的Token类 反对谷歌云。其他gcloud-rest-*包组件接受 Tokeninstance作为参数;您可以为所有 这些组件或为每个组件定义一个。每个组件对应于给定的 Google云服务和每个服务都需要“scopes”。在
安装
$ pip install --upgrade gcloud-{aio,rest}-auth
使用
^{pr2}$另外,Token构造函数接受以下可选的 参数:
- service_file:指向service account、授权用户文件或任何 其他应用程序凭据。或者,您可以传递一个类似 对象,例如io.StringIO实例,以防您的凭据不是 存储在一个文件中,但在内存中。如果省略,将尝试在 从GCE元数据生成令牌的路径或回退。在
- session:要用于所有对象的aiohttp.ClientSession实例 请求。如果省略,将创建一个默认会话。如果你使用 默认会话,您可能有兴趣使用Token()作为上下文 管理器(async with Token(..) as token:)或显式调用 Token.close()方法,以确保会话被正确清理。在
- ^{15可选的{GCP为哪个}生成 令牌。仅有效(并且是必需的!)用于service account身份验证。在
CLI
此项目还可以用于帮助您手动验证以测试GCP routes,例如,我们可以列出项目的正常运行时间检查 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 guide。在
- 项目
标签: