mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
deploy api: code clean-up and add todo
This commit is contained in:
parent
8ca56a429e
commit
0b47fbe861
@ -4,6 +4,9 @@
|
||||
* JAWS Command: deploy api <stage>
|
||||
* - 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) {
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user