util.__global__ Class
Utilities module
Item Index
Methods
_authWithHeader
-
method -
headers -
queryObj -
callback -
[bucket] -
[object] -
[data]
Authenticated with http header
Parameters:
-
methodStringHttp method
-
headersObjectHttp header
-
queryObjObjectExtra query string in object format
-
callbackFunctionFunction called when get response. callback supplied with http.Response object
-
[bucket]String optionalbucket name
-
[object]String optionalobject name
-
[data]String optionalobject content
authWithUrl
-
params -
callback
URL 中包含签名示例:
http://storage.aliyun.com/quotes/nelson?OSSAccessKeyId=44CF9590006BF252F707&Expires=1141889120
&Signature=vjbyPxybdZaNmGa%2ByT272YEAiv4%3D
在 URL 中实现签名,必须至少包含 Signature,Expires,OSSAccessKeyId
三个参数。Expires 这个参数的值是一个 UNIX 时间(自 UTC 时间 1970 年 1 月 1
号开始的秒数,详见 wiki),用于标识该 URL 的超时时间。如果 OSS 接收到这
个URL请求的时候晚于签名中包含的Expires参数时,则返回请求超时的错误码。
例如:当前时间是 1141889060,开发者希望创建一个 60 秒后自动失效的 URL,13
则可以设置 Expires 时间为 1141889120。
所有的 OSS 支持的请求和各种 Head 参数,在 URL 中进行签名的方法和上
节介绍的签名算法基本一样。主要区别如下:
1) 通过 URL 包含签名时,之前的 Date 参数换成 Expires 参数。
2) 不支持同时在 URL 和 Head 中包含签名。
3) 如果传入的 Signature,Expires,OSSAccessKeyId 出现不止一次,以第一次
为准。
4) 请求先验证请求时间是否晚于 Expires 时间,然后再验证签名。
Parameters:
-
paramsObjectvariable parameters,the following two are necessary:
- method http method
- headers http headers
- timeout expire millisecond after now
- bucket bucket name
- object object name
-
callbackFunctionCallback function after OSS response, supplied with http.Response object
cryptoMD5
-
data
Crypto data with MD5
Parameters:
-
dataStringContent need crypto
Returns:
debugOutput
-
func -
variable -
variable -
[sep]
Debug mode variable output helper
Parameters:
-
funcStringfunction name contain the variable
-
variableStringvariable name
-
variableAllvalue
-
[sep]String optionalseperator for each output
debugOutput
-
func -
variable -
variable -
[sep]
Debug mode variable output helper
Parameters:
-
funcStringfunction name contain the variable
-
variableStringvariable name
-
variableAllvalue
-
[sep]String optionalseperator for each output
getCanonicalizedHeader
-
headers
1) 将所有以“x-oss-”为前缀的 HTTP 请求头的名字转换成小写字母。如’X-OSS-Meta-Name: TaoBao’
转换成’x-oss-meta-name: TaoBao’。
2) 将上一步得到的所有 HTTP 请求头按照字典序进行升序排列。
3) 如果有相同名字的请求头,则根据标准 RFC 2616, 4.2 章进行合并(两个值之间只用逗号分隔)。
如有两个名为’x-oss-meta-name’的请求头,对应的值分别为’TaoBao’和’Alipay’,则合并后
为:’x-oss-meta-name:TaoBao,Alipay’。
4) 删除请求头和内容之间分隔符两端出现的任何空格。如’x-oss-meta-name: TaoBao,Alipay’转换
成:’x-oss-meta-name:TaoBao,Alipay’。
5) 将所有的头和内容用’\n’分隔符分隔拼成最后的 CanonicalizedOSSHeader。
Parameters:
-
headersObjecthttp header
Returns:
getCanonicalizedResource
-
queryObj -
[bucket] -
[object]
1) 将CanonicalizedResource 置成空字符串(“”)
2) 放入要访问的 OSS 资源:“ /BucketName/ObjectName”(无 ObjectName 则不填)
3) 如果请求的资源包括子资源(sub-resource),那么将所有的子资源按照字典序,从小到大排列并
以’&’为分隔符生成子资源字符串。在 CanonicalizedResource 字符串尾添加“?”和子资源字
符串。此时的 CanonicalizedResource 例子如:/BucketName/ObjectName?acl &uploadId=UploadId
4) 如果用户请求在查询字符串(query string)中指定了要重写(override)返回请求的 header
那么将这些查询字符串及其请求值按照字典序,从小到大排列,以’&’为分隔符,按参数的字典序添加到
CanonicalizedResource 中。此时的 CanonicalizedResource 例子:
/BucketName/ObjectName?acl&response-content-type=ContentType & uploadId =UploadId
Parameters:
-
queryObjObjectExtra query string in object format
-
[bucket]String optionalbucket name
-
[object]String optionalobject name
getPathname
-
[bucket] -
[object]
Generate path name. Both bucket and object name are optional, but If bucket name not appeared,object name should disappear neither.
Parameters:
-
[bucket]String optionalbucket name
-
[object]String optionalobject name
Returns:
getSign
-
access_key_secret -
method -
headers -
queryObj -
[bucket] -
[object]
Sign message using hmac-sha1
Parameters:
-
access_key_secretStringPersonal access key secret
-
methodStringhttp method
-
headersObjecthttp headers
-
queryObjObjectExtra query string in object format
-
[bucket]String optionalbucket name
-
[object]String optionalobject name
Returns:
getUnixTime
-
timeout
Get Unix time from 1970.1.1 to now in seconds
Parameters:
-
timeoutNumberexpire timeout millisecond later
Returns:
getUTCDate
-
timeout
Get UTC format timeout millisecond fron now on
Parameters:
-
timeoutNumbermillisecond from now on
