Skip to content

Commit

Permalink
Merge pull request #19 from opentorc/staging
Browse files Browse the repository at this point in the history
Apr 11th: Production <- Staging
  • Loading branch information
lbelling authored Apr 12, 2024
2 parents 170d791 + c87a020 commit 6b55a31
Show file tree
Hide file tree
Showing 9 changed files with 9,394 additions and 1,191 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/code-backup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Mirror repo to S3
on:
push:
branches:
- master
jobs:
s3Backup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: S3 Backup
uses: peter-evans/s3-backup@v1
env:
ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_GITHUB_ACTION_CODE_BACKUP }}
MIRROR_TARGET: ${{ secrets.AWS_S3_TARGET_GITHUB_ACTION_CODE_BACKUP }}
SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY_GITHUB_ACTION_CODE_BACKUP }}
with:
args: --overwrite --remove
4 changes: 2 additions & 2 deletions .github/workflows/update-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Automatic GitHub Release
uses: justincy/[email protected]
id: release
- uses: actions/setup-node@v1
- uses: actions/setup-node@v4
if: steps.release.outputs.released == 'true'
with:
registry-url: 'https://npm.pkg.github.com'
Expand Down
10,330 changes: 9,253 additions & 1,077 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentorc/config-wrapper",
"version": "1.2.3",
"version": "1.3.0",
"description": "config management wrapper",
"main": "./src/index.js",
"bin": {
Expand All @@ -14,20 +14,23 @@
"license": "ISC",
"dependencies": {
"arg": "^5.0.1",
"aws-sdk": "^2.1035.0",
"chalk": "^4.1.2",
"inquirer": "^8.2.0",
"line-reader": "^0.4.0"
},
"devDependencies": {
"chai": "^4.3.4",
"mocha": "^9.1.3"
"mocha": "^9.1.3",
"standard": "^17.1.0"
},
"engineStrict": true,
"engines": {
"node": ">=v16.3.0"
},
"publishConfig": {
"@opentorc:registry": "https://npm.pkg.github.com"
},
"peerDependencies": {
"@aws-sdk/client-ssm": "^3.552.0"
}
}
67 changes: 32 additions & 35 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ const arg = require('arg')
const inquirer = require('inquirer')
const chalk = require('chalk')

let pkg = require('../package.json');
const configWrapper = require('./index');
const { mkdir } = require('fs');
const pkg = require('../package.json')
const configWrapper = require('./index')


