Skip to content

Commit 8630d89

Browse files
authored
Merge pull request #291 from appcelerator/APIGOV-33064
APIGOV-33064 Query Engage for latest version of agent for creating output of install command
2 parents c1e9790 + 77d4478 commit 8630d89

6 files changed

Lines changed: 106 additions & 172 deletions

File tree

src/lib/engage/clients-external/apiserverclient.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ApiServerVersions,
1111
BasePaths,
1212
CommandLineInterface,
13+
Component,
1314
GenericResource,
1415
GenericResourceWithoutName,
1516
LanguageTypes,
@@ -894,6 +895,21 @@ export class ApiServerClient {
894895
}
895896
}
896897

898+
async getComponentDefinitionsByName(componentName: string, version = ApiServerVersions.v1alpha1): Promise<Component> {
899+
const log = logger('ApiServerClient.getComponentDefinitionsByName');
900+
log.info('get component definitions');
901+
try {
902+
const service = await this.initializeDataService();
903+
const component: Component = await service.get(`/definitions/${version}/components/${componentName}`);
904+
905+
return component;
906+
907+
} catch (e: any) {
908+
log.error('get specs, error: ', e);
909+
throw e;
910+
}
911+
}
912+
897913
async bulkCreate(
898914
resources: Array<GenericResourceWithoutName | GenericResource>,
899915
sortedDefsMap: Map<string, ResourceDefinition>,

src/lib/engage/services/install-service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ const determineRegion = async (region: string | undefined): Promise<string> => {
8989
return configurationRegion ? configurationRegion : Regions.US;
9090
};
9191

92-
async function getAgentVersions(agentInstallFlow: InstallationFlowMethods, installConfig: AgentInstallConfig, account: Account): Promise<void> {
92+
async function getAgentVersions(agentInstallFlow: InstallationFlowMethods, installConfig: AgentInstallConfig, apiServerClient: ApiServerClient): Promise<void> {
9393
if (agentInstallFlow.AgentNameMap && !installConfig.switches.isHostedInstall && installConfig.switches.isDaEnabled) {
9494
installConfig.daVersion = await helpers.getLatestAgentVersion(
95+
apiServerClient,
9596
agentInstallFlow.AgentNameMap[AgentTypes.da] as string,
96-
account
9797
);
9898
}
9999
if (agentInstallFlow.AgentNameMap && !installConfig.switches.isHostedInstall && installConfig.switches.isTaEnabled) {
100100
installConfig.taVersion = await helpers.getLatestAgentVersion(
101+
apiServerClient,
101102
agentInstallFlow.AgentNameMap[AgentTypes.ta] as string,
102-
account
103103
);
104104
}
105105
}
@@ -249,8 +249,8 @@ export async function installAgents(params: InstallAgentsCommandParams): Promise
249249
installConfig.switches.isDockerInstall = installConfig.deploymentType === AgentConfigTypes.DOCKERIZED;
250250
installConfig.switches.isBinaryInstall = installConfig.deploymentType === AgentConfigTypes.BINARIES;
251251

252-
// Get the version of the agents from jfrog, not needed in hosted install
253-
await getAgentVersions(agentInstallFlow, installConfig, params.account);
252+
// Get the version of the agents from Engage, not needed in hosted install
253+
await getAgentVersions(agentInstallFlow, installConfig, apiServerClient);
254254

255255
// if EDGE_GATEWAY or EDGE_GATEWAY_ONLY and isDaEnabled, ask if the organization structure should replicate
256256
if (

src/lib/engage/types.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,49 @@ export interface CommandLineInterface {
153153
};
154154
}
155155

156+
export interface Component {
157+
group: 'definitions',
158+
apiVersion: ApiServerVersions,
159+
kind: 'Component',
160+
name: string,
161+
title: string,
162+
metadata: {
163+
id: string,
164+
audit: {
165+
createTimestamp: string,
166+
modifyTimestamp: string
167+
},
168+
accessRights: {
169+
canChangeOwner: boolean,
170+
canDelete: boolean,
171+
canWrite: boolean,
172+
canRead: boolean
173+
},
174+
resourceVersion: string,
175+
selfLink: string
176+
},
177+
spec: {
178+
type: ComponentType,
179+
latest: ComponentSpecVersionInfo,
180+
retracted: string[],
181+
supported: ComponentSpecVersionInfo[]
182+
}
183+
184+
}
185+
186+
export enum ComponentType {
187+
Agent = 'agent',
188+
DA = 'DiscoveryAgent',
189+
TA = 'TraceabilityAgent',
190+
CA = 'ComplianceAgent'
191+
}
192+
193+
export interface ComponentSpecVersionInfo {
194+
version: string;
195+
releaseDate: string;
196+
endOfSupportDate: string;
197+
}
198+
156199
export interface AuditMetadata {
157200
createTimestamp: string; // '2020-08-04T21:05:32.106Z';
158201
createUserId: string; // '07e6b449-3a31-4a96-8920-e87dd504cb87';
@@ -349,7 +392,6 @@ export enum BasePaths {
349392
V7Agents = '/artifactory/ampc-public-generic-release/v7-agents',
350393
AWSAgents = '/artifactory/ampc-public-generic-release/aws-agents',
351394
DockerAgentPublicRepo = '/agent',
352-
DockerAgentAPIRepoPath = '/artifactory/api/docker/ampc-public-docker-release/v2/agent',
353395
}
354396

355397
export interface ValidatedDocs {
@@ -855,8 +897,7 @@ export const GatewayTypeToDataPlane = {
855897
[GatewayTypes.WSO2]: DataPlaneNames.WSO2,
856898
};
857899

858-
export const PublicRepoUrl = 'https://axway.jfrog.io';
859-
export const PublicDockerRepoBaseUrl = 'axway.jfrog.io/ampc-public-docker-release';
900+
export const PublicDockerRepoBaseUrl = 'repository.axway.com/ampc-public-docker-release';
860901

861902
export class DOSAConfigInfo {
862903
clientId: string | null;

src/lib/engage/utils/agents/flows/awsAgents.ts

Lines changed: 14 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import chalk from 'chalk';
2-
import fs from 'fs';
32
import logger from '../../../../logger.js';
4-
import { dataService } from '../../../../request.js';
5-
import { AgentConfigTypes, AgentInstallConfig, AgentNames, AgentTypes, AWSRegions, BasePaths, BundleType, GatewayTypes, InstallationFlowMethods, PublicDockerRepoBaseUrl, PublicRepoUrl, TrueFalse, YesNo, YesNoChoices } from '../../../types.js';
3+
import { AgentConfigTypes, AgentInstallConfig, AgentNames, AgentTypes, AWSRegions, BasePaths, BundleType, GatewayTypes, InstallationFlowMethods, PublicDockerRepoBaseUrl, TrueFalse, YesNo, YesNoChoices } from '../../../types.js';
64
import { askInput, askList, validateInputLength, validateRegex } from '../../basic-prompts.js';
75
import { isWindows, writeTemplates, writeToFile } from '../../utils.js';
86
import { AWSAgentValues } from '../index.js';
97
import * as helpers from '../index.js';
10-
import { Account } from '../../../../../types.js';
118

129
const debugLog = logger('lib: engage: utils: agents: flows: awsAgents');
1310
const daImage = `${PublicDockerRepoBaseUrl}${BasePaths.DockerAgentPublicRepo}/${AgentNames.AWS_DA}`;
@@ -411,8 +408,6 @@ ${chalk.cyan(
411408
${chalk.cyan(
412409
` aws ssm put-parameter --type SecureString --name ${awsAgentValues.cloudFormationConfig.SSMPublicKeyParameter} --value "file://public_key.pem"`
413410
)}`;
414-
// Cleanup EC2 file
415-
fs.unlinkSync(ConfigFiles.EC2DeployYAML);
416411
break;
417412
}
418413
case DeploymentTypes.OTHER: {
@@ -423,10 +418,6 @@ ${chalk.cyan(
423418
(value) => (s3ResourcesIncludes += `--include "${value}" `)
424419
);
425420

426-
// Cleanup EC2 file
427-
fs.unlinkSync(ConfigFiles.EC2DeployYAML);
428-
// Cleanup ECS Fargate file
429-
fs.unlinkSync(ConfigFiles.FargateDeployYAML);
430421
const info = `To utilize the agents, pull the latest Docker images and run them using the appropriate supplied environment files, (${helpers.configFiles.DA_ENV_VARS} & ${helpers.configFiles.TA_ENV_VARS}):`;
431422

432423
dockerEnvConfig = `Wait for the CloudFormation Stack to complete.
@@ -501,8 +492,6 @@ ${chalk.cyan(
501492
${chalk.cyan(
502493
` aws ssm put-parameter --type SecureString --name ${awsAgentValues.cloudFormationConfig.SSMPublicKeyParameter} --value "file://public_key.pem"`
503494
)}`;
504-
// Cleanup Fargate file
505-
fs.unlinkSync(ConfigFiles.FargateDeployYAML);
506495
break;
507496
}
508497
}
@@ -513,7 +502,13 @@ ${chalk.cyan(
513502
const s3Region = awsAgentValues.region === AWSRegions.US_EAST_1 ? 's3' : `s3.${awsAgentValues.region}`;
514503

515504
return `
516-
To complete the install, run the following AWS CLI command:
505+
To complete the install, first download and extract the CloudFormation templates:
506+
- Download the CloudFormation package:
507+
${chalk.cyan(` curl -O https://repository.axway.com/artifactory/ampc-public-generic-release/aws-agents/aws_apigw_agent_config/latest/${ConfigFiles.AgentConfigZip}`)}
508+
- Extract the package:
509+
${chalk.cyan(` unzip ${ConfigFiles.AgentConfigZip}`)}
510+
511+
Then run the following AWS CLI commands:
517512
- Create, if necessary, and upload all files to your S3 bucket
518513
${chalk.cyan(
519514
` aws s3api create-bucket --bucket ${awsAgentValues.cloudFormationConfig.AgentResourcesBucket} --create-bucket-configuration LocationConstraint=${awsAgentValues.region}`
@@ -537,55 +532,6 @@ ${chalk.gray(`Additional information about agent features can be found here:\n${
537532
`;
538533
};
539534

540-
// Download latest aws apigw config zip
541-
const downloadAPIGWAgentConfigZip = async (account: Account): Promise<string> => {
542-
const url = `${BasePaths.AWSAgents}/aws_apigw_agent_config/latest/${ConfigFiles.AgentConfigZip}`;
543-
544-
const service = await dataService({
545-
account,
546-
baseUrl: PublicRepoUrl,
547-
});
548-
try {
549-
const token = account.auth?.tokens?.access_token;
550-
if (!token) {
551-
throw new Error('Invalid/expired account');
552-
}
553-
const { stream } = await service.download(url);
554-
await helpers.streamPipeline(stream, fs.createWriteStream(ConfigFiles.AgentConfigZip));
555-
return ConfigFiles.AgentConfigZip;
556-
} catch (err: any) {
557-
throw new Error(`Failed to download the agent: ${err.message}`);
558-
}
559-
};
560-
561-
// Unzip latest aws apigw config zip
562-
const unzipAPIGWAgentConfigZip = async (zipFile: string, log: (text: string) => void = () => {}): Promise<boolean> => {
563-
await helpers.unzip(zipFile);
564-
fs.unlinkSync(zipFile);
565-
566-
const isCloudFormation = fs.existsSync(ConfigFiles.DeployAllYAML);
567-
if (!isCloudFormation) {
568-
log(`${ConfigFiles.DeployAllYAML} was not extracted from ${ConfigFiles.AgentConfigZip}`);
569-
return false;
570-
}
571-
return true;
572-
};
573-
574-
export const installPreprocess = async (installConfig: AgentInstallConfig): Promise<AgentInstallConfig> => {
575-
// attempt to download the cloud formation files
576-
installConfig.log(chalk.gray('Downloading the latest Cloud formation template...'));
577-
const account = installConfig.centralConfig.apiServerClient?.account;
578-
if (!account) {
579-
throw new Error('Unable to resolve account for DataService call during AWS agent install preprocess');
580-
}
581-
const apigwAgentConfigZipFile = await downloadAPIGWAgentConfigZip(account);
582-
if (apigwAgentConfigZipFile !== '') {
583-
installConfig.log(chalk.gray('\nSuccess'));
584-
}
585-
(installConfig.gatewayConfig as helpers.AWSAgentValues).apigwAgentConfigZipFile = apigwAgentConfigZipFile;
586-
return installConfig;
587-
};
588-
589535
export const completeInstall = async (installConfig: AgentInstallConfig): Promise<void> => {
590536
/**
591537
* Create agent resources
@@ -596,11 +542,7 @@ export const completeInstall = async (installConfig: AgentInstallConfig): Promis
596542
awsAgentValues.centralConfig = installConfig.centralConfig;
597543
awsAgentValues.traceabilityConfig = installConfig.traceabilityConfig;
598544

599-
const unpackZip = await unzipAPIGWAgentConfigZip(awsAgentValues.apigwAgentConfigZipFile, installConfig.log);
600-
if (unpackZip) {
601-
installConfig.log('\nCreating the agent environment files for AWS...');
602-
}
603-
545+
installConfig.log('\nCreating the agent environment files for AWS...');
604546
installConfig.log('Generating the configuration file(s)...');
605547

606548
installConfig.log('Generating the cloud formation parameters file...');
@@ -636,9 +578,12 @@ export const AWSInstallMethods: InstallationFlowMethods = {
636578
GetBundleType: askBundleType,
637579
GetDeploymentType: askConfigType,
638580
AskGatewayQuestions: gatewayConnectivity,
639-
InstallPreprocess: installPreprocess,
640581
FinalizeGatewayInstall: completeInstall,
641-
ConfigFiles: Object.values(ConfigFiles),
582+
ConfigFiles: [
583+
ConfigFiles.DAEnvVars,
584+
ConfigFiles.TAEnvVars,
585+
ConfigFiles.CFProperties,
586+
],
642587
AgentNameMap: {
643588
[AgentTypes.da]: AgentNames.AWS_DA,
644589
[AgentTypes.ta]: AgentNames.AWS_TA,

src/lib/engage/utils/agents/flows/edgeAgents.ts

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import chalk from 'chalk';
2-
import fs from 'fs';
3-
import { dataService } from '../../../../request.js';
4-
import { AgentConfigTypes, AgentInstallConfig, AgentNames, AgentTypes, BasePaths, BundleType, GatewayTypes, InstallationFlowMethods, localhost, LoggingSource, PublicDockerRepoBaseUrl, PublicRepoUrl, svcAccMsg, YesNo, YesNoChoices } from '../../../types.js';
2+
import { AgentConfigTypes, AgentInstallConfig, AgentNames, AgentTypes, BasePaths, BundleType, GatewayTypes, InstallationFlowMethods, localhost, LoggingSource, PublicDockerRepoBaseUrl, svcAccMsg, YesNo, YesNoChoices } from '../../../types.js';
53
import { askInput, askList, askUsernameAndPassword } from '../../basic-prompts.js';
64
import { writeTemplates, isWindows, AgentHelmInfo, helmImageSecretInfo, helmInstallInfo } from '../../utils.js';
75
import { V7AgentValues } from '../index.js';
86
import * as helpers from '../index.js';
97
import { kubectl } from '../kubectl.js';
108
import { amplifyAgentsNs } from './akamaiAgent.js';
11-
import { Account } from '../../../../../types.js';
129

1310
const defaultLogFiles = '/group-*_instance-*.log';
1411
const defaultOTLogFiles = '/group-*_instance-*_traffic*.log';
@@ -45,47 +42,6 @@ export const prompts = {
4542
'Do you want to replicate your original organization structure for your newly discovered APIs? If yes, make sure the organization names match the team names that are created in Amplify platform',
4643
};
4744

48-
const downloadV7AgentBundle = async (account: Account, type: BundleType, version: string): Promise<string> => {
49-
const fileName
50-
= type === BundleType.DISCOVERY ? `discovery_agent-${version}.zip` : `traceability_agent-${version}.zip`;
51-
const url
52-
= type === BundleType.DISCOVERY
53-
? `${BasePaths.V7Agents}/v7_discovery_agent/${version}/discovery_agent-${version}.zip`
54-
: `${BasePaths.V7Agents}/v7_traceability_agent/${version}/traceability_agent-${version}.zip`;
55-
const service = await dataService({
56-
account: account,
57-
baseUrl: PublicRepoUrl,
58-
});
59-
try {
60-
const { stream } = await service.download(url);
61-
await helpers.streamPipeline(stream, fs.createWriteStream(fileName));
62-
return fileName;
63-
} catch (err: any) {
64-
throw new Error(`Failed to download the agent: ${err.message}`);
65-
}
66-
};
67-
68-
const downloadBinary = async (account: Account, bundleType: BundleType, version: string) => {
69-
const fileName = await downloadV7AgentBundle(account, bundleType, version);
70-
await helpers.unzip(fileName);
71-
fs.unlinkSync(fileName);
72-
};
73-
74-
const downloadBinaries = async (installConfig: AgentInstallConfig) => {
75-
const account = installConfig.centralConfig.apiServerClient?.account;
76-
if (!account) {
77-
throw new Error('Unable to resolve account for DataService call during AWS agent install preprocess');
78-
}
79-
installConfig.log('Downloading and unpacking binary files...');
80-
if (installConfig.switches.isDaEnabled) {
81-
await downloadBinary(account, BundleType.DISCOVERY, installConfig.daVersion);
82-
}
83-
if (installConfig.switches.isTaEnabled) {
84-
await downloadBinary(account, BundleType.TRACEABILITY, installConfig.taVersion);
85-
}
86-
installConfig.log('Downloading and unpacking is complete.');
87-
};
88-
8945
export const askIsGatewayOnlyMode = async (): Promise<GatewayTypes> => {
9046
const mode = await askList({
9147
msg: prompts.enterGatewayManagerMode,
@@ -273,6 +229,8 @@ const generateSuccessHelpMsg = (installConfig: AgentInstallConfig) => {
273229
installConfig.centralConfig.ampcDosaInfo.isNew,
274230
installConfig.switches.isDaEnabled,
275231
installConfig.switches.isTaEnabled,
232+
installConfig.daVersion,
233+
installConfig.taVersion,
276234
installConfig.log
277235
);
278236
} else if (configType === AgentConfigTypes.DOCKERIZED) {
@@ -298,11 +256,6 @@ export const installPreprocess = async (installConfig: AgentInstallConfig): Prom
298256
= await helpers.askPublicAndPrivateKeysPath();
299257
}
300258

301-
// attempt to download the binaries prior to creating resources
302-
if (installConfig.switches.isBinaryInstall) {
303-
await downloadBinaries(installConfig);
304-
}
305-
306259
return installConfig;
307260
};
308261

@@ -418,7 +371,20 @@ const dockerSuccessMsg = (installConfig: AgentInstallConfig, eventLogPath: strin
418371
}
419372
};
420373

421-
const binarySuccessMsg = (isNewDosa: boolean, isDaEnabled: boolean, isTaEnabled: boolean, log: (text: string) => void = () => {}) => {
374+
const binarySuccessMsg = (isNewDosa: boolean, isDaEnabled: boolean, isTaEnabled: boolean, daVersion: string, taVersion: string, log: (text: string) => void = () => {}) => {
375+
const baseUrl = 'https://repository.axway.com/artifactory/ampc-public-generic-release/v7-agents';
376+
377+
if (isDaEnabled) {
378+
log(chalk.whiteBright('\nDownload the Discovery Agent binary:'));
379+
log(chalk.cyan(`curl -O ${baseUrl}/v7_discovery_agent/${daVersion}/discovery_agent-${daVersion}.zip`));
380+
log(chalk.cyan(`unzip discovery_agent-${daVersion}.zip`));
381+
}
382+
if (isTaEnabled) {
383+
log(chalk.whiteBright('\nDownload the Traceability Agent binary:'));
384+
log(chalk.cyan(`curl -O ${baseUrl}/v7_traceability_agent/${taVersion}/traceability_agent-${taVersion}.zip`));
385+
log(chalk.cyan(`unzip traceability_agent-${taVersion}.zip`));
386+
}
387+
422388
const daFiles = [ ConfigFiles.DAEnvVars, ConfigFiles.EdgeDABinaryFile, ConfigFiles.EdgeDAYaml ];
423389
const taFiles = [ ConfigFiles.TAEnvVars, ConfigFiles.EdgeTABinaryFile, ConfigFiles.EdgeTAYaml ];
424390
const keys = [ 'private_key.pem', 'public_key.pem' ];
@@ -435,7 +401,7 @@ const binarySuccessMsg = (isNewDosa: boolean, isDaEnabled: boolean, isTaEnabled:
435401
}
436402
const agents = isDaEnabled && isTaEnabled ? 'agents' : 'agent';
437403

438-
log(chalk.whiteBright('Please copy following files from current folder to API Gateway machine:'));
404+
log(chalk.whiteBright('\nPlease copy following files from current folder to API Gateway machine:'));
439405
log(chalk.cyan(files.join('\n')));
440406
log(chalk.whiteBright('for example') + ' ' + chalk.cyan(`scp ${files.join(' ')} root@host:~/some_folder/`));
441407

0 commit comments

Comments
 (0)