Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从gcp实例/函数python查询google groups api_Python_Google Cloud Platform_Google Workspace_Service Accounts - Fatal编程技术网

从gcp实例/函数python查询google groups api

从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

我正在尝试创建一个脚本,从GCP实例查询google groups API。实例已附加SA,此SA在GSuite中允许作用域-“”,并且用户也在GSuite中设置,并附加了自定义角色(列表组)

对于SA,我在GCP控制台中创建了一个密钥文件。然后,我获得了凭证,如文档所示:

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

我从谷歌得到的答案是:

  • 不,不为SA生成私钥进行模拟是不可能的
  • 不,获取组的正确方法是查询Gsuite的API