Skip to content
Merged
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
168 changes: 166 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
"got": "^14.6.2",
"http-proxy-agent": "^7.0.2",
"https-proxy-agent": "^7.0.6",
"inquirer": "^8.2.4",
"jose": "^6.1.0",
"js-yaml": "^4.1.0",
"keytar": "7.9.0",
"lodash": "^4.17.21",
"node-cache": "^5.1.2",
Expand Down
109 changes: 109 additions & 0 deletions src/commands/engage/apply.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import Command from '../../lib/command.js';
import { Flags } from '@oclif/core';
import { commonFlags } from '../../lib/engage/flags.js';
import logger, { highlight } from '../../lib/logger.js';
import { OutputTypes, LanguageTypes, ApiServerClientApplyResult, GenericResource, YesNo, YesNoChoices } from '../../lib/types.js';
import { loadAndVerifySpecs, verifyFile } from '../../lib/utils/utils.js';
import Renderer from '../../lib/results/renderer.js';
import { ApiServerClient } from '../../lib/clients-external/apiserverclient.js';
import { DefinitionsManager } from '../../lib/results/DefinitionsManager.js';
import { askList } from '../../lib/utils/basic-prompts.js';
import chalk from 'chalk';

export default class EngageApply extends Command {
static override summary = 'Update resources from a file.';

static override aliases = [ 'central:apply' ];

static override description = `You must be authenticated to update one or more resources.
Run ${highlight('"axway auth login"')} to authenticate.`;

static override examples = [
{
description: 'Update a resource from a file',
command: '<%= config.bin %> <%= command.id %> <Resource> --file <FilePath>',
},
];

static override flags = {
...commonFlags,
output: Flags.string({
char: 'o',
description: `Additional output formats. One of: ${OutputTypes.yaml} | ${OutputTypes.json}`,
}),
file: Flags.string({
char: 'f',
description: 'Filename to use to create or update the resources. One of: yaml | json',
}),
yes: Flags.boolean({
char: 'y',
description: 'Automatically reply "yes" to any command prompts.',
}),
language: Flags.string({
description: `Language Codes. One of: Comma Separated values of ${LanguageTypes.French} | ${LanguageTypes.US} | ${LanguageTypes.German} | ${LanguageTypes.Portugese}`,
}),
subresource: Flags.string({
description: 'Name of the 1 subresource to update. Will prevent main resource and all other subresources from being updated.',
}),
};

async run(): Promise<any> {
const log = logger('EngageApply');

const { flags, account } = await this.parse(EngageApply);

let isCmdError = false;

// need to verify args here since if "-f" is required
log('verifying args');
if (!flags.file) {
throw new Error('File name is required, please provide -f, --file [path] option');
}

log(`verifying file: ${flags.file}`);
verifyFile(flags.file);

let results: ApiServerClientApplyResult[] = [];
const render = new Renderer(console, flags.output).startSpin('Creating or updating resource(s)');
const client = new ApiServerClient({ account, region: flags.region, useCache: flags.cache });
const defsManager = new DefinitionsManager(client);

log('executing api calls');
try {
await defsManager.init();
log('loading and verifying specs');
const { docs, isMissingName } = await loadAndVerifySpecs(flags.file, defsManager.getAllKindsList());
if (!flags.yes && isMissingName) {
render.stopSpin();
if (
(await askList({
msg: `As your file contains resources with missing logical names, their logical names will be autogenerated. \nRun ${chalk.cyan(
'axway engage apply -f <filepath> -o [yaml|json] -y > <output filepath>'
)} to capture the resource(s) with the autogenerated logical name(s) so you can use them again. \nNOTE: To suppress this prompt in the future, please use the '-y' flag. \nWould you like to continue *without* capturing the resource names in a new file?`,
choices: YesNoChoices,
default: YesNo.Yes,
})) === YesNo.No
) { process.exit(1); }
render.startSpin('Creating or updating resource(s)');
}
const sortedKindsMap = defsManager.getSortedKindsMap();
results = await client.bulkCreateOrUpdate(docs as GenericResource[], sortedKindsMap, flags.language, flags.subresource);
render.bulkCreateOrUpdateResult(results);
isCmdError = results.some((nextResult) => (nextResult.error?.length ?? 0) > 0);
} catch (e: any) {
log('command error', e);
isCmdError = true;
if (results.some((nextResult) => nextResult.data)) {
// Render the results that have completed.
render.bulkCreateOrUpdateResult(results);
}
render.anyError(e);
} finally {
log(`command finished, exit with error = ${isCmdError}`);
render.stopSpin();
if (isCmdError) {
process.exit(1);
}
}
}
}
2 changes: 2 additions & 0 deletions src/commands/engage/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { resolveTeamNames } from '../../lib/results/resultsrenderer.js';
export default class EngageGet extends Command {
static override summary = 'List one or more resources.';

static override aliases = [ 'central:get' ];

static override description = `You must be authenticated to list one or more resources.
Run ${highlight('"axway auth login"')} to authenticate.`;

Expand Down
2 changes: 2 additions & 0 deletions src/commands/engage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { highlight } from '../../lib/logger.js';
export default class EngageCommand extends Command {
static override hidden = true;

static override aliases = [ 'central' ];

static override summary = 'Manage APIs, services and publish to the Amplify Marketplace.';

static override description = `You must be authenticated to manage Engage Operations.
Expand Down
8 changes: 4 additions & 4 deletions src/lib/clients-external/apiserverclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,14 @@ export class ApiServerClient {
resources.map((resource) => {
const resourceDef = sortedDefsArray.find(
(def) =>
def.spec.kind === resource.kind
&& def.spec.scope?.kind === resource.metadata?.scope?.kind,
def.spec?.kind === resource.kind
&& def.spec?.scope?.kind === resource.metadata?.scope?.kind,
);
const scopeDef = resource.metadata?.scope
? sortedDefsArray.find(
(def) =>
def.spec.kind === resource.metadata!.scope!.kind
&& !def.spec.scope,
def.spec?.kind === resource.metadata!.scope!.kind
&& !def.spec?.scope,
)
: undefined;
const scopeName = resource.metadata?.scope?.name;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export const dataService = async ({
// eslint-disable-next-line no-loop-func
limit(async () => {
allPages[thisPageIndex] = await (this as DataServiceMethods).get(
fullUrl,
url,
params
);
pageDownloadCount++;
Expand Down
Loading
Loading