Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
def get_credential_response():
    config = {
        # 临时密钥有效时长,单位是秒
        'duration_seconds':
        1800,
        'secret_id':
        'AKIDPiqmW3qcgXVSKN8jngPzRhvxzYyDL5qP',
        # 固定密钥
        'secret_key':
        'EH8oHoLgpmJmBQUM1Uoywjmv7EFzd5OJ',
        'proxy': {
            'http': 'web-proxy.tencent.com:8080',
            'https': 'web-proxy.tencent.com:8080'
        },
        # 换成你的 bucket
        'bucket':
        'android-ut-persist-bucket-1253653367',
        # 换成 bucket 所在地区
        'region':
        'ap-guangzhou',
        # 这里改成允许的路径前缀,可以根据自己网站的用户登录态判断允许上传的目录,例子:* 或者 a/* 或者 a.jpg
        'allow_prefix':
        '*',
        # 密钥的权限列表。简单上传和分片需要以下的权限,其他权限列表请看 https://cloud.tencent.com/document/product/436/31923
        'allow_actions': [
            # 简单上传
            'name/cos:PutObject',
            # 分片上传
            'name/cos:InitiateMultipartUpload',
            'name/cos:ListMultipartUploads',
            'name/cos:ListParts',
            'name/cos:UploadPart',
            'name/cos:CompleteMultipartUpload'
        ],
    }

    sts = Sts(config)
    response = sts.get_credential()
    return str(response)
Exemplo n.º 4
0
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))
Exemplo n.º 5
0
        'AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        # 固定密钥
        'secret_key':
        'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        'proxy': {},
        # 换成你的 bucket
        'bucket':
        'test-1250000000',
        # 换成 bucket 所在地区
        'region':
        'ap-guangzhou',
        # 这里改成允许的路径前缀,可以根据自己网站的用户登录态判断允许上传的目录,例子:* 或者 a/* 或者 a.jpg
        'allow_prefix':
        '*',
        # 密钥的权限列表。简单上传和分片需要以下的权限,其他权限列表请看 https://cloud.tencent.com/document/product/436/31923
        'allow_actions': [
            # 简单上传
            'name/cos:PutObject',
            # 分片上传
            'name/cos:InitiateMultipartUpload',
            'name/cos:ListMultipartUploads',
            'name/cos:ListParts',
            'name/cos:UploadPart',
            'name/cos:CompleteMultipartUpload'
        ]
    }

    sts = Sts(config)
    response = sts.get_credential()
    print('get data : ' + str(response))