Skip to content
Open
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
24 changes: 24 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const BbPromise = require('bluebird');
const fs = require('fs');
const validate = require('serverless/lib/plugins/aws/lib/validate');
const encrypt = require('./lib/encrypt');
const decrypt = require('./lib/decrypt');
Expand Down Expand Up @@ -90,6 +91,29 @@ class Crypt {
.then(this.validate)
.then(this.decrypt),
};

const delegate = serverless.variables.getValueFromSource.bind(serverless.variables);
serverless.variables.getValueFromSource = async (variableString) => {
if (variableString.startsWith(`decrypt:`)) {
const variableName = variableString.split(':')[1];
const secrets = JSON.parse(fs.readFileSync(this.secret_file, 'utf8'));

const params = {
CiphertextBlob: new Buffer(secrets[variableName], 'base64'),
};

return await this.provider.request(
'KMS',
'decrypt',
params,
this.options.stage, this.options.region
).then((ret) => {
return ret.Plaintext.toString('utf-8');
});
}

return delegate(variableString);
}
}
}

Expand Down