Skip to content

Instantly share code, notes, and snippets.

@amitaibu
Last active August 29, 2015 14:21
Show Gist options
  • Save amitaibu/250762259b30fe404f88 to your computer and use it in GitHub Desktop.
Save amitaibu/250762259b30fe404f88 to your computer and use it in GitHub Desktop.
env:
- secure: "0a89c69f2a2b7679334c"
- secure: "0a89c69f2a2b7679334d"
- foo: "bar"
#!/usr/bin/env node
var Promise = require("bluebird");
var yaml = require('js-yaml');
var fs = Promise.promisifyAll(require("fs"));
var exec = require('child_process').exec;
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'd6F3Efeq';
function encrypt(text){
var cipher = crypto.createCipher(algorithm,password)
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
function decrypt(text){
var decipher = crypto.createDecipher(algorithm,password)
var dec = decipher.update(text,'hex','utf8')
dec += decipher.final('utf8');
return dec;
}
var prepareShFile = function(obj) {
var contents = [
'cd ~/build',
'set -x'
];
contents = contents.concat(json.before_script);
contents = contents.concat(json.script);
return contents.join('\n');
};
fs.readFileAsync('./.shoov.yml')
.then(function (data) {
return yaml.safeLoad(data);
})
.then(function (data) {
var variables = [];
data.env.forEach(function(row) {
var keyName = Object.keys(row)[0];
var variableValue;
if (keyName == 'secure') {
var decryptArr = decrypt(row[keyName]).split(':');
if (decryptArr.length != 2) {
throw new Error('Wrong secure key.');
}
keyName = decryptArr[0];
variableValue = decryptArr[1];
}
else {
var variableValue = row[keyName];
}
// Export value as a bash variable.
variables.push('export ' + keyName + '=' + variableValue);
});
return variables.join('\n');
})
.then(function(data) {
return fs.writeFileAsync('./export.sh', data);
})
.catch(function(err) {
console.log(err);
});
{
"dependencies": {
"bluebird": "^2.9.26",
"crypto": "0.0.3",
"js-yaml": "^3.3.1",
"request-promise": "^0.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment