Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue when specifying old apiVersion with some service clients #1152

Merged
merged 1 commit into from
Sep 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-apiVersion-3752650d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "apiVersion",
"description": "Fixes an issue where some service clients would fail to instantiate if an older apiVersion was specified."
}
2 changes: 1 addition & 1 deletion clients/cloudfront.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var Service = require('../lib/service');
var apiLoader = require('../lib/api_loader');

apiLoader.services['cloudfront'] = {};
AWS.CloudFront = Service.defineService('cloudfront', ['2016-09-07']);
AWS.CloudFront = Service.defineService('cloudfront', ['2013-05-12*', '2013-11-11*', '2014-05-31*', '2014-10-21*', '2014-11-06*', '2015-04-17*', '2015-07-27*', '2015-09-17*', '2016-01-13*', '2016-01-28*', '2016-08-01*', '2016-08-20*', '2016-09-07']);
require('../lib/services/cloudfront');
Object.defineProperty(apiLoader.services['cloudfront'], '2016-09-07', {
get: function get() {
Expand Down
2 changes: 1 addition & 1 deletion clients/cloudwatchevents.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var Service = require('../lib/service');
var apiLoader = require('../lib/api_loader');

apiLoader.services['cloudwatchevents'] = {};
AWS.CloudWatchEvents = Service.defineService('cloudwatchevents', ['2015-10-07']);
AWS.CloudWatchEvents = Service.defineService('cloudwatchevents', ['2014-02-03*', '2015-10-07']);
Object.defineProperty(apiLoader.services['cloudwatchevents'], '2015-10-07', {
get: function get() {
var model = require('../apis/events-2015-10-07.min.json');
Expand Down
2 changes: 1 addition & 1 deletion clients/ec2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var Service = require('../lib/service');
var apiLoader = require('../lib/api_loader');

apiLoader.services['ec2'] = {};
AWS.EC2 = Service.defineService('ec2', ['2016-04-01']);
AWS.EC2 = Service.defineService('ec2', ['2013-06-15*', '2013-10-15*', '2014-02-01*', '2014-05-01*', '2014-06-15*', '2014-09-01*', '2014-10-01*', '2015-03-01*', '2015-04-15*', '2015-10-01*', '2016-04-01']);
require('../lib/services/ec2');
Object.defineProperty(apiLoader.services['ec2'], '2016-04-01', {
get: function get() {
Expand Down
2 changes: 1 addition & 1 deletion clients/elasticache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var Service = require('../lib/service');
var apiLoader = require('../lib/api_loader');

apiLoader.services['elasticache'] = {};
AWS.ElastiCache = Service.defineService('elasticache', ['2015-02-02']);
AWS.ElastiCache = Service.defineService('elasticache', ['2012-11-15*', '2014-03-24*', '2014-07-15*', '2014-09-30*', '2015-02-02']);
Object.defineProperty(apiLoader.services['elasticache'], '2015-02-02', {
get: function get() {
var model = require('../apis/elasticache-2015-02-02.min.json');
Expand Down
2 changes: 1 addition & 1 deletion clients/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var Service = require('../lib/service');
var apiLoader = require('../lib/api_loader');

apiLoader.services['inspector'] = {};
AWS.Inspector = Service.defineService('inspector', ['2016-02-16']);
AWS.Inspector = Service.defineService('inspector', ['2015-08-18*', '2016-02-16']);
Object.defineProperty(apiLoader.services['inspector'], '2016-02-16', {
get: function get() {
var model = require('../apis/inspector-2016-02-16.min.json');
Expand Down
2 changes: 1 addition & 1 deletion clients/rds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var Service = require('../lib/service');
var apiLoader = require('../lib/api_loader');

apiLoader.services['rds'] = {};
AWS.RDS = Service.defineService('rds', ['2013-01-10', '2013-02-12', '2013-09-09', '2014-10-31']);
AWS.RDS = Service.defineService('rds', ['2013-01-10', '2013-02-12', '2013-09-09', '2014-09-01*', '2014-10-31']);
Object.defineProperty(apiLoader.services['rds'], '2013-01-10', {
get: function get() {
var model = require('../apis/rds-2013-01-10.min.json');
Expand Down
3 changes: 2 additions & 1 deletion dist-tools/client-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ ClientCreator.prototype.generateClientFileSource = function generateClientFileSo
if (!modelVersions) {
throw new Error('Unable to get models for ' + modelName);
}
var obsoleteVersions = serviceMetadata.versions || [];
var versionNumbers = Object.keys(modelVersions);
var tab = ' ';
var code = '';
Expand All @@ -88,7 +89,7 @@ ClientCreator.prototype.generateClientFileSource = function generateClientFileSo
code += 'var Service = require(\'../lib/service\');\n';
code += 'var apiLoader = require(\'../lib/api_loader\');\n\n';
code += 'apiLoader.services[\'' + serviceName +'\'] = {};\n';
code += 'AWS.' + className + ' = Service.defineService(\'' + serviceName + '\', [\'' + versionNumbers.join('\', \'') + '\']);\n';
code += 'AWS.' + className + ' = Service.defineService(\'' + serviceName + '\', [\'' + [].concat(obsoleteVersions, versionNumbers).sort().join('\', \'') + '\']);\n';
// pull in service customizations
if (this.customizationsExist(serviceName)) {
code += 'require(\'../lib/services/' + serviceName + '\');\n';
Expand Down
13 changes: 13 additions & 0 deletions test/service.spec.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
helpers = require('./helpers')
AWS = helpers.AWS
MockService = helpers.MockService
metadata = require('../apis/metadata.json')

describe 'AWS.Service', ->

Expand Down Expand Up @@ -135,6 +136,18 @@ describe 'AWS.Service', ->
service = new MockService(sslEnabled: false, endpoint: '{scheme}://{service}.{region}.domain.tld')
expect(service.config.endpoint).to.equal('http://mockservice.mock-region.domain.tld')

describe 'will work with', ->
allServices = require('../clients/all')
for own className, ctor of allServices
serviceIdentifier = className.toLowerCase()
# check for obsolete versions
obsoleteVersions = metadata[serviceIdentifier].versions || []
for version in obsoleteVersions
((ctor, id, v) ->
it id + ' version ' + v, ->
expect(-> new ctor(apiVersion: v)).not.to.throw()
)(ctor, serviceIdentifier, version)

describe 'setEndpoint', ->
FooService = null

Expand Down