本文整理汇总了Python中minio.Minio.set_bucket_policy方法的典型用法代码示例。如果您正苦于以下问题:Python Minio.set_bucket_policy方法的具体用法?Python Minio.set_bucket_policy怎么用?Python Minio.set_bucket_policy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类minio.Minio
的用法示例。
在下文中一共展示了Minio.set_bucket_policy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1:
# 需要导入模块: from minio import Minio [as 别名]
# 或者: from minio.Minio import set_bucket_policy [as 别名]
"Sid":"",
"Effect":"Allow",
"Principal":{"AWS":"*"},
"Action":"s3:ListBucket",
"Resource":"arn:aws:s3:::my-bucketname"
},
{
"Sid":"",
"Effect":"Allow",
"Principal":{"AWS":"*"},
"Action":"s3:GetObject",
"Resource":"arn:aws:s3:::my-bucketname/*"
}
]
}
client.set_bucket_policy('my-bucketname', json.dumps(policy_read_only))
# Set bucket policy to read-write for bucket 'my-bucketname'
policy_read_write = {
"Version": "2012-10-17",
"Statement": [
{
"Action": ["s3:GetBucketLocation"],
"Sid": "",
"Resource": ["arn:aws:s3:::my-bucketname"],
"Effect": "Allow",
"Principal": {"AWS": "*"}
},
{
"Action": ["s3:ListBucket"],
"Sid": "",
示例2: Minio
# 需要导入模块: from minio import Minio [as 别名]
# 或者: from minio.Minio import set_bucket_policy [as 别名]
# Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
# dummy values, please replace them with original values.
from minio import Minio
from minio.error import ResponseError
from minio.policy import Policy
client = Minio('s3.amazonaws.com',
access_key='YOUR-ACCESSKEYID',
secret_key='YOUR-SECRETACCESSKEY')
# Make a new bucket
try:
# Set policy Policy.READ_ONLY to bucket 'my-bucketname' which
# enables 'my-bucketname' readable by everyone.
client.set_bucket_policy('my-bucketname', '', Policy.READ_ONLY)
# Set policy Policy.READ_WRITE to bucket 'my-bucketname' and
# prefix 'public-folder/' which enables
# 'my-bucketname/public-folder/' read/writeable by everyone.
client.set_bucket_policy('my-bucketname', 'public-folder/',
Policy.READ_WRITE)
# Set policy Policy.WRITE_ONLY to bucket 'my-bucketname' and
# prefix 'incoming' which enables 'my-bucketname/incoming'
# writeable by everyone.
client.set_bucket_policy('my-bucketname', 'incoming',
Policy.WRITE_ONLY)
# Set policy Policy.NONE to bucket 'my-bucketname' which
# removes existing policy and set no access to everyone.