Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions esvs/variables/esv-connector-timeout-reset-counter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"_id": "esv-connector-timeout-reset-counter",
"description": "",
"expressionType": "string",
"valueBase64": "${ESV_CONNECTOR_TIMEOUT_RESET_COUNTER}"
}
6 changes: 6 additions & 0 deletions esvs/variables/esv-email-welcome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"_id": "esv-email-welcome",
"description": "Welcome email template",
"expressionType": "string",
"valueBase64": "${ESV_EMAIL_WELCOME}"
}
68 changes: 68 additions & 0 deletions src/cli/FrodoCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,18 @@ function cloneArgument(argument: Argument): Argument {
return cloned;
}

/**
* Option that collects repeated values into an array.
*/
export class ListOption extends Option {
constructor(flags: string, description?: string) {
super(flags, description);
this.argParser((value: string, previous: string[]) =>
previous === this.defaultValue ? [value] : [...previous, value]
).default([]);
}
}

export const hostArgument = new Argument(
'[host]',
'AM base URL, e.g.: https://cdk.iam.example.com/am. To use a connection profile, just specify a unique substring or alias.'
Expand Down Expand Up @@ -523,6 +535,22 @@ const directoryOption = withHelpGroup(
RUNTIME_OPTIONS_HEADING
);

const envOption = withHelpGroup(
new ListOption(
'-E, --env <key=value>',
'Set an environment variable for placeholder resolution. Omit the value to pass through the host environment variable of the same name. May be specified multiple times. Overrides values from --env-file.'
),
RUNTIME_OPTIONS_HEADING
);

const envFileOption = withHelpGroup(
new ListOption(
'-F, --env-file <file>',
'Read environment variables from a file for placeholder resolution. May be specified multiple times; later files override earlier ones.'
),
RUNTIME_OPTIONS_HEADING
);

const insecureOption = withHelpGroup(
new Option(
'-k, --insecure',
Expand Down Expand Up @@ -631,6 +659,8 @@ const defaultOpts = [
flushCacheOption,
retryOption,
useRealmPrefixOnManagedObjects,
envOption,
envFileOption,
];

/**
Expand Down Expand Up @@ -715,6 +745,44 @@ const stateMap = {
[retryOption.attributeName()]: (strategy: RetryStrategy) => {
state.setAxiosRetryStrategy(strategy);
},
[envFileOption.attributeName()]: (
files: string[],
options: Record<string, unknown>
) => {
const merged: Record<string, string> = {};

for (const filePath of files) {
let content: string;
try {
content = fs.readFileSync(filePath, 'utf8');
} catch (error) {
throw new FrodoError(`Error reading env file ${filePath}`, error);
}
for (const line of content.split('\n')) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#')) continue;
const separatorIndex = trimmed.indexOf('=');
if (separatorIndex < 1) {
throw new FrodoError(
`Invalid line in ${filePath}: "${trimmed}", expected key=value`
);
}
merged[trimmed.slice(0, separatorIndex)] = trimmed.slice(
separatorIndex + 1
);
}
}
for (const pair of (options[envOption.attributeName()] as string[]) || []) {
const separatorIndex = pair.indexOf('=');
if (separatorIndex < 1) {
throw new FrodoError(
`Invalid env format: "${pair}", expected key=value`
);
}
merged[pair.slice(0, separatorIndex)] = pair.slice(separatorIndex + 1);
}
state.setEnvValues(merged);
},
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function setup() {
.description('Export all config.')
.addOption(
new Option(
'-F, --config-folder <config-folder-path>',
'-f, --config-folder <config-folder-path>',
'Path to the folder containing the config files.\n'
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { configManagerImportVariables } from '../../../configManagerOps/FrConfigVariableOps';
import { getTokens } from '../../../ops/AuthenticateOps';
import { printMessage, verboseMessage } from '../../../utils/Console';
import { FrodoCommand } from '../../FrodoCommand';

const { CLOUD_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;

const deploymentTypes = [CLOUD_DEPLOYMENT_TYPE_KEY];

export default function setup() {
const program = new FrodoCommand(
'frodo config-manager push variables',
[],
deploymentTypes
);
program
.description('Import variables.')
.addOption(
new Option(
'-n, --name <name>',
'Variable name; import only the specified variable. If omitted, all variables are imported.'
)
)

.action(async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
if (await getTokens(false, true, deploymentTypes)) {
verboseMessage('Importing variables');
const outcome = await configManagerImportVariables(
options.name,
options.envValue,
options.envVarFile
);
if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
else {
printMessage(
'Unrecognized combination of options or no options...',
'error'
);
program.help();
process.exitCode = 1;
}
});
return program;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import ServiceObjects from './config-manager-push-service-objects';
import TermsAndConditions from './config-manager-push-terms-and-conditions';
import Themes from './config-manager-push-themes';
import UiConfig from './config-manager-push-ui-config';
import Variables from './config-manager-push-variables';

export default function setup() {
const program = new FrodoStubCommand('push').description(
Expand Down Expand Up @@ -53,7 +54,8 @@ export default function setup() {
program.addCommand(RemoteServers().name('remote-servers'));
program.addCommand(SecretMappings().name('secret-mappings'));
program.addCommand(CustomNodes().name('custom-nodes'));

program.addCommand(CSP().name('csp'));
program.addCommand(Variables().name('variables'));

return program;
}
9 changes: 1 addition & 8 deletions src/cli/idm/idm-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,10 @@ export default function setup() {
)
.addOption(
new Option(
'-E, --entities-file [entities-file]',
'-e, --entities-file [entities-file]',
'Name of the entity file. Ignored with -i.'
)
)
.addOption(new Option('-e, --env-file [envfile]', 'Name of the env file.'))
.addOption(
new Option(
'-a, --all',
'Export all IDM configuration objects into a single file in directory -D. Ignored with -i.'
)
)
.addOption(
new Option(
'-A, --all-separate',
Expand Down
9 changes: 1 addition & 8 deletions src/cli/idm/idm-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,10 @@ export default function setup() {
.addOption(new Option('-f, --file [file]', 'Import file. Ignored with -A.'))
.addOption(
new Option(
'-E, --entities-file [entities-file]',
'-e, --entities-file [entities-file]',
'Name of the entity file. Ignored with -i.'
)
)
.addOption(new Option('-e, --env-file [envfile]', 'Name of the env file.'))
.addOption(
new Option(
'-a, --all',
'Import all IDM configuration objects from a single file in directory -D. Ignored with -i.'
)
)
.addOption(
new Option(
'-A, --all-separate',
Expand Down
7 changes: 0 additions & 7 deletions src/cli/idm/idm-schema-object-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ export default function setup() {
'Export file if -x or -a are included. Ignored with -A.'
)
)
.addOption(new Option('-e, --env-file [envfile]', 'Name of the env file.'))
.addOption(
new Option(
'-N, --no-metadata',
'Does not include metadata in the export file.'
)
)
.addOption(
new Option(
'-x, --no-extract',
Expand Down
1 change: 0 additions & 1 deletion src/cli/idm/idm-schema-object-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default function setup() {
program
.description('Import IDM configuration managed objects.')
.addOption(new Option('-f, --file [file]', 'Import file.'))
.addOption(new Option('-e, --env-file [envfile]', 'Name of the env file.'))
.addOption(
new Option(
'-i, --individual-object',
Expand Down
2 changes: 1 addition & 1 deletion src/cli/iga/workflow/iga-workflow-delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function setup() {
)
.addOption(
new Option(
'-F, --force',
'-f, --force',
'Force delete workflow(s), even if they are associated with request types.'
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/journey/journey-describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function setup() {
)
.addOption(
new Option(
'-F, --output-file <file>',
'-O, --output-file <file>',
'Name of the file to write the output to.'
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/promote/promote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function setup() {
)
.addOption(
new Option(
'-E, --frodo-export-dir <directory>',
'-e, --frodo-export-dir <directory>',
'The directory where the frodo export is located.'
)
)
Expand Down
Loading