Skip to content

Commit 84556af

Browse files
authored
Merge pull request #420 from MitocGroup/issue_414
#414: Add versioning into API endpoints using API Gateway service
2 parents 958e200 + 44ac0db commit 84556af

15 files changed

Lines changed: 36 additions & 7 deletions

File tree

‎src/lib/Property/DeployConfig.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,11 @@ export class DeployConfig {
242242
static get AVAILABLE_ENV() {
243243
return ['dev', 'stage', 'test', 'prod'];
244244
}
245+
246+
/**
247+
* @returns {String}
248+
*/
249+
static get DEFAULT_API_VERSION() {
250+
return 'v1';
251+
}
245252
}

‎src/lib/Property/Instance.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ export class Instance {
299299
return this._config.env;
300300
}
301301

302+
/**
303+
* @returns {String}
304+
*/
305+
get apiVersion() {
306+
return this._config.apiVersion;
307+
}
308+
302309
/**
303310
* @returns {String}
304311
*/

‎src/lib/Property/config.schema.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export default {
9393
domain: Joi.string().optional().lowercase()
9494
.regex(/^([a-zA-Z0-9-_]+\.)+[a-zA-Z]+?$/i)
9595
.replace(/^www\./i, ''),
96+
apiVersion: JoiHelper.string().regex(/^[a-zA-Z0-9_]+$/i).required().default(DeployConfig.DEFAULT_API_VERSION),
9697
aws: Joi.object().keys({
9798
accessKeyId: JoiHelper.string().required().empty(''),
9899
secretAccessKey: JoiHelper.string().required().empty(''),
@@ -111,6 +112,7 @@ export default {
111112
appIdentifier: JoiHelper.string().regex(/^[a-zA-Z0-9_\.-]+$/).optional().default(appId),
112113
env: JoiHelper.stringEnum(DeployConfig.AVAILABLE_ENV).optional().default(DeployConfig.AVAILABLE_ENV[0]),
113114
awsAccountId: Joi.number().optional().default(guessAwsAccountId(guessedAwsCredentials)),
115+
apiVersion: JoiHelper.string().regex(/^[a-zA-Z0-9_]+$/i).required().default(DeployConfig.DEFAULT_API_VERSION),
114116
aws: Joi.object().keys({
115117
accessKeyId: JoiHelper.string().required(),
116118
secretAccessKey: JoiHelper.string().required(),

‎src/lib/Provisioning/Service/APIGatewayService.js‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class APIGatewayService extends AbstractService {
155155
* @returns {String}
156156
*/
157157
get stageName() {
158-
return this.env;
158+
return this.property.apiVersion;
159159
}
160160

161161
/**
@@ -253,11 +253,12 @@ export class APIGatewayService extends AbstractService {
253253
this._config.api.id,
254254
this._config.api.resources,
255255
this._config.api.role
256-
)((methods, integrations, rolePolicy, deployedApi, authorizer) => {
256+
)((methods, integrations, rolePolicy, apiStage, authorizer) => {
257257
this._config.api.methods = methods;
258258
this._config.api.integrations = integrations;
259259
this._config.api.rolePolicy = rolePolicy;
260-
this._config.api.deployedApi = deployedApi;
260+
this._config.api.stages = this._config.api.stages || {};
261+
this._config.api.stages[this.stageName] = apiStage;
261262
this._config.api.authorizer = authorizer;
262263

263264
// generate cloud watch log group name for deployed API Gateway
@@ -388,10 +389,10 @@ export class APIGatewayService extends AbstractService {
388389
this._addPolicyToApiRole(apiRole, (data) => {
389390
rolePolicy = data;
390391

391-
this._deployApi(apiId, (deployedApi) => {
392+
this._deployApi(apiId, (apiStage) => {
392393

393394
this._updateStage(apiId, this.stageName, apiRole, this.apiConfig, (data) => {
394-
callback(methods, integrations, rolePolicy, deployedApi, authorizer);
395+
callback(methods, integrations, rolePolicy, apiStage, authorizer);
395396
});
396397
});
397398
});
@@ -564,7 +565,7 @@ export class APIGatewayService extends AbstractService {
564565
stageName: this.stageName,
565566
cacheClusterEnabled: this.apiConfig.cache.enabled,
566567
cacheClusterSize: this.apiConfig.cache.clusterSize,
567-
stageDescription: `Stage for "${this.env}" environment`,
568+
stageDescription: `Stage for "${this.env}/${this.stageName}" environment`,
568569
description: `Deployed on ${new Date().toTimeString()}`,
569570
};
570571

‎src/test/Property/Config.spec.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ suite('Property/Config', () => {
1111
secretAccessKey: 'to_pass_string_validation',
1212
},
1313
env: 'test',
14+
apiVersion: 'v1',
1415
awsAccountId: 123456789012,
1516
appIdentifier: 'test_appId-432423-generated',
1617
appName: 'appName'
@@ -50,6 +51,7 @@ suite('Property/Config', () => {
5051
secretAccessKey: 'to_pass_string_validation',
5152
},
5253
env: 'test',
54+
apiVersion: 'v1',
5355
awsAccountId: 123456789012,
5456
appIdentifier: 'generated',
5557
appName: 'sample app'
@@ -76,6 +78,7 @@ suite('Property/Config', () => {
7678
// },
7779
// awsAccountId: 123456789012,
7880
// env: 'dev',
81+
// apiVersion: 'v1',
7982
// appIdentifier: 'randomly generated',
8083
// };
8184
// chai.expect(Config.generate().awsAccountId).to.be.equal(generatedConfig.awsAccountId);

‎src/test/Property/Frontend.spec.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ suite('Property/Frontend', () => {
3636
},
3737
awsAccountId: 123456789012,
3838
env: 'dev',
39+
apiVersion: 'v1',
3940
appIdentifier: '59e6913c9ed3afe744b5434817ce6345',
4041
},
4142
validationSchemas: [],

‎src/test/Provisioning/Service/APIGatewayService.spec.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ suite('Provisioning/Service/APIGatewayService', () => {
129129
});
130130

131131
test('Check stageName getter returns valid value', () => {
132-
chai.expect(apiGatewayService.stageName).to.be.eql('test');
132+
chai.expect(apiGatewayService.stageName).to.be.eql('v1');
133133
});
134134

135135
//test('Check _updateCognitoRolesPolicy() method updates cognito roles policy', () => {

‎src/test/testMaterials/Property1/deeploy.test.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"secretAccessKey": "to_pass_string_validation"
66
},
77
"env": "test",
8+
"apiVersion": "v1",
89
"awsAccountId": 123456789012,
910
"appIdentifier": "generated",
1011
"appName": "sample app"

‎src/test/testMaterials/Property1_dep/deeploy.test.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"secretAccessKey": "to_pass_string_validation"
66
},
77
"env": "test",
8+
"apiVersion": "v1",
89
"awsAccountId": 123456789012,
910
"appIdentifier": "generated",
1011
"appName": "sample app"

‎src/test/testMaterials/Property1_dep2/deeploy.test.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"secretAccessKey": "to_pass_string_validation"
66
},
77
"env": "test",
8+
"apiVersion": "v1",
89
"awsAccountId": 123456789012,
910
"appIdentifier": "generated",
1011
"appName": "sample app"

0 commit comments

Comments
 (0)