Skip to content

Commit 9b1d705

Browse files
committed
APIGOV-33064 Query Engage for latest version of agent for creating output of install command
1 parent 55edafc commit 9b1d705

4 files changed

Lines changed: 75 additions & 51 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: 45 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 {
@@ -836,8 +878,8 @@ export const GatewayTypeToDataPlane = {
836878
[GatewayTypes.WSO2]: DataPlaneNames.WSO2,
837879
};
838880

839-
export const PublicRepoUrl = 'https://axway.jfrog.io';
840-
export const PublicDockerRepoBaseUrl = 'axway.jfrog.io/ampc-public-docker-release';
881+
export const PublicRepoUrl = 'https://repository.axway.com';
882+
export const PublicDockerRepoBaseUrl = 'repository.axway.com/ampc-public-docker-release';
841883

842884
export class DOSAConfigInfo {
843885
clientId: string | null;

src/lib/engage/utils/agents/getters.ts

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { ApiServerClient } from '../../clients-external/apiserverclient.js';
2-
import { ApiServerClientListResult, BasePaths, PublicRepoUrl } from '../../types.js';
3-
import { dataService } from '../../../request.js';
2+
import { ApiServerClientListResult } from '../../types.js';
43
import { DefinitionsManager } from '../../results/DefinitionsManager.js';
54
import logger from '../../../logger.js';
6-
import { Account } from '../../../../types.js';
75

86
const { log, error } = logger('lib: engage: utils: agents: getters');
97

@@ -56,49 +54,17 @@ export const getEnvironmentId = async (
5654
return resource.data?.metadata ? resource.data.metadata.id || '' : '';
5755
};
5856

59-
export const getLatestAgentVersion = async (agent: string, account: Account): Promise<string> => {
57+
export const getLatestAgentVersion = async (client: ApiServerClient, agentName: string): Promise<string> => {
6058
try {
61-
const service = await dataService({ account, baseUrl: PublicRepoUrl + BasePaths.DockerAgentAPIRepoPath });
62-
63-
const response = await service.get(
64-
`/${agent}/tags/list`,
65-
{
66-
// docker api requires auth, even if its just anonymous
67-
Authorization: `Basic ${Buffer.from('anonymous:').toString('base64')}`,
68-
},
69-
true
70-
);
71-
72-
if (response.tags.length === 0) {
73-
return 'latest';
59+
const componentDef = await client.getComponentDefinitionsByName(agentName);
60+
const version = componentDef.spec?.latest?.version;
61+
if (version) {
62+
log(`Latest Version (${agentName}): ${version}`);
63+
return version;
7464
}
75-
const latestVersion = response.tags.reduce((prev: string, current: string) => {
76-
// skip any tags that are latest
77-
if (prev === 'latest') {
78-
return current;
79-
} else if (current === 'latest') {
80-
return prev;
81-
}
82-
83-
// find the largest tag
84-
const [ pMajor, pMinor, pPatch ] = prev.split('.').map(Number);
85-
const [ cMajor, cMinor, cPatch ] = current.split('.').map(Number);
86-
87-
if (cMajor > pMajor) {
88-
return current;
89-
}
90-
if (cMajor === pMajor && cMinor > pMinor) {
91-
return current;
92-
}
93-
if (cMajor === pMajor && cMinor === pMinor && cPatch > pPatch) {
94-
return current;
95-
}
96-
return prev;
97-
});
98-
log(`Latest Version (${agent}): ${latestVersion}`);
99-
return latestVersion;
65+
return 'latest';
10066
} catch (e: any) {
101-
error('Error hit retrieving latest version of agent, setting tag to latest');
67+
error('Error retrieving latest version, setting tag to latest');
10268
error(e);
10369
return 'latest';
10470
}

0 commit comments

Comments
 (0)