Skip to main content

this is sts for python on v3

Project description

获取 SDK

pip install -U qcloud-python-sts

调用示例

请查看 demo 里的示例。

接口说明

get_credential

获取临时密钥接口

参数说明

字段 类型 描述
secret_id String 云 API 密钥 Id
secret_key String 云 API 密钥 key
duration_seconds long 要申请的临时密钥最长有效时间,单位秒,默认 1800,最大可设置 7200
bucket String 存储桶名称:bucketName-appid, 如 test-125000000
region String 存储桶所属地域,如 ap-guangzhou
allow_prefix list 资源的前缀,可以根据自己网站的用户登录态判断允许上传的具体路径,例子: a.jpg 或者 a/* 或者 * (使用通配符*存在重大安全风险, 请谨慎评估使用)
allow_actions list 授予 COS API 权限集合, 如简单上传操作:name/cos:PutObject
policy dict 策略:由 allow_actions、bucket、allow_prefix字段组成的描述授权的具体信息

返回值说明

字段 类型 描述
credentials dict 临时密钥信息
tmpSecretId String 临时密钥 Id,可用于计算签名
tmpSecretKey String 临时密钥 Key,可用于计算签名
sessionToken String 请求时需要用的 token 字符串,最终请求 COS API 时,需要放在 Header 的 x-cos-security-token 字段
startTime String 密钥的起始时间,是 UNIX 时间戳
expiredTime String 密钥的失效时间,是 UNIX 时间戳

返回结果

成功的话,可以拿到包含密钥的 JSON 文本:

{
    "credentials": {
        "tmpSecretId": "AKIDEPMQB_Q9Jt2fJxXyIekOzKZzx-sdGQgBga4TzsUdTWL9xlvsjInOHhCYFqfoKOY4",
        "tmpSecretKey": "W/3Lbl1YEW02mCoawIesl5kNehSskrSbp1cT1tgW70g=",
        "sessionToken": "c6xnSYAxyFbX8Y50627y9AA79u6Qfucw6924760b61588b79fea4c277b01ba157UVdr_10Y30bdpYtO8CXedYZe3KKZ_DyzaPiSFfNAcbr2MTfAgwJe-dhYhfyLMkeCqWyTNF-rOdOb0rp4Gto7p4yQAKuIPhQhuDd77gcAyGakC2WXHVd6ZuVaYIXBizZxqIHAf4lPiLHa6SZejSQfa_p5Ip2U1cAdkEionKbrX97xTKTcA_5Pu525CFSzHZIQibc2uNMZ-IRdQp12MaXZB6bxM6nB4xXH45mDIlbIGjaAsrtRJJ3csmf82uBKaJrYQoguAjBepMH91WcH87LlW9Ya3emNfVX7NMRRf64riYd_vomGF0TLgan9smEKAOdtaL94IkLvVJdhLqpvjBjp_4JCdqwlFAixaTzGJHdJzpGWOh0mQ6jDegAWgRYTrJvc5caYTz7Vphl8XoX5wHKKESUn_vqyTAid32t0vNYE034FIelxYT6VXuetYD_mvPfbHVDIXaFt7e_O8hRLkFwrdAIVaUml1mRPvccv2qOWSXs"
    },
    "expiration": "2019-08-07T08:54:35Z",
    "startTime": 1565166275,
    "expiredTime": 1565168075
}

get_policy

获取策略(policy)接口。本接口适用于接收 Web、iOS、Android 客户端 SDK 提供的 Scope 参数。推荐您把 Scope 参数放在请求的 Body 里面,通过 POST 方式传到后台。

参数说明

字段 类型 描述
bucket String 存储桶名称:bucketName-appid, 如 test-125000000
region String 存储桶所属地域,如 ap-guangzhou
resource_prefix String 资源的前缀,可以根据自己网站的用户登录态判断允许上传的具体路径,例子: a.jpg 或者 a/* 或者 * (使用通配符*存在重大安全风险, 请谨慎评估使用)
action String 授予 COS API 权限,, 如简单上传操作:name/cos:PutObject
scope Scope 构造policy的信息:由 action、bucket、region、sourcePrefix组成

返回值说明

字段 类型 描述
policy dict 申请临时密钥所需的权限策略

返回结果

{
"version":"2.0",
"statement":[
	{
		"action":["name/cos:PutObject"],
		"effect":"allow",
		"resource":["qcs::cos:ap-guangzhou:uid/1250000000:example-1250000000/1.txt"]
	},
	{
		"action":["name/cos:GetObject" ],
		"effect":"allow",
		"resource":["qcs::cos:ap-guangzhou:uid/1250000000:example-1250000000/dir/exampleobject" ]
	}
]
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qcloud-python-sts-3.1.6.tar.gz (6.3 kB view details)

Uploaded Source

File details

Details for the file qcloud-python-sts-3.1.6.tar.gz.

File metadata

  • Download URL: qcloud-python-sts-3.1.6.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.8

File hashes

Hashes for qcloud-python-sts-3.1.6.tar.gz
Algorithm Hash digest
SHA256 7fdbd9d4d45587714e731e7de5812ed44e77d70a139f3400fe5e4b5b3ddc32d3
MD5 6fb6433bb8fa73b5a52a9a2b88efe339
BLAKE2b-256 6861b1499952745afa145a814b5a190e8dab2ae9239bfb156658d435addcd19f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page