function parseArgumentsIntoOptions(rawArgs) {
function parseArgumentsIntoOptions (rawArgs) {
const args = arg({
'--outfile': String,
'--infile': String,
Expand All @@ -26,11 +24,10 @@ function parseArgumentsIntoOptions(rawArgs) {
'-f': '--folder',
'-s': '--service',
'-h': '--help'
},{
}, {
argv: rawArgs.slice(2),
permissive: true
}
)
})

return {
outfile: args['--outfile'] || '',
Expand All @@ -47,12 +44,12 @@ function parseArgumentsIntoOptions(rawArgs) {
}
}

function displayHelp() {
function displayHelp () {
console.log(chalk.green.bgRed.bold('HJAAALP!'))
/*
{underline.green loadParamsIntoEnv:} load up parameters into the current process environment as env vars
{bold.blue * --source:} aws || filename (default: aws)
*/
/*
{underline.green loadParamsIntoEnv:} load up parameters into the current process environment as env vars
{bold.blue * --source:} aws || filename (default: aws)
*/
console.log(chalk`
{bold.red COMMANDS:}
{underline.green remapKeysInEnv:} take {italic.red existing env vars} and remap them to {italic.red new env vars}. ie: {italic.blue DEV_AWS_ACCESS_KEY_ID} -> {italic.blue AWS_ACCESS_KEY_ID}
Expand All @@ -75,15 +72,15 @@ function displayHelp() {
`)
}

async function remapKeysInEnv(config) {
async function remapKeysInEnv (config) {
console.log(chalk.green('Remapping keys in env'))
const params = configWrapper.envLoader.remapKeysInEnv(config.oldprefix, config.newprefix)
console.log(chalk.green(`Saving ${params.length} parameters to ${config.outfile}`))
configWrapper.envLoader.paramsToSourceFile(params, config.outfile)
console.log(chalk.green(`Saved ${params.length} parameters to ${config.outfile}`))
}

async function saveParamsFile(config) {
async function saveParamsFile (config) {
console.log(chalk.green('Saving params file'))
const path = configWrapper.awsManager.constructParamPath(config.env, config.service)
console.log(chalk.green(`saving '${path}' out to ${config.outfile}`))
Expand All @@ -103,7 +100,7 @@ async function saveParamsFile(config) {
}
}

async function putToAWSFromFile(config) {
async function putToAWSFromFile (config) {
const { infile, env, service, overwrite, encrypt } = config
console.log(chalk.green(`Reading params from file: ${infile}`))
const params = await configWrapper.envLoader.readEnvFile(infile)
Expand All @@ -115,7 +112,7 @@ async function putToAWSFromFile(config) {
const results = await configWrapper.awsManager.setParametersByService(params, env, service)
console.log(chalk.green(`Saved ${results.length} parameters to AWS for "/torc/${env}/${service}"`))
}
async function exportAllParams(config) {
async function exportAllParams (config) {
// console.log(config)
const rootFolder = config?.folder || './params'
await fs.mkdir(rootFolder, { recursive: true })
Expand All @@ -141,7 +138,7 @@ async function exportAllParams(config) {
await fs.mkdir(`${rootFolder}/${env}`)
const services = Object.keys(params[env])

for (let j = 0; j < services.length; ++j) {
for (let j = 0; j < services.length; ++j) {
const service = services[j]
const aEnvVars = []
const vars = Object.keys(params[env][service])
Expand All @@ -156,9 +153,9 @@ async function exportAllParams(config) {
await fs.writeFile(`${rootFolder}/${env}/${service}.env`, aEnvVars.join('\n'))
}
}
}
}

async function promptForMissingOptions(options) {
async function promptForMissingOptions (options) {
let commandFunc = null

const questions = []
Expand All @@ -172,7 +169,7 @@ async function promptForMissingOptions(options) {
type: 'input',
name: 'outfile',
message: 'Output file: ',
default: '.env',
default: '.env'
})
}

Expand All @@ -181,16 +178,16 @@ async function promptForMissingOptions(options) {
type: 'input',
name: 'oldprefix',
message: 'Prefix to replace: ',
default: 'DEV_',
default: 'DEV_'
})
}

if (!options.newprefix) {
questions.push({
type: 'input',
name: 'newprefix',
message: 'Replacing previx (can be blank): ',
default: '',
message: 'Replacing prefix (can be blank): ',
default: ''
})
}
break
Expand All @@ -202,16 +199,16 @@ async function promptForMissingOptions(options) {
type: 'input',
name: 'outfile',
message: 'Output file: ',
default: '.env',
default: '.env'
})
}

if (!options.env) {
questions.push({
type: 'input',
name: 'env',
message: 'Environment: ',
default: 'dev',
default: 'dev'
})
}

Expand All @@ -220,7 +217,7 @@ async function promptForMissingOptions(options) {
type: 'input',
name: 'service',
message: 'Service: ',
default: '',
default: ''
})
}
break
Expand All @@ -232,7 +229,7 @@ async function promptForMissingOptions(options) {
type: 'input',
name: 'infile',
message: 'Input file: ',
default: '.env',
default: '.env'
})
}

Expand All @@ -241,7 +238,7 @@ async function promptForMissingOptions(options) {
type: 'input',
name: 'env',
message: 'Environment: ',
default: 'dev',
default: 'dev'
})
}

Expand All @@ -250,7 +247,7 @@ async function promptForMissingOptions(options) {
type: 'input',
name: 'service',
message: 'Service: ',
default: '',
default: ''
})
}
break
Expand All @@ -262,7 +259,7 @@ async function promptForMissingOptions(options) {
type: 'input',
name: 'folder',
message: 'Folder: ',
default: './params',
default: './params'
})
}
break
Expand All @@ -284,10 +281,10 @@ async function promptForMissingOptions(options) {
service: options.service || answers.service,
env: options.env || answers.env,
commandFunc
};
}
}

async function cli(args) {
async function cli (args) {
console.log(chalk.green(`\n${pkg.name} v${pkg.version}`))
let options = parseArgumentsIntoOptions(args)
options = await promptForMissingOptions(options)
Expand All @@ -299,4 +296,4 @@ async function cli(args) {

module.exports = {
cli
}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ const awsManager = require('./lib/awsManager')
module.exports = {
envLoader,
awsManager
}
}
Loading

0 comments on commit 6b55a31

Please sign in to comment.