Comparing version 0.0.2 to 0.0.3
@@ -20,7 +20,4 @@ { | ||
"sourceType": "module", | ||
"ecmaVersion": 2017, | ||
"ecmaFeatures": { | ||
"experimentalObjectRestSpread": true | ||
} | ||
"ecmaVersion": 2019 | ||
} | ||
} |
@@ -19,3 +19,2 @@ #!/usr/bin/env node | ||
await envGrabber({ bucketName, fileName }); | ||
console.log('Environment variables file successfully downloaded'); | ||
} catch (error) { | ||
@@ -22,0 +21,0 @@ console.log(error.message); |
28
index.js
'use strict'; | ||
const gcs = require('@google-cloud/storage')(); | ||
const byline = require('byline'); | ||
@@ -15,8 +16,27 @@ /** | ||
function envGrabber({ bucketName, fileName = '.env' }) { | ||
return gcs | ||
.bucket(bucketName) | ||
.file(fileName) | ||
.download({ destination: fileName }); | ||
return new Promise(async resolve => { | ||
const result = []; | ||
const file = await gcs | ||
.bucket(bucketName) | ||
.file(fileName) | ||
.createReadStream(); | ||
const lineStream = byline.createStream(file); | ||
lineStream.on('data', line => { | ||
const [key, value] = line | ||
.toString() | ||
.replace(/"|'/g, '') | ||
.split('='); | ||
result.push(key); | ||
process.env[key] = value; | ||
}); | ||
lineStream.on('end', () => { | ||
console.log( | ||
`The following environment variables were set: ${result.join(', ')}`, | ||
); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
module.exports = envGrabber; |
{ | ||
"name": "envgrabber", | ||
"license": "MIT", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A tool to retrieve .env files from a Google Storage bucket before deployment", | ||
@@ -17,2 +17,3 @@ "devDependencies": { | ||
"@google-cloud/storage": "^1.7.0", | ||
"byline": "^5.0.0", | ||
"yargs": "^11.0.0" | ||
@@ -19,0 +20,0 @@ }, |
<h1 align="center"> envGrabber </h1> | ||
<p align="center"> | ||
<b >A simple script to pull environment variables from a GCP Storage bucket. Designed to work with Google App Engine out of the box</b> | ||
<b >A simple script to pull environment variables from a GCP Storage bucket a sets them in your app. Designed to work with Google App Engine out of the box</b> | ||
</p> | ||
@@ -23,6 +23,9 @@ <br> | ||
await envGrabber({ | ||
bucketName: 'my_super_secret_bucket', | ||
fileName: '.env', // optional, '.env' is assumed. | ||
}); | ||
(async () => { | ||
await envGrabber({ | ||
bucketName: 'my_super_secret_bucket', | ||
fileName: '.env', // optional, '.env' is assumed. | ||
}); | ||
})() | ||
```` |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
99640
89
30
3
1
+ Addedbyline@^5.0.0
+ Addedbyline@5.0.0(transitive)