Ejemplo 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)
def request_sts():
    scopes = list()
    scopes.append(
        Scope('name/cos:PutObject', 'android-ut-persist-bucket-1253653367',
              'ap-guangzhou', 'dir/*'))
    scopes.append(
        Scope('name/cos:GetObject', 'android-ut-persist-bucket-1253653367',
              'ap-guangzhou', 'dir/*'))
    scopes.append(
        Scope('name/cos:InitiateMultipartUpload',
              'android-ut-persist-bucket-1253653367', 'ap-guangzhou', 'dir/*'))
    scopes.append(
        Scope('name/cos:ListParts', 'android-ut-persist-bucket-1253653367',
              'ap-guangzhou', 'dir/*'))
    scopes.append(
        Scope('name/cos:UploadPart', 'android-ut-persist-bucket-1253653367',
              'ap-guangzhou', 'dir/*'))
    scopes.append(
        Scope('name/cos:CompleteMultipartUpload',
              'android-ut-persist-bucket-1253653367', 'ap-guangzhou', 'dir/*'))
    scopes.append(
        Scope('name/cos:GetObject', 'android-ut-persist-bucket-1253653367',
              'ap-guangzhou', '1/test.txt'))
    content = list()
    for element in scopes:
        content.append(element.get_dict())
    user_info = {'scopes': json.dumps(content)}
    r = requests.post("http://127.0.0.1:5000/scopests", data=user_info)
    print(r.text)
Ejemplo n.º 3
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))
Ejemplo n.º 4
0
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))
Ejemplo n.º 5
0
def test_policy():
    scope = Scope('name/cos:PutObject', 'test-1250000000', 'ap-guangzhou',
                  'dir/*')
    scopes = list()
    scopes.append(scope)
    print(Sts.get_policy(scopes=scopes))
Ejemplo n.º 6
0
def test_policy():
    scope = Scope('name/cos:PutObject', 'test-1250000000', 'ap-guangzhou',
                  'dir/*')
    print(Sts.get_policy(scope=scope))
Ejemplo n.º 7
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))
Ejemplo n.º 8
0
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))