def test_sts(): scope = Scope() scope.set_bucket('android-ut-persist-bucket-1253653367') scope.set_region('ap-guangzhou') scope.add_action('name/cos:PutObject') scope.add_action('name/cos:GetObject') scope.add_action('name/cos:InitiateMultipartUpload') scope.add_action('name/cos:ListMultipartUploads') scope.add_action('name/cos:ListParts') scope.add_action('name/cos:UploadPart') scope.add_action('name/cos:CompleteMultipartUpload') scope.add_resource_prefix('1/test.txt') scope.add_resource_prefix('test/*') config = { # 临时密钥有效时长,单位是秒 'duration_seconds': 1800, # 固定密钥 'secret_id': 'AKIDPiqmW3qcgXVSKN8jngPzRhvxzYyDL5qP', # 固定密钥 'secret_key': 'EH8oHoLgpmJmBQUM1Uoywjmv7EFzd5OJ', 'proxy': { 'http': 'web-proxy.tencent.com:8080', 'https': 'web-proxy.tencent.com:8080' }, 'policy': Sts.get_policy(scope) } sts = Sts(config) response = sts.get_credential() print('get data : ' + str(response))
def get_credential_response_with_scope(): print(request.headers) content = request.form.get('scopes') _list = json.loads(content) print(_list) scopes = list() for l in _list: d = dict(l) scopes.append( Scope(action=d['action'], bucket=d['bucket'], region=d['region'], resource_prefix=d['prefix'])) policy = Sts.get_policy(scopes) print(policy) config = { # 临时密钥有效时长,单位是秒 'duration_seconds': 1800, 'secret_id': 'AKIDPiqmW3qcgXVSKN8jngPzRhvxzYyDL5qP', # 固定密钥 'secret_key': 'EH8oHoLgpmJmBQUM1Uoywjmv7EFzd5OJ', 'proxy': { 'http': 'web-proxy.tencent.com:8080', 'https': 'web-proxy.tencent.com:8080' }, 'policy': policy } sts = Sts(config) response = sts.get_credential() return str(response)
def test_policy2(): scope = Scope() scope.set_bucket('test-1250000000') scope.set_region('ap-guangzhou') scope.add_action('name/cos:PutObject') scope.add_action('name/cos:GetObject') scope.add_action('name/cos:InitiateMultipartUpload') scope.add_action('name/cos:ListMultipartUploads') scope.add_action('name/cos:ListParts') scope.add_action('name/cos:UploadPart') scope.add_action('name/cos:CompleteMultipartUpload') scope.add_resource_prefix('1/test.txt') scope.add_resource_prefix('test/*') print(Sts.get_policy(scope))
def test_sts(): scopes = list() scopes.append( Scope('name/cos:PutObject', 'test-1250000000', 'ap-guangzhou', 'dir/*')) scopes.append( Scope('name/cos:GetObject', 'test-1250000000', 'ap-guangzhou', 'dir/*')) scopes.append( Scope('name/cos:InitiateMultipartUpload', 'test-1250000000', 'ap-guangzhou', 'dir/*')) scopes.append( Scope('name/cos:ListParts', 'test-1250000000', 'ap-guangzhou', 'dir/*')) scopes.append( Scope('name/cos:UploadPart', 'test-1250000000', 'ap-guangzhou', 'dir/*')) scopes.append( Scope('name/cos:CompleteMultipartUpload', 'test-1250000000', 'ap-guangzhou', 'dir/*')) scopes.append( Scope('name/cos:GetObject', 'test-1250000000', 'ap-guangzhou', '1/test.txt')) config = { # 临时密钥有效时长,单位是秒 'duration_seconds': 1800, 'secret_id': 'AKIDXXX', # 固定密钥 'secret_key': 'EH8oXXX', 'proxy': { 'http': 'XXX', 'https': 'XXX' }, 'policy': Sts.get_policy(scopes) } sts = Sts(config) response = sts.get_credential() print('get data : ' + str(response))
def test_policy2(): scopes = list() scopes.append( Scope('name/cos:PutObject', 'test-1250000000', 'ap-guangzhou', 'dir/*')) scopes.append( Scope('name/cos:GetObject', 'test-1250000000', 'ap-guangzhou', 'dir/*')) scopes.append( Scope('name/cos:InitiateMultipartUpload', 'test-1250000000', 'ap-guangzhou', 'dir/*')) scopes.append( Scope('name/cos:ListParts', 'test-1250000000', 'ap-guangzhou', 'dir/*')) scopes.append( Scope('name/cos:UploadPart', 'test-1250000000', 'ap-guangzhou', 'dir/*')) scopes.append( Scope('name/cos:CompleteMultipartUpload', 'test-1250000000', 'ap-guangzhou', 'dir/*')) scopes.append( Scope('name/cos:GetObject', 'test-1250000000', 'ap-guangzhou', '1/test.txt')) print(Sts.get_policy(scopes))
def test_policy(): scope = Scope('name/cos:PutObject', 'test-1250000000', 'ap-guangzhou', 'dir/*') scopes = list() scopes.append(scope) print(Sts.get_policy(scopes=scopes))
def test_policy(): scope = Scope('name/cos:PutObject', 'test-1250000000', 'ap-guangzhou', 'dir/*') print(Sts.get_policy(scope=scope))