use directories for structure
This commit is contained in:
42
node_modules/aws4/aws4.js
generated
vendored
42
node_modules/aws4/aws4.js
generated
vendored
@@ -22,6 +22,10 @@ function encodeRfc3986(urlEncodedString) {
|
||||
})
|
||||
}
|
||||
|
||||
function encodeRfc3986Full(str) {
|
||||
return encodeRfc3986(encodeURIComponent(str))
|
||||
}
|
||||
|
||||
// request: { path | body, [host], [method], [headers], [service], [region] }
|
||||
// credentials: { accessKeyId, secretAccessKey, [sessionToken] }
|
||||
function RequestSigner(request, credentials) {
|
||||
@@ -29,7 +33,7 @@ function RequestSigner(request, credentials) {
|
||||
if (typeof request === 'string') request = url.parse(request)
|
||||
|
||||
var headers = request.headers = (request.headers || {}),
|
||||
hostParts = this.matchHost(request.hostname || request.host || headers.Host || headers.host)
|
||||
hostParts = (!this.service || !this.region) && this.matchHost(request.hostname || request.host || headers.Host || headers.host)
|
||||
|
||||
this.request = request
|
||||
this.credentials = credentials || this.defaultCredentials()
|
||||
@@ -66,6 +70,19 @@ RequestSigner.prototype.matchHost = function(host) {
|
||||
if (hostParts[1] === 'es')
|
||||
hostParts = hostParts.reverse()
|
||||
|
||||
if (hostParts[1] == 's3') {
|
||||
hostParts[0] = 's3'
|
||||
hostParts[1] = 'us-east-1'
|
||||
} else {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
if (/^s3-/.test(hostParts[i])) {
|
||||
hostParts[1] = hostParts[i].slice(3)
|
||||
hostParts[0] = 's3'
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hostParts
|
||||
}
|
||||
|
||||
@@ -79,10 +96,9 @@ RequestSigner.prototype.isSingleRegion = function() {
|
||||
}
|
||||
|
||||
RequestSigner.prototype.createHost = function() {
|
||||
var region = this.isSingleRegion() ? '' :
|
||||
(this.service === 's3' && this.region !== 'us-east-1' ? '-' : '.') + this.region,
|
||||
service = this.service === 'ses' ? 'email' : this.service
|
||||
return service + region + '.amazonaws.com'
|
||||
var region = this.isSingleRegion() ? '' : '.' + this.region,
|
||||
subdomain = this.service === 'ses' ? 'email' : this.service
|
||||
return subdomain + region + '.amazonaws.com'
|
||||
}
|
||||
|
||||
RequestSigner.prototype.prepareRequest = function() {
|
||||
@@ -222,20 +238,20 @@ RequestSigner.prototype.canonicalString = function() {
|
||||
if (query) {
|
||||
var reducedQuery = Object.keys(query).reduce(function(obj, key) {
|
||||
if (!key) return obj
|
||||
obj[key] = !Array.isArray(query[key]) ? query[key] :
|
||||
(firstValOnly ? query[key][0] : query[key].slice().sort())
|
||||
obj[encodeRfc3986Full(key)] = !Array.isArray(query[key]) ? query[key] :
|
||||
(firstValOnly ? query[key][0] : query[key])
|
||||
return obj
|
||||
}, {})
|
||||
var encodedQueryPieces = []
|
||||
Object.keys(reducedQuery).forEach(function(key) {
|
||||
var encodedPrefix = encodeURIComponent(key) + '='
|
||||
Object.keys(reducedQuery).sort().forEach(function(key) {
|
||||
if (!Array.isArray(reducedQuery[key])) {
|
||||
encodedQueryPieces.push(encodeRfc3986(encodedPrefix + encodeURIComponent(reducedQuery[key])))
|
||||
encodedQueryPieces.push(key + '=' + encodeRfc3986Full(reducedQuery[key]))
|
||||
} else {
|
||||
reducedQuery[key].forEach(function(val) { encodedQueryPieces.push(encodeRfc3986(encodedPrefix + encodeURIComponent(val))) })
|
||||
reducedQuery[key].map(encodeRfc3986Full).sort()
|
||||
.forEach(function(val) { encodedQueryPieces.push(key + '=' + val) })
|
||||
}
|
||||
})
|
||||
queryStr = encodedQueryPieces.sort().join('&')
|
||||
queryStr = encodedQueryPieces.join('&')
|
||||
}
|
||||
if (pathStr !== '/') {
|
||||
if (normalizePath) pathStr = pathStr.replace(/\/{2,}/g, '/')
|
||||
@@ -244,7 +260,7 @@ RequestSigner.prototype.canonicalString = function() {
|
||||
path.pop()
|
||||
} else if (!normalizePath || piece !== '.') {
|
||||
if (decodePath) piece = decodeURIComponent(piece).replace(/\+/g, ' ')
|
||||
path.push(encodeRfc3986(encodeURIComponent(piece)))
|
||||
path.push(encodeRfc3986Full(piece))
|
||||
}
|
||||
return path
|
||||
}, []).join('/')
|
||||
|
Reference in New Issue
Block a user