dotenvi
Advanced tools
Comparing version 0.0.6 to 0.1.0
@@ -9,2 +9,3 @@ #! /usr/bin/env node | ||
const resolvers_1 = require("./resolvers"); | ||
const utils_1 = require("./utils"); | ||
const parser = new argparse_1.ArgumentParser(); | ||
@@ -16,13 +17,6 @@ parser.addArgument(['-s', '--stage'], { | ||
const args = parser.parseArgs(); | ||
function writeFile(document) { | ||
let output = ''; | ||
const variables = Object.keys(document); | ||
for (const variable of variables) { | ||
output += `${variable}=${document[variable]}\n`; | ||
} | ||
fs.writeFileSync('.env', output); | ||
} | ||
let document; | ||
try { | ||
// TODO Load external resolvers | ||
let document = yaml.safeLoad(fs.readFileSync('./env.yml', 'utf8')); | ||
document = yaml.safeLoad(fs.readFileSync('./env.yml', 'utf8')); | ||
if (args.stage) { | ||
@@ -34,11 +28,19 @@ document = document[args.stage]; | ||
} | ||
const rewriter = new rewriter_1.Rewriter(resolvers_1.resolvers); | ||
rewriter.rewrite(document).then(result => { | ||
console.info(`Writing .env file to ${process.cwd()}/.env`); | ||
writeFile(result); | ||
}); | ||
const errors = utils_1.validateDocument(document); | ||
if (errors.length) { | ||
throw new Error(`Validation errors found while loading document. Did you forget to specify -s?: \n${errors.join("\n")}`); | ||
} | ||
} | ||
catch (e) { | ||
console.error(`Could not load yaml ${e}`); | ||
catch (error) { | ||
console.error(`Could not load yaml ${error.stack}`); | ||
process.exit(1); | ||
} | ||
const rewriter = new rewriter_1.Rewriter(resolvers_1.resolvers); | ||
rewriter.rewrite(document).then(result => { | ||
console.info(`Writing .env file to ${process.cwd()}/.env`); | ||
utils_1.writeFile(result); | ||
}).catch((error) => { | ||
console.error(`Could not write .env file: ${error.stack}`); | ||
process.exit(1); | ||
}); | ||
//# sourceMappingURL=index.js.map |
@@ -13,2 +13,4 @@ "use strict"; | ||
const aws_sdk_1 = require("aws-sdk"); | ||
const util_1 = require("util"); | ||
const Credstash = require('nodecredstash'); | ||
exports.resolvers = { | ||
@@ -43,4 +45,12 @@ cft: (argument) => __awaiter(this, void 0, void 0, function* () { | ||
return argument; | ||
}), | ||
cred: (argument) => __awaiter(this, void 0, void 0, function* () { | ||
const credstash = new Credstash({ awsOpts: { region: 'us-east-1' } }); | ||
const promisified = util_1.promisify(credstash.getSecret); | ||
return promisified({ name: argument }) | ||
.catch((error) => { | ||
throw new Error(`Could not load value ${argument} from credstash: ${error.stack}`); | ||
}); | ||
}) | ||
}; | ||
//# sourceMappingURL=resolvers.js.map |
{ | ||
"name": "dotenvi", | ||
"version": "0.0.6", | ||
"version": "0.1.0", | ||
"author": "Ben Ross", | ||
@@ -41,2 +41,3 @@ "license": "MIT", | ||
"js-yaml": "^3.11.0", | ||
"nodecredstash": "^2.0.2", | ||
"ts-jest": "^22.4.4", | ||
@@ -43,0 +44,0 @@ "typescript": "^2.8.1" |
@@ -30,2 +30,3 @@ # dotenvi | ||
SOME_ENV_VARIABLE: ${env:SOME_ENV_VARIABLE} ## Reference to an external environment variable | ||
SOME_CREDSTASH_VARIABLE: ${cred:SOME_CREDSTASH_VARIABLE} ## Reference to a credstash key | ||
SOME_CONSTANT: SOME_CONSTANT | ||
@@ -40,4 +41,4 @@ | ||
production: | ||
<<: *default_env | ||
SOME_CONSTANT: OVERRIDE_FOR_PRODUCTION | ||
<<: *default_env | ||
``` | ||
@@ -50,2 +51,7 @@ | ||
## Configuration | ||
Note that any AWS references (cred, cft, etc...) are currently hard-coded to us-east-1. | ||
## Discussion | ||
@@ -52,0 +58,0 @@ |
@@ -10,2 +10,3 @@ #! /usr/bin/env node | ||
import { resolvers } from './resolvers'; | ||
import { validateDocument, writeFile } from './utils'; | ||
@@ -19,15 +20,7 @@ const parser = new ArgumentParser(); | ||
function writeFile(document: { [name: string]: string }) { | ||
let output = ''; | ||
const variables = Object.keys(document); | ||
for (const variable of variables) { | ||
output += `${variable}=${document[variable]}\n`; | ||
} | ||
fs.writeFileSync('.env', output); | ||
} | ||
let document; | ||
try { | ||
// TODO Load external resolvers | ||
let document = yaml.safeLoad(fs.readFileSync('./env.yml', 'utf8')) as Document; | ||
document = yaml.safeLoad(fs.readFileSync('./env.yml', 'utf8')) as Document; | ||
if (args.stage) { | ||
@@ -39,9 +32,18 @@ document = (document as any)[args.stage]; | ||
} | ||
const rewriter = new Rewriter(resolvers); | ||
rewriter.rewrite(document).then(result => { | ||
console.info(`Writing .env file to ${process.cwd()}/.env`); | ||
writeFile(result); | ||
}); | ||
} catch (e) { | ||
console.error(`Could not load yaml ${e}`); | ||
const errors = validateDocument(document); | ||
if (errors.length) { | ||
throw new Error(`Validation errors found while loading document. Did you forget to specify -s?: \n${errors.join("\n")}`); | ||
} | ||
} catch (error) { | ||
console.error(`Could not load yaml ${error.stack}`); | ||
process.exit(1); | ||
} | ||
const rewriter = new Rewriter(resolvers); | ||
rewriter.rewrite(document).then(result => { | ||
console.info(`Writing .env file to ${process.cwd()}/.env`); | ||
writeFile(result); | ||
}).catch((error: Error) => { | ||
console.error(`Could not write .env file: ${error.stack}`); | ||
process.exit(1); | ||
}); |
import * as AWS from 'aws-sdk'; | ||
import { CloudFormation, Config } from 'aws-sdk'; | ||
import { DescribeStacksOutput } from 'aws-sdk/clients/cloudformation'; | ||
import { promisify } from 'util'; | ||
import { ResolverMap } from './types'; | ||
const Credstash = require('nodecredstash'); | ||
export const resolvers: ResolverMap = { | ||
cft: async (argument: string) => { | ||
if (!AWS.config.region) { | ||
@@ -40,3 +43,11 @@ AWS.config.update({ region: 'us-east-1' }); | ||
return argument; | ||
}, | ||
cred: async (argument: string) => { | ||
const credstash = new Credstash({ awsOpts: { region: 'us-east-1' } }); | ||
const promisified = promisify(credstash.getSecret); | ||
return promisified({ name: argument }) | ||
.catch((error: Error) => { | ||
throw new Error(`Could not load value ${argument} from credstash: ${error.stack}`); | ||
}); | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
261474
27
408
74
11
4
+ Addednodecredstash@^2.0.2
+ Addedaes-js@3.1.2(transitive)
+ Addedaws-sdk@2.1621.0(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@4.9.2(transitive)
+ Addedevents@1.1.1(transitive)
+ Addedieee754@1.1.13(transitive)
+ Addedis-arguments@1.1.1(transitive)
+ Addedis-generator-function@1.0.10(transitive)
+ Addedjmespath@0.16.0(transitive)
+ Addednodecredstash@2.0.2(transitive)
+ Addedpunycode@1.3.2(transitive)
+ Addedquerystring@0.2.0(transitive)
+ Addedsax@1.2.1(transitive)
+ Addedurl@0.10.3(transitive)
+ Addedutil@0.12.5(transitive)
+ Addeduuid@8.0.0(transitive)
+ Addedxml2js@0.6.2(transitive)
+ Addedxmlbuilder@11.0.1(transitive)