Skip to content

Commit

Permalink
Mirror back current api key source setting
Browse files Browse the repository at this point in the history
  • Loading branch information
QuingKhaos committed May 6, 2019
1 parent 01c1173 commit 12526c8
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class BinarySupport {
});
}

getApiGatewayApiKeySource(apiId) {
return new Promise(resolve => {
this.provider.request('APIGateway', 'getRestApi', { restApiId: apiId }).then(resp => {
resolve(resp['apiKeySource']);
});
});
}

putSwagger(apiId, swagger) {
return this.provider.request('APIGateway', 'putRestApi', { restApiId: apiId, mode: 'merge', body: swagger });
}
Expand All @@ -47,18 +55,22 @@ class BinarySupport {

afterDeploy() {
const mimeTypes = this.serverless.service.custom.apigwBinary.types;
const swaggerInput = JSON.stringify({
"swagger": "2.0",
"info": {
"title": this.getApiGatewayName()
},
"x-amazon-apigateway-binary-media-types": mimeTypes
});
const stage = this.options.stage || this.serverless.service.provider.stage;

return this.getApiId(stage).then(apiId => {
return this.putSwagger(apiId, swaggerInput).then(() => {
return this.createDeployment(apiId, stage);
return this.getApiGatewayApiKeySource(apiId).then(apiKeySource => {
const swaggerInput = JSON.stringify({
"swagger": "2.0",
"info": {
"title": this.getApiGatewayName()
},
"x-amazon-apigateway-api-key-source": apiKeySource,
"x-amazon-apigateway-binary-media-types": mimeTypes
});

return this.putSwagger(apiId, swaggerInput).then(() => {
return this.createDeployment(apiId, stage);
});
});
});
}
Expand Down

0 comments on commit 12526c8

Please sign in to comment.