-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support upload retry with multiple regions and add abstract design ab…
…out region
- Loading branch information
Showing
14 changed files
with
2,436 additions
and
354 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
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,51 @@ | ||
function Endpoint (host, options) { | ||
options = options || {}; | ||
|
||
this.host = host; | ||
this.defaultScheme = options.defaultScheme || 'https'; | ||
} | ||
|
||
/** | ||
* @typedef EndpointPersistInfo | ||
* @property {string} host | ||
* @property {string} defaultScheme | ||
*/ | ||
|
||
/** | ||
* @param {EndpointPersistInfo} persistInfo | ||
* @returns {Endpoint} | ||
*/ | ||
Endpoint.fromPersistInfo = function (persistInfo) { | ||
return new Endpoint(persistInfo.host, { | ||
defaultScheme: persistInfo.defaultScheme | ||
}); | ||
}; | ||
|
||
/** | ||
* @param {Object} [options] | ||
* @param {string} [options.scheme] | ||
*/ | ||
Endpoint.prototype.getValue = function (options) { | ||
options = options || {}; | ||
|
||
const scheme = options.scheme || this.defaultScheme; | ||
const host = this.host; | ||
|
||
return scheme + '://' + host; | ||
}; | ||
|
||
Object.defineProperty(Endpoint.prototype, 'persistInfo', { | ||
/** | ||
* @returns {EndpointPersistInfo} | ||
*/ | ||
get: function () { | ||
return { | ||
defaultScheme: this.defaultScheme, | ||
host: this.host | ||
}; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
|
||
exports.Endpoint = Endpoint; |
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,68 @@ | ||
/** | ||
* @interface EndpointsProvider | ||
*/ | ||
|
||
/** | ||
* @function | ||
* @name EndpointsProvider#setEndpoints | ||
* @param {endpoints: Endpoint[]} endpoints | ||
* @returns {Promise<void>} | ||
*/ | ||
|
||
/** | ||
* @function | ||
* @name EndpointsProvider#getEndpoints | ||
* @returns {Promise<Endpoint[]>} | ||
*/ | ||
|
||
// --- could split to files if migrate to typescript --- // | ||
|
||
/** | ||
* @class | ||
* @implements EndpointsProvider | ||
* @property {Endpoint[]} endpoints | ||
* @constructor | ||
* @param {Endpoint[]} endpoints | ||
*/ | ||
function StaticEndpointsProvider (endpoints) { | ||
this.endpoints = endpoints; | ||
} | ||
|
||
/** | ||
* @param {Region} region | ||
* @param {string} serviceName | ||
*/ | ||
StaticEndpointsProvider.fromRegion = function (region, serviceName) { | ||
return new StaticEndpointsProvider(region.services[serviceName]); | ||
}; | ||
|
||
/** | ||
* @returns {Promise<Endpoint[]>} | ||
*/ | ||
StaticEndpointsProvider.prototype.getEndpoints = function () { | ||
return Promise.resolve(this.endpoints); | ||
}; | ||
|
||
/** | ||
* @param {Endpoint[]} endpoints | ||
* @returns {Promise<void>} | ||
*/ | ||
StaticEndpointsProvider.prototype.setEndpoints = function (endpoints) { | ||
this.endpoints = endpoints; | ||
return Promise.resolve(); | ||
}; | ||
|
||
/** | ||
* @param {RegionsProvider} regionsProvider | ||
* @param {string} serviceName | ||
* @returns {Promise<EndpointsProvider[]>} | ||
*/ | ||
function getEndpointsProvidersFromRegionsProvider (regionsProvider, serviceName) { | ||
return regionsProvider.getRegions() | ||
.then(regions => { | ||
return regions.map(r => StaticEndpointsProvider.fromRegion(r, serviceName)); | ||
}); | ||
} | ||
|
||
exports.StaticEndpointsProvider = StaticEndpointsProvider; | ||
exports.getEndpointsProvidersFromRegionsProvider = getEndpointsProvidersFromRegionsProvider; |
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
Oops, something went wrong.