#!/usr/bin/env python3
"""Set COS models directory to public read"""
import os, json
os.environ['ZY_OSS_KEY'] = 'AKIDkQuBQhoiS2OYXWebXLwMbdT7cvAScbbU'
os.environ['ZY_OSS_SECRET'] = 'nPoZKArgUJBA4nJenjSxJSQBj5FCj3A4'
from qcloud_cos import CosConfig, CosS3Client
cfg = CosConfig(Region='ap-guangzhou', SecretId=os.environ['ZY_OSS_KEY'], SecretKey=os.environ['ZY_OSS_SECRET'])
client = CosS3Client(cfg)
bkt = 'sy-finetune-corpus-1317346199'
policy = {
    'Version': '2012-10-17',
    'Statement': [{
        'Effect': 'Allow',
        'Principal': {'qcs': ['qcs::cam::anonymous:anonymous']},
        'Action': ['name/cos:GetObject'],
        'Resource': ['qcs::cos:ap-guangzhou:uid/1317346199:sy-finetune-corpus-1317346199/models/*']
    }]
}
client.put_bucket_policy(Bucket=bkt, Policy=json.dumps(policy))
print('OK: models/* public read')
