security fix for parameter store list
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||
import chalk = require('chalk');
|
||||
import { defaultMenuSettings, sleep } from '../../../../globals';
|
||||
import {
|
||||
readParameterNameCache,
|
||||
writeParameterNameCache,
|
||||
} from '../../../../common/parameterstore-cache';
|
||||
const { AutoComplete } = require('enquirer');
|
||||
|
||||
module.exports = {
|
||||
@@ -9,12 +13,9 @@ module.exports = {
|
||||
description: 'List all parameters in parameter store (a ps l)',
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
const { system, strings, print, filesystem } = toolbox;
|
||||
const { system, strings, print } = toolbox;
|
||||
|
||||
// Check for cache in /tmp folder
|
||||
const cache = filesystem.read('/tmp/.pwcli_parametercache');
|
||||
const cacheValues = !cache ? [] : JSON.parse(cache);
|
||||
const valueNames = [...cacheValues];
|
||||
const valueNames = [...readParameterNameCache(toolbox)];
|
||||
|
||||
let nextToken = '';
|
||||
if (valueNames.length === 0) {
|
||||
@@ -45,11 +46,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
spinner.text = 'Saving parameter names to /tmp/.pwcli_parametercache';
|
||||
|
||||
filesystem.file('/tmp/.pwcli_parametercache', {
|
||||
mode: '600',
|
||||
content: JSON.stringify(valueNames),
|
||||
});
|
||||
writeParameterNameCache(toolbox, valueNames);
|
||||
await sleep(2000);
|
||||
|
||||
spinner.stop();
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||
import chalk = require('chalk');
|
||||
import { defaultMenuSettings, sleep } from '../../../../globals';
|
||||
import * as fs from 'fs';
|
||||
import {
|
||||
parameterNameCacheFilePath,
|
||||
readParameterNameCache,
|
||||
} from '../../../../common/parameterstore-cache';
|
||||
const { AutoComplete } = require('enquirer');
|
||||
|
||||
module.exports = {
|
||||
@@ -10,18 +13,13 @@ module.exports = {
|
||||
description: 'Update an existing item in parameter store (a ps u)',
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
const { print, prompt, system, filesystem } = toolbox;
|
||||
const { print, prompt, system } = toolbox;
|
||||
|
||||
// Read the .pwcli_parametercache file
|
||||
const cacheFilePath = '/tmp/.pwcli_parametercache';
|
||||
let parameters = [];
|
||||
if (fs.existsSync(cacheFilePath)) {
|
||||
const cacheContent = await filesystem.read(cacheFilePath);
|
||||
parameters = JSON.parse(cacheContent);
|
||||
} else {
|
||||
const parameters = readParameterNameCache(toolbox);
|
||||
if (parameters.length === 0) {
|
||||
print.error(
|
||||
chalk.red(
|
||||
'Cache file not found. Please run "a ps l" first to populate the cache.',
|
||||
`Parameter name cache is missing or invalid at "${parameterNameCacheFilePath}". Run "a ps l" to populate a name-only cache.`,
|
||||
),
|
||||
);
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||
|
||||
export const parameterNameCacheFilePath = '/tmp/.pwcli_parametercache';
|
||||
|
||||
const isParameterNameList = (value: unknown): value is string[] => {
|
||||
return (
|
||||
Array.isArray(value) && value.every((item) => typeof item === 'string')
|
||||
);
|
||||
};
|
||||
|
||||
export const readParameterNameCache = (
|
||||
toolbox: GluegunMenuToolbox,
|
||||
): string[] => {
|
||||
const { filesystem } = toolbox;
|
||||
const cache = filesystem.read(parameterNameCacheFilePath);
|
||||
|
||||
if (!cache) {
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
const parsedCache = JSON.parse(cache);
|
||||
return isParameterNameList(parsedCache) ? parsedCache : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const writeParameterNameCache = (
|
||||
toolbox: GluegunMenuToolbox,
|
||||
parameterNames: string[],
|
||||
) => {
|
||||
toolbox.filesystem.file(parameterNameCacheFilePath, {
|
||||
mode: '600',
|
||||
content: JSON.stringify(parameterNames),
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user