s3.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:Cloud-Custodian 作者: jtroberts83 项目源码 文件源码
def modify_bucket_tags(session_factory, buckets, add_tags=(), remove_tags=()):
    for bucket in buckets:
        client = bucket_client(local_session(session_factory), bucket)
        # all the tag marshalling back and forth is a bit gross :-(
        new_tags = {t['Key']: t['Value'] for t in add_tags}
        for t in bucket.get('Tags', ()):
            if (t['Key'] not in new_tags and
                    not t['Key'].startswith('aws') and
                    t['Key'] not in remove_tags):
                new_tags[t['Key']] = t['Value']
        tag_set = [{'Key': k, 'Value': v} for k, v in new_tags.items()]
        try:
            client.put_bucket_tagging(
                Bucket=bucket['Name'], Tagging={'TagSet': tag_set})
        except ClientError as e:
            log.exception(
                'Exception tagging bucket %s: %s', bucket['Name'], e)
            continue
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号