From 0b47fbe861084dfd5821efaf786000b5ef8d7864 Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Fri, 4 Sep 2015 00:12:32 -0700 Subject: [PATCH] deploy api: code clean-up and add todo --- lib/commands/deploy_api.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/commands/deploy_api.js b/lib/commands/deploy_api.js index 61988c3ff..cc7fee2ae 100644 --- a/lib/commands/deploy_api.js +++ b/lib/commands/deploy_api.js @@ -4,6 +4,9 @@ * JAWS Command: deploy api * - Deploys project's API Gateway REST API to the specified stage */ + +// TODO: Validate Endpoint JSON + var JawsError = require('../jaws-error'), Promise = require('bluebird'), fs = require('fs'), @@ -41,7 +44,7 @@ function ApiDeployer(stage, region, prjRootPath, prjJson, prjCreds) { _this._prjCreds = prjCreds; _this._endpoints = []; _this._resources = []; - _this._awsAccountNumber = _this._region.iamRoleArn.replace('arn:aws:iam::','').split(':')[0]; + _this._awsAccountNumber = _this._region.iamRoleArn.replace('arn:aws:iam::', '').split(':')[0]; _this._restApiId = _this._region.restApiId ? _this._region.restApiId : null; // Instantiate API Gateway Client @@ -117,7 +120,8 @@ ApiDeployer.prototype._findOrCreateApi = Promise.method(function() { .then(function(response) { _this._restApiId = response.id; - utils.logIfVerbose(_this._region.region + ': found existing REST API on AWS API Gateway with ID: ' + response.id); + utils.logIfVerbose(_this._region.region + + ': found existing REST API on AWS API Gateway with ID: ' + response.id); }); } else { @@ -179,7 +183,7 @@ ApiDeployer.prototype._buildEndpoints = Promise.method(function() { .then(_this._createEndpointMethod) .then(_this._createEndpointIntegration) .then(_this._createEndpointMethodResponses) - .then(_this._createEndpointMethodIntegResponses) + .then(_this._createEndpointMethodIntegResponses); }); }); @@ -289,7 +293,8 @@ ApiDeployer.prototype._createEndpointMethod = Promise.method(function(endpoint) methodBody); }); }, function() { - _this.ApiClient.putMethod( + + return _this.ApiClient.putMethod( _this._restApiId, endpoint.endpoint.apig.resource.id, endpoint.endpoint.method, @@ -343,6 +348,7 @@ ApiDeployer.prototype._createEndpointIntegration = Promise.method(function(endpo 'JAWS API Gateway integration currently supports lambda only', JawsError.errorCodes.UNKNOWN); } + // Create Integration return _this.ApiClient.putIntegration( _this._restApiId, @@ -372,7 +378,7 @@ ApiDeployer.prototype._createEndpointMethodResponses = Promise.method(function(e var _this = this; - return Promise.try(function () { + return Promise.try(function() { // Collect Response Keys if (endpoint.endpoint.responses) return Object.keys(endpoint.endpoint.responses); @@ -401,7 +407,7 @@ ApiDeployer.prototype._createEndpointMethodResponses = Promise.method(function(e + ': created method response for the path: ' + endpoint.endpoint.path); }) - .catch(function (error) { + .catch(function(error) { throw new JawsError( error.message, JawsError.errorCodes.UNKNOWN); @@ -419,7 +425,7 @@ ApiDeployer.prototype._createEndpointMethodIntegResponses = Promise.method(funct var _this = this; - return Promise.try(function () { + return Promise.try(function() { // Collect Response Keys if (endpoint.endpoint.responses) return Object.keys(endpoint.endpoint.responses); @@ -493,7 +499,7 @@ module.exports = function(JAWS) { * @param stage * @returns {bluebird|exports|module.exports} */ - JAWS.deployApi = function (stage, region, allTagged) { + JAWS.deployApi = function(stage, region, allTagged) { return new Promise(function(resolve, reject) { // Check stage exists @@ -556,5 +562,5 @@ module.exports = function(JAWS) { }); }); }); - } + }; }; \ No newline at end of file