From 25e5957907a3eeb00df209281c14b80bbfaa260e Mon Sep 17 00:00:00 2001 From: xkcm <42122011+xkcm@users.noreply.github.com> Date: Wed, 24 May 2023 16:11:25 +0200 Subject: [PATCH 1/5] [KP-1165] Support 'allowEmptyResult' configuration field (#46) --- core.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core.js b/core.js index f29f639..ad2ed4a 100644 --- a/core.js +++ b/core.js @@ -10,6 +10,7 @@ function generatePluginMethod(method) { const methodDefinition = loadMethodFromConfiguration(action.method.name); const parameters = await helpers.readActionArguments(action, settings, methodDefinition); + const allowEmptyResult = methodDefinition.allowEmptyResult ?? false; const shouldRedactSecrets = methodDefinition.redactSecrets ?? consts.DEFAULT_REDACT_SECRETS; const secrets = shouldRedactSecrets && Object.values(await redaction.getVaultedParameters(parameters, methodDefinition)); @@ -25,7 +26,7 @@ function generatePluginMethod(method) { throw shouldRedactSecrets ? redaction.redactSecrets(error, secrets) : error; } - if (_.isNil(result) || _.isEmpty(result)) { + if (!allowEmptyResult && (_.isNil(result) || _.isEmpty(result))) { return consts.OPERATION_FINISHED_SUCCESSFULLY_MESSAGE; } From ac37fc3e3099f7e1c7ae7e1886dfbb1604968988 Mon Sep 17 00:00:00 2001 From: xkcm <42122011+xkcm@users.noreply.github.com> Date: Mon, 29 May 2023 18:20:21 +0200 Subject: [PATCH 2/5] KP-1153 (Fix secrets redaction) (#47) * Fix secrets redaction * Fix bug * Retrigger CI --- core.js | 18 +++++++++++++++--- secrets-redaction.js | 6 +++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/core.js b/core.js index ad2ed4a..1a2ce65 100644 --- a/core.js +++ b/core.js @@ -1,19 +1,31 @@ const _ = require("lodash"); + const consts = require("./consts.json"); const helpers = require("./helpers"); const redaction = require("./secrets-redaction"); const autocomplete = require("./autocomplete"); -const { loadMethodFromConfiguration } = require("./config-loader"); +const { + loadMethodFromConfiguration, + loadConfiguration, +} = require("./config-loader"); function generatePluginMethod(method) { return async (action, settings) => { const methodDefinition = loadMethodFromConfiguration(action.method.name); + const pluginDefinition = loadConfiguration(); const parameters = await helpers.readActionArguments(action, settings, methodDefinition); const allowEmptyResult = methodDefinition.allowEmptyResult ?? false; const shouldRedactSecrets = methodDefinition.redactSecrets ?? consts.DEFAULT_REDACT_SECRETS; - const secrets = shouldRedactSecrets - && Object.values(await redaction.getVaultedParameters(parameters, methodDefinition)); + const secrets = []; + if (shouldRedactSecrets) { + const paramsDefinition = [ + ...(methodDefinition.params ?? []), + ...(pluginDefinition.auth?.params ?? []), + ]; + const secretsObject = redaction.filterVaultedParameters(parameters, paramsDefinition); + secrets.push(...Object.values(secretsObject)); + } const utils = { logger: shouldRedactSecrets ? redaction.createRedactedLogger(secrets) : console, diff --git a/secrets-redaction.js b/secrets-redaction.js index fe4ede4..d945d8c 100644 --- a/secrets-redaction.js +++ b/secrets-redaction.js @@ -81,8 +81,8 @@ function redactSecretsInPlainObject(input, secrets) { ); } -async function getVaultedParameters(params, methodDefinition) { - const vaultParams = Object.entries(params).filter(([paramName]) => methodDefinition.params.some( +function filterVaultedParameters(params, paramsDefinition) { + const vaultParams = Object.entries(params).filter(([paramName]) => paramsDefinition.some( (paramDefinition) => paramDefinition.type === "vault" && paramDefinition.name === paramName, )); return Object.fromEntries(vaultParams); @@ -93,7 +93,7 @@ function escapeRegExp(string) { } module.exports = { - getVaultedParameters, + filterVaultedParameters, redactSecrets, createRedactedLogger, }; From dac4347c41d4f50745492e977ac9c10d0df607a2 Mon Sep 17 00:00:00 2001 From: xkcm <42122011+xkcm@users.noreply.github.com> Date: Wed, 7 Jun 2023 00:34:33 +0200 Subject: [PATCH 3/5] KP-1191 (Remove using default values from settings/config) (#51) --- core.js | 14 +++++++++++--- helpers.js | 21 +++++++++------------ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/core.js b/core.js index 1a2ce65..4e6a764 100644 --- a/core.js +++ b/core.js @@ -13,7 +13,10 @@ function generatePluginMethod(method) { return async (action, settings) => { const methodDefinition = loadMethodFromConfiguration(action.method.name); const pluginDefinition = loadConfiguration(); - const parameters = await helpers.readActionArguments(action, settings, methodDefinition); + const { + params, + settings: parsedSettings, + } = await helpers.readActionArguments(action, settings, methodDefinition); const allowEmptyResult = methodDefinition.allowEmptyResult ?? false; const shouldRedactSecrets = methodDefinition.redactSecrets ?? consts.DEFAULT_REDACT_SECRETS; @@ -23,7 +26,7 @@ function generatePluginMethod(method) { ...(methodDefinition.params ?? []), ...(pluginDefinition.auth?.params ?? []), ]; - const secretsObject = redaction.filterVaultedParameters(parameters, paramsDefinition); + const secretsObject = redaction.filterVaultedParameters(params, paramsDefinition); secrets.push(...Object.values(secretsObject)); } @@ -33,7 +36,12 @@ function generatePluginMethod(method) { let result; try { - result = await method(parameters, { action, settings, utils }); + result = await method(params, { + action, + settings, + utils, + parsedSettings, + }); } catch (error) { throw shouldRedactSecrets ? redaction.redactSecrets(error, secrets) : error; } diff --git a/helpers.js b/helpers.js index c131aca..325d293 100644 --- a/helpers.js +++ b/helpers.js @@ -31,7 +31,7 @@ async function readActionArguments( throw new Error(`Could not find a method "${action.method.name}" in config.json`); } - const settingsParamsDefinition = loadConfiguration()?.settings ?? []; + const settingsParamsDefinition = loadConfiguration().settings ?? []; const settingsParsingPromises = settingsParamsDefinition.map(async (settingDefinition) => { settingsValues[settingDefinition.name] = await parseParameter( settingDefinition, @@ -52,7 +52,6 @@ async function readActionArguments( paramValues[paramDefinition.name] = await parseParameter( paramDefinition, paramValues[paramDefinition.name], - settingsValues[paramDefinition.name], ); const { validationType } = paramDefinition; @@ -70,7 +69,6 @@ async function readActionArguments( paramValues[paramDefinition.name] = await parseParameter( paramDefinition, paramValues[paramDefinition.name], - settingsValues[paramDefinition.name], ); const { validationType } = paramDefinition; @@ -84,10 +82,10 @@ async function readActionArguments( await Promise.all(accountParsingPromises); } - return removeUndefinedAndEmpty({ - ...settingsValues, - ...paramValues, - }); + return { + params: removeUndefinedAndEmpty(paramValues), + settings: removeUndefinedAndEmpty(settingsValues), + }; } async function temporaryFileSentinel(fileDataArray, functionToWatch) { @@ -171,18 +169,17 @@ function removeUndefinedAndEmpty(object) { return _.omitBy(object, (value) => value === "" || _.isNil(value) || (_.isObjectLike(value) && _.isEmpty(value))); } -function parseParameter(paramDefinition, paramValue, settingsValue) { - const valueToParse = paramValue ?? settingsValue ?? paramDefinition.default; - if (_.isNil(valueToParse)) { +function parseParameter(paramDefinition, paramValue) { + if (_.isNil(paramValue)) { if (paramDefinition.required) { throw Error(`Missing required "${paramDefinition.name}" value`); } - return valueToParse; + return paramValue; } const { parserOptions } = paramDefinition; const parserToUse = paramDefinition.parserType || paramDefinition.type; - return parsers.resolveParser(parserToUse)(valueToParse, parserOptions); + return parsers.resolveParser(parserToUse)(paramValue, parserOptions); } function validateParamValue( From 4e34dcf0307b271f186ac4f1e75ba4f939b430a3 Mon Sep 17 00:00:00 2001 From: xkcm Date: Mon, 29 May 2023 18:28:06 +0200 Subject: [PATCH 4/5] Version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 07cd51d..064c454 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kaholo/plugin-library", - "version": "2.2.1", + "version": "2.3.0", "description": "Kaholo library for plugins", "main": "kaholo-plugin-library.js", "scripts": { From c3ebfbca7135fd88f2a0438476872d9e56a431c2 Mon Sep 17 00:00:00 2001 From: xkcm Date: Wed, 7 Jun 2023 00:45:15 +0200 Subject: [PATCH 5/5] Update package-lock.json --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index c5251c9..6346d55 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kaholo/plugin-library", - "version": "2.1.2", + "version": "2.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@kaholo/plugin-library", - "version": "2.1.2", + "version": "2.3.0", "license": "ISC", "dependencies": { "fast-password-entropy": "^1.1.1",