@axinom/mosaic-cli 0.20.0-rc.9 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/hosting/index.js +2 -0
- package/dist/commands/hosting/index.js.map +1 -1
- package/dist/commands/hosting/manifest/upload-manifest.js +4 -0
- package/dist/commands/hosting/manifest/upload-manifest.js.map +1 -1
- package/dist/commands/hosting/pilet/pilet-commands.js +8 -13
- package/dist/commands/hosting/pilet/pilet-commands.js.map +1 -1
- package/dist/commands/hosting/pilet/register-pilet-options.d.ts +0 -2
- package/dist/commands/hosting/pilet/register-pilet.d.ts +1 -1
- package/dist/commands/hosting/pilet/register-pilet.js +62 -51
- package/dist/commands/hosting/pilet/register-pilet.js.map +1 -1
- package/dist/commands/hosting/service/deploy/service-deploy-command.d.ts +3 -0
- package/dist/commands/hosting/service/deploy/service-deploy-command.js +72 -0
- package/dist/commands/hosting/service/deploy/service-deploy-command.js.map +1 -0
- package/dist/commands/hosting/service/deploy/service-deploy-options.d.ts +14 -0
- package/dist/commands/hosting/service/deploy/service-deploy-options.js +3 -0
- package/dist/commands/hosting/service/deploy/service-deploy-options.js.map +1 -0
- package/dist/commands/hosting/service/deploy/service-deploy.d.ts +9 -0
- package/dist/commands/hosting/service/deploy/service-deploy.js +244 -0
- package/dist/commands/hosting/service/deploy/service-deploy.js.map +1 -0
- package/dist/commands/hosting/service/service-commands.d.ts +2 -0
- package/dist/commands/hosting/service/service-commands.js +16 -0
- package/dist/commands/hosting/service/service-commands.js.map +1 -0
- package/dist/commands/hosting/service/undeploy/service-undeploy-command.d.ts +3 -0
- package/dist/commands/hosting/service/undeploy/service-undeploy-command.js +53 -0
- package/dist/commands/hosting/service/undeploy/service-undeploy-command.js.map +1 -0
- package/dist/commands/hosting/service/undeploy/service-undeploy-options.d.ts +11 -0
- package/dist/commands/hosting/service/undeploy/service-undeploy-options.js +3 -0
- package/dist/commands/hosting/service/undeploy/service-undeploy-options.js.map +1 -0
- package/dist/commands/hosting/service/undeploy/service-undeploy.d.ts +9 -0
- package/dist/commands/hosting/service/undeploy/service-undeploy.js +140 -0
- package/dist/commands/hosting/service/undeploy/service-undeploy.js.map +1 -0
- package/package.json +4 -4
- package/src/commands/hosting/index.ts +2 -0
- package/src/commands/hosting/manifest/upload-manifest.ts +7 -0
- package/src/commands/hosting/pilet/pilet-commands.ts +9 -13
- package/src/commands/hosting/pilet/register-pilet-options.ts +0 -2
- package/src/commands/hosting/pilet/register-pilet.ts +89 -57
- package/src/commands/hosting/service/deploy/service-deploy-command.ts +72 -0
- package/src/commands/hosting/service/deploy/service-deploy-options.ts +14 -0
- package/src/commands/hosting/service/deploy/service-deploy.ts +347 -0
- package/src/commands/hosting/service/service-commands.ts +23 -0
- package/src/commands/hosting/service/undeploy/service-undeploy-command.ts +53 -0
- package/src/commands/hosting/service/undeploy/service-undeploy-options.ts +11 -0
- package/src/commands/hosting/service/undeploy/service-undeploy.ts +188 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { red, yellow } from 'chalk';
|
|
2
|
+
import { CommandModule } from 'yargs';
|
|
3
|
+
import { undeployService, validateUndeploymentArgs } from './service-undeploy';
|
|
4
|
+
import { GetServiceUndeployOptions } from './service-undeploy-options';
|
|
5
|
+
|
|
6
|
+
export const serviceUndeploy: CommandModule<
|
|
7
|
+
unknown,
|
|
8
|
+
GetServiceUndeployOptions
|
|
9
|
+
> = {
|
|
10
|
+
builder: (yargs) => {
|
|
11
|
+
return yargs
|
|
12
|
+
.option('name', {
|
|
13
|
+
describe: 'Name of the Deployment',
|
|
14
|
+
alias: 'n',
|
|
15
|
+
string: true,
|
|
16
|
+
})
|
|
17
|
+
.option('serviceDeploymentId', {
|
|
18
|
+
describe: 'ID of the Deployment',
|
|
19
|
+
alias: 'i',
|
|
20
|
+
string: true,
|
|
21
|
+
})
|
|
22
|
+
.option('mosaicHostingClientId', {
|
|
23
|
+
describe: 'Service Account Client ID to authenticate',
|
|
24
|
+
alias: 'c',
|
|
25
|
+
string: true,
|
|
26
|
+
})
|
|
27
|
+
.option('mosaicHostingClientSecret', {
|
|
28
|
+
describe: 'Service Account Client Secret to authenticate',
|
|
29
|
+
alias: 's',
|
|
30
|
+
string: true,
|
|
31
|
+
})
|
|
32
|
+
.option('idServiceAuthBaseURL', {
|
|
33
|
+
describe: 'ID Service Authentication Endpoint Base URL',
|
|
34
|
+
alias: 'a',
|
|
35
|
+
string: true,
|
|
36
|
+
})
|
|
37
|
+
.option('hostingServiceBaseURL', {
|
|
38
|
+
describe: 'Hosting Service Base URL',
|
|
39
|
+
alias: 'h',
|
|
40
|
+
string: true,
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
handler: async (args) => {
|
|
44
|
+
const [validatedArgs, errorMessages] = validateUndeploymentArgs(args);
|
|
45
|
+
if (errorMessages.length > 0) {
|
|
46
|
+
console.log(red('Some required arguments are missing.'));
|
|
47
|
+
console.log(yellow(errorMessages));
|
|
48
|
+
console.log();
|
|
49
|
+
} else {
|
|
50
|
+
await undeployService(validatedArgs);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for Undeploying a Service
|
|
3
|
+
*/
|
|
4
|
+
export interface GetServiceUndeployOptions {
|
|
5
|
+
name?: string;
|
|
6
|
+
serviceDeploymentId?: string;
|
|
7
|
+
mosaicHostingClientId?: string;
|
|
8
|
+
mosaicHostingClientSecret?: string;
|
|
9
|
+
idServiceAuthBaseURL?: string;
|
|
10
|
+
hostingServiceBaseURL?: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { getServiceAccountToken } from '@axinom/mosaic-id-link-be';
|
|
2
|
+
import { isNullOrWhitespace } from '@axinom/mosaic-service-common';
|
|
3
|
+
import axios, { AxiosError, AxiosInstance } from 'axios';
|
|
4
|
+
import { green, red, yellow } from 'chalk';
|
|
5
|
+
import { GetServiceUndeployOptions } from './service-undeploy-options';
|
|
6
|
+
|
|
7
|
+
const getAxiosInstance = (
|
|
8
|
+
hostingServiceBaseUrl: string,
|
|
9
|
+
serviceAccountToken: string,
|
|
10
|
+
): AxiosInstance => {
|
|
11
|
+
return axios.create({
|
|
12
|
+
baseURL: new URL(hostingServiceBaseUrl).toString(),
|
|
13
|
+
headers: {
|
|
14
|
+
Authorization: `Bearer ${serviceAccountToken}`,
|
|
15
|
+
'content-type': 'application/json',
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const undeployService = async (
|
|
21
|
+
args: Required<GetServiceUndeployOptions>,
|
|
22
|
+
): Promise<void> => {
|
|
23
|
+
const serviceAccountToken = await getServiceAccountToken(
|
|
24
|
+
args.idServiceAuthBaseURL,
|
|
25
|
+
args.mosaicHostingClientId,
|
|
26
|
+
args.mosaicHostingClientSecret,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const axiosInstance: AxiosInstance = getAxiosInstance(
|
|
30
|
+
args.hostingServiceBaseURL,
|
|
31
|
+
serviceAccountToken.accessToken,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
let serviceDeploymentId: string | undefined;
|
|
35
|
+
|
|
36
|
+
if (!isNullOrWhitespace(args.name)) {
|
|
37
|
+
serviceDeploymentId = await getServiceDeploymentIdByName(
|
|
38
|
+
args.name,
|
|
39
|
+
axiosInstance,
|
|
40
|
+
);
|
|
41
|
+
} else {
|
|
42
|
+
serviceDeploymentId = args.serviceDeploymentId;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (isNullOrWhitespace(serviceDeploymentId)) {
|
|
46
|
+
console.log(
|
|
47
|
+
red(`No Service Deployment was found for name [${args.name}].`),
|
|
48
|
+
);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const serviceUneployment = JSON.stringify({
|
|
53
|
+
query: `mutation InitiateServiceUndeployment($serviceDeploymentId: UUID!) {
|
|
54
|
+
initiateServiceUndeployment(input: {serviceDeploymentId: $serviceDeploymentId}) {
|
|
55
|
+
status
|
|
56
|
+
serviceDeploymentId
|
|
57
|
+
}
|
|
58
|
+
}`,
|
|
59
|
+
variables: {
|
|
60
|
+
serviceDeploymentId,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const response = await axiosInstance.post('graphql', serviceUneployment);
|
|
66
|
+
if (response.data.errors !== undefined && response.data.errors.length > 0) {
|
|
67
|
+
console.log(
|
|
68
|
+
red(
|
|
69
|
+
`Error while initiating undeployment for Service Deployment ID [${serviceDeploymentId}].`,
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
console.log(response.data.errors);
|
|
73
|
+
console.log();
|
|
74
|
+
} else {
|
|
75
|
+
console.log(
|
|
76
|
+
green(
|
|
77
|
+
`Undeployment for Service Deployment ID [${serviceDeploymentId}] initiated successfully.`,
|
|
78
|
+
),
|
|
79
|
+
);
|
|
80
|
+
console.log(
|
|
81
|
+
yellow(JSON.stringify(response.data.data?.initiateServiceUndeployment)),
|
|
82
|
+
);
|
|
83
|
+
console.log();
|
|
84
|
+
}
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.log(
|
|
87
|
+
red(
|
|
88
|
+
`Error while initiating undeployment for Service Deployment ID [${serviceDeploymentId}].`,
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
console.log(red(JSON.stringify((error as AxiosError).message)));
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Validate arguments for Service Undeployment
|
|
97
|
+
*
|
|
98
|
+
* @param args
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
export const validateUndeploymentArgs = (
|
|
102
|
+
args: GetServiceUndeployOptions,
|
|
103
|
+
): [Required<GetServiceUndeployOptions>, string[]] => {
|
|
104
|
+
const errorMessages: string[] = [];
|
|
105
|
+
|
|
106
|
+
const idServiceAuthBaseURL =
|
|
107
|
+
args.idServiceAuthBaseURL ?? process.env.ID_SERVICE_AUTH_BASE_URL ?? '';
|
|
108
|
+
const hostingServiceBaseURL =
|
|
109
|
+
args.hostingServiceBaseURL ?? process.env.HOSTING_SERVICE_BASE_URL ?? '';
|
|
110
|
+
const mosaicHostingClientId =
|
|
111
|
+
args.mosaicHostingClientId ?? process.env.MOSAIC_HOSTING_CLIENT_ID ?? '';
|
|
112
|
+
const mosaicHostingClientSecret =
|
|
113
|
+
args.mosaicHostingClientSecret ??
|
|
114
|
+
process.env.MOSAIC_HOSTING_CLIENT_SECRET ??
|
|
115
|
+
'';
|
|
116
|
+
const name = args.name ?? '';
|
|
117
|
+
const serviceDeploymentId = args.serviceDeploymentId ?? '';
|
|
118
|
+
|
|
119
|
+
if (isNullOrWhitespace(idServiceAuthBaseURL)) {
|
|
120
|
+
errorMessages.push('[idServiceAuthBaseURL] is required.');
|
|
121
|
+
}
|
|
122
|
+
if (isNullOrWhitespace(mosaicHostingClientId)) {
|
|
123
|
+
errorMessages.push('[clientId] is required.');
|
|
124
|
+
}
|
|
125
|
+
if (isNullOrWhitespace(mosaicHostingClientSecret)) {
|
|
126
|
+
errorMessages.push('[clientSecret] is required.');
|
|
127
|
+
}
|
|
128
|
+
if (isNullOrWhitespace(hostingServiceBaseURL)) {
|
|
129
|
+
errorMessages.push('[hostingServiceBaseURL] is required.');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (isNullOrWhitespace(name) && isNullOrWhitespace(serviceDeploymentId)) {
|
|
133
|
+
errorMessages.push(
|
|
134
|
+
'Either the [name] or [serviceDeploymentId] must be provided to initiate the service undeployment.',
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!isNullOrWhitespace(name) && !isNullOrWhitespace(serviceDeploymentId)) {
|
|
139
|
+
errorMessages.push(
|
|
140
|
+
'Only one of [name] or [serviceDeploymentId] arguments must be provided. Both cannot be present.',
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return [
|
|
145
|
+
{
|
|
146
|
+
name,
|
|
147
|
+
serviceDeploymentId,
|
|
148
|
+
idServiceAuthBaseURL,
|
|
149
|
+
mosaicHostingClientId,
|
|
150
|
+
mosaicHostingClientSecret,
|
|
151
|
+
hostingServiceBaseURL,
|
|
152
|
+
},
|
|
153
|
+
errorMessages,
|
|
154
|
+
];
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const getServiceDeploymentIdByName = async (
|
|
158
|
+
name: string,
|
|
159
|
+
axiosInstance: AxiosInstance,
|
|
160
|
+
): Promise<string | undefined> => {
|
|
161
|
+
const deploymentInfo = JSON.stringify({
|
|
162
|
+
query: `query GetServiceDeploymentIdByName($name: String!) {
|
|
163
|
+
serviceDeployments(condition: {name: $name}) {
|
|
164
|
+
nodes {
|
|
165
|
+
id
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}`,
|
|
169
|
+
variables: {
|
|
170
|
+
name,
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
try {
|
|
175
|
+
const response = await axiosInstance.post('graphql', deploymentInfo);
|
|
176
|
+
if (response.data.errors !== undefined && response.data.errors.length > 0) {
|
|
177
|
+
console.log(red(`Error while retrieving deployment id for [${name}].`));
|
|
178
|
+
console.log(response.data.errors);
|
|
179
|
+
console.log();
|
|
180
|
+
} else {
|
|
181
|
+
return response.data.data?.serviceDeployments?.nodes[0]?.id;
|
|
182
|
+
}
|
|
183
|
+
} catch (error) {
|
|
184
|
+
console.log(red(`Error while retrieving deployment id for [${name}].`));
|
|
185
|
+
console.log(JSON.stringify((error as AxiosError).message));
|
|
186
|
+
console.log();
|
|
187
|
+
}
|
|
188
|
+
};
|