-
Notifications
You must be signed in to change notification settings - Fork 576
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add asyncSignatureUrl method (#1057)
* feat: add asyncSignatureUrl method * chore: add asyncSignatureUrl warn message * feat: to resolve conversation * chore: optimized test case * chore: optimized test case * chore: chore: optimized test case * chore: the tag signatureUrl will be deprecated in the next version * chore: remove not use function checkBrowserEnv Co-authored-by: Undefined <peizerao@gmail.com>
- Loading branch information
Showing
8 changed files
with
190 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const urlutil = require('url'); | ||
const utility = require('utility'); | ||
const copy = require('copy-to'); | ||
const signHelper = require('../../common/signUtils'); | ||
const { isIP } = require('../utils/isIP'); | ||
const { setSTSToken } = require('../utils/setSTSToken'); | ||
const { isFunction } = require('../utils/isFunction'); | ||
const proto = exports; | ||
|
||
proto.asyncSignatureUrl = async function asyncSignatureUrl(name, options) { | ||
if (isIP(this.options.endpoint.hostname)) { | ||
throw new Error('can not get the object URL when endpoint is IP'); | ||
} | ||
options = options || {}; | ||
name = this._objectName(name); | ||
options.method = options.method || 'GET'; | ||
const expires = utility.timestamp() + (options.expires || 1800); | ||
const params = { | ||
bucket: this.options.bucket, | ||
object: name | ||
}; | ||
|
||
const resource = this._getResource(params); | ||
|
||
if (this.options.stsToken && isFunction(this.options.refreshSTSToken)) { | ||
await setSTSToken.call(this); | ||
} | ||
|
||
if (this.options.stsToken) { | ||
options['security-token'] = this.options.stsToken; | ||
} | ||
|
||
const signRes = signHelper._signatureForURL(this.options.accessKeySecret, options, resource, expires); | ||
|
||
const url = urlutil.parse(this._getReqUrl(params)); | ||
url.query = { | ||
OSSAccessKeyId: this.options.accessKeyId, | ||
Expires: expires, | ||
Signature: signRes.Signature | ||
}; | ||
|
||
copy(signRes.subResource).to(url.query); | ||
|
||
return url.format(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters