예제 #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': 'AKIDXXX',
        # 固定密钥
        'secret_key': 'EH8oXXX',
        'proxy': {
            'http': 'XXX',
            'https': 'XX'
        },
        'policy': policy
    }

    sts = Sts(config)
    response = sts.get_credential()
    return str(response)
예제 #2
0
def request_sts():
    scopes = list()
    scopes.append(
        Scope('name/cos:PutObject', 'android-ut-persist-bucket-1253653367',
              'ap-guangzhou', 'exampleobject'))
    scopes.append(
        Scope('name/cos:GetObject', 'android-ut-persist-bucket-1253653367',
              'ap-guangzhou', 'exampleobject'))
    scopes.append(
        Scope('name/cos:InitiateMultipartUpload',
              'android-ut-persist-bucket-1253653367', 'ap-guangzhou',
              'exampleobject'))
    scopes.append(
        Scope('name/cos:ListParts', 'android-ut-persist-bucket-1253653367',
              'ap-guangzhou', 'exampleobject'))
    scopes.append(
        Scope('name/cos:UploadPart', 'android-ut-persist-bucket-1253653367',
              'ap-guangzhou', 'exampleobject'))
    scopes.append(
        Scope('name/cos:CompleteMultipartUpload',
              'android-ut-persist-bucket-1253653367', 'ap-guangzhou',
              'exampleobject'))
    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)
예제 #3
0
def test_sts():
    scopes = list()
    scopes.append(Scope('name/cos:PutObject', 'example-1253653367', 'ap-guangzhou', 'exampleobject'))
    scopes.append(Scope('name/cos:GetObject', 'example-1253653367', 'ap-guangzhou', 'exampleobject'))
    scopes.append(Scope('name/cos:InitiateMultipartUpload', 'example-1253653367', 'ap-guangzhou', 'exampleobject'))
    scopes.append(Scope('name/cos:ListParts', 'example-1253653367', 'ap-guangzhou', 'exampleobject'))
    scopes.append(Scope('name/cos:UploadPart', 'example-1253653367', 'ap-guangzhou', 'exampleobject'))
    scopes.append(Scope('name/cos:CompleteMultipartUpload', 'example-1253653367', 'ap-guangzhou', 'exampleobject'))
    scopes.append(Scope('name/cos:GetObject', 'example-1253653367', 'ap-guangzhou', '1/test.txt'))
    config = {
        # 临时密钥有效时长,单位是秒
        'duration_seconds': 1800,
        'secret_id': os.environ['COS_SECRET_ID'],
        # 固定密钥
        'secret_key': os.environ['COS_SECRET_KEY'],
        # 换成 bucket 所在地区
        'region': 'ap-guangzhou',
        #  设置网络代理
        # 'proxy': {
        #     'http': 'xxx',
        #     'https': 'xxx'
        # },
        'policy': Sts.get_policy(scopes)
    }

    sts = Sts(config)
    response = sts.get_credential()
    print('get data : ' + json.dumps(dict(response), indent=4))
예제 #4
0
def test_policy2():
    scopes = list()
    scopes.append(Scope('name/cos:PutObject', 'example-1250000000', 'ap-guangzhou', 'exampleobject'))
    scopes.append(Scope('name/cos:GetObject', 'example-1250000000', 'ap-guangzhou', 'exampleobject'))
    scopes.append(Scope('name/cos:InitiateMultipartUpload', 'example-1250000000', 'ap-guangzhou', 'exampleobject'))
    scopes.append(Scope('name/cos:ListParts', 'example-1250000000', 'ap-guangzhou', 'exampleobject'))
    scopes.append(Scope('name/cos:UploadPart', 'example-1250000000', 'ap-guangzhou', 'exampleobject'))
    scopes.append(Scope('name/cos:CompleteMultipartUpload', 'example-1250000000', 'ap-guangzhou', 'exampleobject'))
    scopes.append(Scope('name/cos:GetObject', 'example-1250000000', 'ap-guangzhou', '1/test.txt'))
    print(json.dumps(Sts.get_policy(scopes), indent=4))
예제 #5
0
def test_sts():
    scopes = list()
    scopes.append(
        Scope('name/cos:PutObject', 'example-1250000000', 'ap-guangzhou',
              'exampleobject'))
    scopes.append(
        Scope('name/cos:GetObject', 'example-1250000000', 'ap-guangzhou',
              'exampleobject'))
    scopes.append(
        Scope('name/cos:InitiateMultipartUpload', 'example-1250000000',
              'ap-guangzhou', 'exampleobject'))
    scopes.append(
        Scope('name/cos:ListParts', 'example-1250000000', 'ap-guangzhou',
              'exampleobject'))
    scopes.append(
        Scope('name/cos:UploadPart', 'example-1250000000', 'ap-guangzhou',
              'exampleobject'))
    scopes.append(
        Scope('name/cos:CompleteMultipartUpload', 'example-1250000000',
              'ap-guangzhou', 'exampleobject'))
    scopes.append(
        Scope('name/cos:GetObject', 'example-1250000000', 'ap-guangzhou',
              '1/test.txt'))
    config = {
        # 临时密钥有效时长,单位是秒
        'duration_seconds': 1800,
        # 固定密钥 id
        'secret_id': 'AKIDPXXX',
        # 固定密钥 key
        'secret_key': 'EH8xxx',
        #  设置网络代理
        # 'proxy': {
        #     'http': 'xxx',
        #     'https': 'xxx'
        # },
        'policy': Sts.get_policy(scopes)
    }

    sts = Sts(config)
    response = sts.get_credential()
    print('get data : ' + json.dumps(dict(response), indent=4))
예제 #6
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))
예제 #7
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))
예제 #8
0
def test_policy():
    scope = Scope('name/cos:PutObject', 'test-1250000000', 'ap-guangzhou',
                  'exampleobject')
    scopes = list()
    scopes.append(scope)
    print(json.dumps(Sts.get_policy(scopes), indent=4))
예제 #9
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))