从gcp实例/函数python查询google groups api
我正在尝试创建一个脚本,从GCP实例查询google groups API。实例已附加SA,此SA在GSuite中允许作用域-“”,并且用户也在GSuite中设置,并附加了自定义角色(列表组) 对于SA,我在GCP控制台中创建了一个密钥文件。然后,我获得了凭证,如文档所示:从gcp实例/函数python查询google groups api,python,google-cloud-platform,google-workspace,service-accounts,Python,Google Cloud Platform,Google Workspace,Service Accounts,我正在尝试创建一个脚本,从GCP实例查询google groups API。实例已附加SA,此SA在GSuite中允许作用域-“”,并且用户也在GSuite中设置,并附加了自定义角色(列表组) 对于SA,我在GCP控制台中创建了一个密钥文件。然后,我获得了凭证,如文档所示: from googleapiclient.discovery import build from google.oauth2 import service_account creds = service_account.C
from googleapiclient.discovery import build
from google.oauth2 import service_account
creds = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
然后添加要充当的用户
creds = creds.with_subject('user@domain.com')
service = build('admin', 'directory_v1', credentials=creds)
results = service.groups().list(domain=tenant, maxResults=10,
orderBy='email',
query='email:{}*'.format(group_name)).execute()
然后我查询API,一切正常,我得到了组
所以我的问题是:
是否有一种方法可以在不生成json密钥文件的情况下使用附加到实例的SA。比如从实例元数据中获取compute_实例/默认凭据/然后以某种方式向gsuiteapi进行身份验证
或者有没有一种方法可以在不点击Gsuite API的情况下查询组,只需从GCP中调用一些就可以了?您应该阅读官方GCP文档页面上的文章
下面是一个如何将服务帐户绑定到VM的示例
gcloud compute instances create example-vm \
--service-account my-sa@my-project.iam.gserviceaccount.com \
--scopes https://www.googleapis.com/auth/admin.directory.group.readonly
我从谷歌得到的答案是: