Merge pull request #5 from Photowall/3-able-to-print-parameter-store-values
added parameter store checkout script
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'
|
||||
import chalk = require('chalk');
|
||||
import { defaultMenuSettings } from '../../../globals';
|
||||
const { AutoComplete } = require('enquirer');
|
||||
|
||||
const sleep = (milliseconds) => {
|
||||
return new Promise(resolve => setTimeout(resolve, milliseconds))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: 'parameterstore',
|
||||
alias: ['ps'],
|
||||
description: 'Parameter store functions (ps)',
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
|
||||
const { system, strings, print, filesystem } = toolbox;
|
||||
|
||||
// Check for cache in /tmp folder
|
||||
const cache = filesystem.read('/tmp/.pwcli_parametercache');
|
||||
const cacheValues = !cache ? [] : JSON.parse(cache);
|
||||
const valueNames = [...cacheValues];
|
||||
|
||||
let nextToken = '';
|
||||
if (valueNames.length === 0) {
|
||||
const spinner = print.spin(`Downloading parameter names (${chalk.red('0')})`);
|
||||
while (nextToken !== null) {
|
||||
const values = JSON.parse(
|
||||
strings.trim(
|
||||
await system.run(`aws ssm describe-parameters --output json --max-items 50 ${(nextToken !== '') ? `--starting-token ${nextToken}` : ''}`)));
|
||||
|
||||
await sleep(500);
|
||||
valueNames.push(...values.Parameters.map(({Name}) => { return Name; }));
|
||||
nextToken = values.NextToken || null;
|
||||
spinner.text = `Downloading parameter names (${chalk.red(valueNames.length)})`
|
||||
}
|
||||
|
||||
spinner.text = 'Saving parameter names to /tmp/.pwcli_parametercache';
|
||||
|
||||
filesystem.file('/tmp/.pwcli_parametercache', {mode: '600', content: JSON.stringify(valueNames)});
|
||||
await sleep(2000);
|
||||
|
||||
spinner.stop();
|
||||
}
|
||||
|
||||
const prompt = new AutoComplete({
|
||||
name: 'parameterNames',
|
||||
message: 'Choose a parameter',
|
||||
limit: 30,
|
||||
initial: valueNames.length - 1,
|
||||
choices: valueNames
|
||||
});
|
||||
|
||||
const parameterName = await prompt.run();
|
||||
console.log(`parameterName`, parameterName);
|
||||
|
||||
const parameterValue = JSON.parse(strings.trim(await system.run(`aws ssm get-parameter --name ${parameterName}`)));
|
||||
print.success(`${chalk.green(parameterName)} value is [${chalk.yellow(parameterValue.Parameter.Value)}]`);
|
||||
|
||||
if (toolbox.fromMenu()) {
|
||||
await toolbox.menu.showMenu('aws', defaultMenuSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user