ks33requests.auth module¶
-
ks33requests.auth.
generate_auth_headers
(http_verb: str, access_key: str, secret_key: str, canonical_resource: str, content_md5: str = '') → Dict[str, str]¶ 生成公共响应头的签名
- 参数
http_verb (str) – 请求的方法,如:
GET
,PUT
,POST
,DELETE
等access_key (str) – KS3 颁发给您的 AccessKey (长度为20个字符的ASCII字符串)。用于标识客户的身份。
secret_key (str) – KS3 颁发给您的 SecretKey (长度为40个字符的ASCII字符串)。作为私钥形式存放于客户服务器不在网络中传递。
canonical_resource (str) –
表示用户访问的资源
content_md5 (str) –
表示请求内容数据的MD5值, 使用Base64编码。
当请求的header中包含Content-MD5时,需要在StringToSign中包含,否则用(“”)替代。
注解
Content-MD5 的算法为先对数据做MD5摘要,再将MD5摘要做Base64编码。 中间不需要做HEX编码,由于部分语言或工具包的MD5是默认做HEX编码的,所以当MD5算出来的结果为HEX编码的,首先需要对算出来的结果做HEX解码,然后再做Base64编码。
参见
详解见 RFC2616
- 返回
HTTP 请求中的
Date
和Authorization
头域- 返回类型
-
ks33requests.auth.
make_canonical_resource_string
(bucket_name: str = '', object_key: str = '', sub_resources: Union[str, List[str], None] = None) → str¶ CanonicalizedResource 的计算方法
- 参数
- 返回
CanonicalizedResource 字符串表示用户访问的资源,将作为 HTTP 请求的 URL 的一部分
- 返回类型
计算方法如下:
CanonicalizedResource="/"
如果
BucketName
不为空,则CanonicalizedResource = CanonicalizedResource + BucketName + "/"
如果
ObjectKey
不为空,则CanonicalizedResource = CanonicalizedResource + ObjectKey
替换
CanonicalizedResource
中的双斜杠("//"
)为"/%2F"
如果
SubResource
不为空,则CanonicalizedResource = CanonicalizedResource + "?" + SubResource