* add command to fix templates * replaceAll and lint fixes * fixed menu * fix lint command and run it * add basic error handling for listing of templates * CR suggestions --------- Co-authored-by: Arwid Thornström <arwidt@gmail.com>
92 lines
2.5 KiB
TypeScript
92 lines
2.5 KiB
TypeScript
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
|
import chalk = require('chalk');
|
|
import { defaultMenuSettings, sleep } from '../../../globals';
|
|
const { AutoComplete } = require('enquirer');
|
|
|
|
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();
|
|
}
|
|
|
|
let parameterName = '';
|
|
while (parameterName !== 'exit') {
|
|
const prompt = new AutoComplete({
|
|
name: 'parameterNames',
|
|
message: 'Choose a parameter (esc to exit)',
|
|
limit: 30,
|
|
initial: 10,
|
|
choices: valueNames,
|
|
});
|
|
|
|
try {
|
|
const parameterName = await prompt.run();
|
|
const parameterValue = JSON.parse(
|
|
strings.trim(
|
|
await system.run(
|
|
`aws ssm get-parameter --name ${parameterName} --with-decryption`
|
|
)
|
|
)
|
|
);
|
|
print.success(
|
|
`${chalk.green(parameterName)} value is [${chalk.yellow(
|
|
parameterValue.Parameter.Value
|
|
)}]`
|
|
);
|
|
} catch (e) {
|
|
parameterName = 'exit';
|
|
}
|
|
}
|
|
|
|
if (toolbox.fromMenu()) {
|
|
await toolbox.menu.showMenu('aws', defaultMenuSettings);
|
|
}
|
|
},
|
|
};
|