如何以编程方式为Cloud ML提供访问权限?

时间:2016-10-23 01:10:02

标签: google-cloud-datalab google-cloud-ml

Cloud ML instructions显示如何使用gsutil授予对存储桶的Cloud ML访问权限。有没有办法在python中以编程方式执行此操作?

1 个答案:

答案 0 :(得分:2)

您可以使用google-cloud python库以编程方式授予对Cloud ML的GCS存储桶的访问权限。

from google.cloud import storage
b = client.get_bucket(BUCKET)

# Grant WRITE access to the service account.
b.acl.user(SERVICE_ACCOUNT).grant_write()
b.acl.save()

# Change the default object permissions to give read access to the service account
b.default_object_acl.user(SERVICE_ACCOUNT).grant_read()
b.default_object_acl.save()

# Grant read access to all existing objects
for o in b.list_blobs():
  o.acl.user(SERVICE_ACCOUNT).grant_read()
  o.acl.save()

有关以编程方式获取服务帐户的说明,请参阅此question