@contrail/cli 2.3.5 → 2.4.0-alpha-0.1
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/README.md +3 -7
- package/dist/api/apps.d.ts +1 -1
- package/dist/api/apps.js +3 -20
- package/dist/auth/login.d.ts +0 -1
- package/dist/auth/login.js +3 -12
- package/dist/commands/app/create.js +1 -2
- package/dist/commands/app/init.js +2 -1
- package/dist/commands/app/install.d.ts +0 -1
- package/dist/commands/app/install.js +1 -6
- package/dist/commands/projects/load.d.ts +0 -3
- package/dist/commands/projects/load.js +36 -55
- package/dist/helpers/app/app-config-validators.d.ts +16 -1
- package/dist/helpers/app/app-config-validators.js +73 -24
- package/dist/helpers/app/app-config-validators.spec.js +225 -20
- package/dist/helpers/app/app-deployer.js +12 -7
- package/dist/helpers/app/app-template-parsers.d.ts +4 -1
- package/dist/helpers/app/app-template-parsers.js +31 -1
- package/dist/helpers/projects/helpers.js +16 -21
- package/dist/interfaces.d.ts +20 -1
- package/dist/interfaces.js +10 -1
- package/dist/templates/typescript/app.yml +6 -1
- package/oclif.manifest.json +2 -17
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ $ npm install -g @contrail/cli
|
|
|
17
17
|
$ contrail COMMAND
|
|
18
18
|
running command...
|
|
19
19
|
$ contrail (--version)
|
|
20
|
-
@contrail/cli/2.
|
|
20
|
+
@contrail/cli/2.4.0-alpha-0.1 darwin-arm64 node-v21.7.1
|
|
21
21
|
$ contrail --help [COMMAND]
|
|
22
22
|
USAGE
|
|
23
23
|
$ contrail COMMAND
|
|
@@ -174,10 +174,9 @@ Install an app from the marketplace
|
|
|
174
174
|
|
|
175
175
|
```
|
|
176
176
|
USAGE
|
|
177
|
-
$ contrail app install [-i <value>] [-w]
|
|
177
|
+
$ contrail app install [-i <value>] [-w]
|
|
178
178
|
|
|
179
179
|
FLAGS
|
|
180
|
-
-h, --showHidden Show the option to install public but hidden apps
|
|
181
180
|
-i, --appIdentifier=<value> The identifier of the app to install
|
|
182
181
|
-w, --installWorkflowTemplates "Install the app's accompanying workflows"
|
|
183
182
|
|
|
@@ -876,14 +875,11 @@ Configure a project from a yml file.
|
|
|
876
875
|
|
|
877
876
|
```
|
|
878
877
|
USAGE
|
|
879
|
-
$ contrail projects load TEMPLATEFILELOCATION
|
|
878
|
+
$ contrail projects load TEMPLATEFILELOCATION
|
|
880
879
|
|
|
881
880
|
ARGUMENTS
|
|
882
881
|
TEMPLATEFILELOCATION The location to the template file
|
|
883
882
|
|
|
884
|
-
FLAGS
|
|
885
|
-
--dumpTransformedFile If set to true, stores a transformed version of the template file
|
|
886
|
-
|
|
887
883
|
DESCRIPTION
|
|
888
884
|
Configure a project from a yml file.
|
|
889
885
|
|
package/dist/api/apps.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export declare function upgradeAppVersion(appOrg: any, appVersionId: any): Promi
|
|
|
7
7
|
export declare function deleteAppOrg(appOrgId: string): Promise<AppOrg>;
|
|
8
8
|
export declare function getInstalledApps(): Promise<AppOrg[]>;
|
|
9
9
|
export declare function installAppToOrg(app: any, configProperties: any): Promise<AppOrg>;
|
|
10
|
-
export declare function getAvailableApps(
|
|
10
|
+
export declare function getAvailableApps(): Promise<App[]>;
|
package/dist/api/apps.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAvailableApps = exports.installAppToOrg = exports.getInstalledApps = exports.deleteAppOrg = exports.upgradeAppVersion = exports.getAppVersions = exports.getWorkflowTemplateDefinitionsForAppVersion = void 0;
|
|
4
|
-
const auth_1 = require("../auth/auth");
|
|
5
4
|
const sdk_1 = require("@contrail/sdk");
|
|
6
5
|
async function getWorkflowTemplateDefinitionsForAppVersion(options) {
|
|
7
6
|
return await new sdk_1.Entities().get({
|
|
@@ -55,26 +54,10 @@ async function installAppToOrg(app, configProperties) {
|
|
|
55
54
|
});
|
|
56
55
|
}
|
|
57
56
|
exports.installAppToOrg = installAppToOrg;
|
|
58
|
-
async function getAvailableApps(
|
|
59
|
-
const
|
|
60
|
-
const apps = [];
|
|
61
|
-
apps.push(...(await new sdk_1.Entities().get({
|
|
57
|
+
async function getAvailableApps() {
|
|
58
|
+
const apps = await new sdk_1.Entities().get({
|
|
62
59
|
entityName: 'app',
|
|
63
|
-
|
|
64
|
-
orgId,
|
|
65
|
-
private: true,
|
|
66
|
-
...options,
|
|
67
|
-
},
|
|
68
|
-
})));
|
|
69
|
-
apps.push(...(await new sdk_1.Entities().get({
|
|
70
|
-
entityName: 'app',
|
|
71
|
-
criteria: {
|
|
72
|
-
orgId,
|
|
73
|
-
private: false,
|
|
74
|
-
hidden: true,
|
|
75
|
-
...options,
|
|
76
|
-
},
|
|
77
|
-
})));
|
|
60
|
+
});
|
|
78
61
|
return apps;
|
|
79
62
|
}
|
|
80
63
|
exports.getAvailableApps = getAvailableApps;
|
package/dist/auth/login.d.ts
CHANGED
package/dist/auth/login.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.authUser = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const amazon_cognito_identity_js_1 = require("amazon-cognito-identity-js");
|
|
6
6
|
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
@@ -15,6 +15,7 @@ const CONFIGURATION = {
|
|
|
15
15
|
async function authUser() {
|
|
16
16
|
logger_1.default.debug('authorizing user...');
|
|
17
17
|
const config = await (0, config_1.getConfig)();
|
|
18
|
+
console.log('config', config);
|
|
18
19
|
if (config && config.apiUserToken && config.apiGateway && config.orgSlug) {
|
|
19
20
|
logger_1.default.debug('populating auth config from fs config...');
|
|
20
21
|
auth_1.Auth.config = {
|
|
@@ -122,19 +123,9 @@ async function setAuthContext(user, params) {
|
|
|
122
123
|
(0, sdk_1.setConfig)(auth_1.Auth.config);
|
|
123
124
|
return refreshCurrentUserOrg();
|
|
124
125
|
}
|
|
125
|
-
async function getCurrentUser() {
|
|
126
|
-
return await sdk_1.Request.request('/users/current', {
|
|
127
|
-
method: 'GET',
|
|
128
|
-
headers: {
|
|
129
|
-
Accept: 'application/json',
|
|
130
|
-
'Content-Type': 'application/json',
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
exports.getCurrentUser = getCurrentUser;
|
|
135
126
|
async function refreshCurrentUserOrg() {
|
|
136
127
|
logger_1.default.debug('refreshing current user org...');
|
|
137
|
-
const currentUser = await getCurrentUser();
|
|
128
|
+
const currentUser = await (0, sdk_1.getCurrentUser)();
|
|
138
129
|
if (!currentUser) {
|
|
139
130
|
throw Error('Could not get current user');
|
|
140
131
|
}
|
|
@@ -15,7 +15,7 @@ class CreateApp extends basecommand_1.BaseCommand {
|
|
|
15
15
|
];
|
|
16
16
|
async run() {
|
|
17
17
|
await (0, login_1.authUser)();
|
|
18
|
-
const currentUser = await (0,
|
|
18
|
+
const currentUser = await (0, sdk_1.getCurrentUser)();
|
|
19
19
|
const username = currentUser.email.split('@')[0];
|
|
20
20
|
const defaultAppName = `Hello World by ${username}`;
|
|
21
21
|
const defaultAppIdentifier = `@${username}/hello-world`;
|
|
@@ -61,7 +61,6 @@ class CreateApp extends basecommand_1.BaseCommand {
|
|
|
61
61
|
name: answers.appName,
|
|
62
62
|
publisher: answers.appPublisher,
|
|
63
63
|
public: false,
|
|
64
|
-
hidden: false,
|
|
65
64
|
description: answers.appDescription,
|
|
66
65
|
frameworkVersion: 2,
|
|
67
66
|
};
|
|
@@ -5,6 +5,7 @@ const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
|
5
5
|
const login_1 = require("../../auth/login");
|
|
6
6
|
const basecommand_1 = require("../../basecommand");
|
|
7
7
|
const setup_template_1 = require("../../helpers/app/setup-template");
|
|
8
|
+
const sdk_1 = require("@contrail/sdk");
|
|
8
9
|
class CreateApp extends basecommand_1.BaseCommand {
|
|
9
10
|
static description = 'Create an app from a template';
|
|
10
11
|
static examples = [
|
|
@@ -13,7 +14,7 @@ class CreateApp extends basecommand_1.BaseCommand {
|
|
|
13
14
|
];
|
|
14
15
|
async run() {
|
|
15
16
|
await (0, login_1.authUser)();
|
|
16
|
-
const currentUser = await (0,
|
|
17
|
+
const currentUser = await (0, sdk_1.getCurrentUser)();
|
|
17
18
|
const username = currentUser.email.split('@')[0];
|
|
18
19
|
const defaultAppName = `Hello World by ${username}`;
|
|
19
20
|
const defaultAppIdentifier = `@${username}/hello-world`;
|
|
@@ -6,7 +6,6 @@ export default class InstallApp extends BaseCommand {
|
|
|
6
6
|
static flags: {
|
|
7
7
|
appIdentifier: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
8
|
installWorkflowTemplates: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
|
-
showHidden: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
10
9
|
};
|
|
11
10
|
run(): Promise<void>;
|
|
12
11
|
}
|
|
@@ -30,16 +30,11 @@ class InstallApp extends basecommand_1.BaseCommand {
|
|
|
30
30
|
description: '"Install the app\'s accompanying workflows"',
|
|
31
31
|
required: false,
|
|
32
32
|
}),
|
|
33
|
-
showHidden: core_1.Flags.boolean({
|
|
34
|
-
char: 'h',
|
|
35
|
-
description: 'Show the option to install public but hidden apps',
|
|
36
|
-
required: false,
|
|
37
|
-
}),
|
|
38
33
|
};
|
|
39
34
|
async run() {
|
|
40
35
|
const { flags } = await this.parse(InstallApp);
|
|
41
36
|
await (0, login_1.authUser)();
|
|
42
|
-
const apps = await (0, apps_1.getAvailableApps)(
|
|
37
|
+
const apps = await (0, apps_1.getAvailableApps)();
|
|
43
38
|
if (!apps.length) {
|
|
44
39
|
throw new Error('No apps are available to install...');
|
|
45
40
|
}
|
|
@@ -5,9 +5,6 @@ export default class LoadProject extends BaseCommand {
|
|
|
5
5
|
static args: {
|
|
6
6
|
templateFileLocation: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
7
7
|
};
|
|
8
|
-
static flags: {
|
|
9
|
-
dumpTransformedFile: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
10
|
-
};
|
|
11
8
|
run(): Promise<void>;
|
|
12
9
|
}
|
|
13
10
|
interface CheckerFunction {
|
|
@@ -9,8 +9,6 @@ const login_1 = require("../../auth/login");
|
|
|
9
9
|
const basecommand_1 = require("../../basecommand");
|
|
10
10
|
const helpers_1 = require("../../helpers/projects/helpers");
|
|
11
11
|
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
12
|
-
const pLimit = require('p-limit');
|
|
13
|
-
const limit = pLimit(30);
|
|
14
12
|
class LoadProject extends basecommand_1.BaseCommand {
|
|
15
13
|
static description = 'Configure a project from a yml file.';
|
|
16
14
|
static examples = [
|
|
@@ -23,26 +21,18 @@ class LoadProject extends basecommand_1.BaseCommand {
|
|
|
23
21
|
required: true,
|
|
24
22
|
}),
|
|
25
23
|
};
|
|
26
|
-
static flags = {
|
|
27
|
-
...basecommand_1.BaseCommand.flags,
|
|
28
|
-
dumpTransformedFile: core_1.Flags.boolean({
|
|
29
|
-
description: 'If set to true, stores a transformed version of the template file',
|
|
30
|
-
default: false,
|
|
31
|
-
}),
|
|
32
|
-
};
|
|
33
24
|
async run() {
|
|
34
|
-
const { args
|
|
25
|
+
const { args } = await this.parse(LoadProject);
|
|
35
26
|
try {
|
|
36
27
|
await (0, login_1.authUser)();
|
|
37
28
|
this.log('%s Parsing Template.', chalk_1.default.blue.bold('START'));
|
|
38
29
|
this.log('%s Uploading', chalk_1.default.yellow.bold('PROJECT'));
|
|
39
30
|
const templateFileLocation = args.templateFileLocation;
|
|
40
31
|
this.log('Using Template File Location: ', args.templateFileLocation);
|
|
41
|
-
await uploadProject(templateFileLocation
|
|
32
|
+
await uploadProject(templateFileLocation);
|
|
42
33
|
this.log('%s Uploaded', chalk_1.default.yellow.bold('PROJECT'));
|
|
43
34
|
}
|
|
44
35
|
catch (e) {
|
|
45
|
-
console.error(e);
|
|
46
36
|
this.log(`%s Project Upload Failed. ${e}`, chalk_1.default.red.bold('FAIL'));
|
|
47
37
|
return;
|
|
48
38
|
}
|
|
@@ -50,16 +40,11 @@ class LoadProject extends basecommand_1.BaseCommand {
|
|
|
50
40
|
}
|
|
51
41
|
}
|
|
52
42
|
exports.default = LoadProject;
|
|
53
|
-
async function uploadProject(templateFileLocation
|
|
43
|
+
async function uploadProject(templateFileLocation) {
|
|
54
44
|
const projectConfigurationFromFile = (0, helpers_1.getProjectFile)(templateFileLocation);
|
|
55
45
|
const projectConfiguration = getProjectConfiguration(projectConfigurationFromFile);
|
|
56
46
|
logger_1.default.info('Checking for object and type references');
|
|
57
47
|
await transformProject(projectConfiguration);
|
|
58
|
-
if (flags.dumpTransformedFile) {
|
|
59
|
-
logger_1.default.info('Dumping transformed project file');
|
|
60
|
-
const fs = require('fs');
|
|
61
|
-
fs.writeFileSync(templateFileLocation + '.transformed', JSON.stringify(projectConfiguration, null, 2));
|
|
62
|
-
}
|
|
63
48
|
logger_1.default.info('Configuring Project.');
|
|
64
49
|
await sdk_1.Request.request('/project-configurator', {
|
|
65
50
|
method: 'POST',
|
|
@@ -170,47 +155,43 @@ async function transformAssortmentObjectReferences(_, assortments) {
|
|
|
170
155
|
relations: ['typeProperties'],
|
|
171
156
|
});
|
|
172
157
|
const assortmentProperties = assortmentType.typeProperties;
|
|
173
|
-
const promises = [];
|
|
174
158
|
for (const assortment of assortments ?? []) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
159
|
+
const attributes = JSON.parse(JSON.stringify(assortment?.assortmentAtts ?? {}));
|
|
160
|
+
if (!Object.keys(attributes)?.length) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
for (const [attributeKey, attributeValue] of Object.entries(attributes)) {
|
|
164
|
+
const property = assortmentProperties.find((x) => x.slug === attributeKey);
|
|
165
|
+
// if not a reference
|
|
166
|
+
if (!property || !property.referencedTypePath) {
|
|
167
|
+
continue;
|
|
179
168
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
//
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
169
|
+
if (property.propertyType === types_1.PropertyType.TypeReference) {
|
|
170
|
+
logger_1.default.debug(`found type reference!${attributeKey}${attributeValue}`);
|
|
171
|
+
// special case: handle type references
|
|
172
|
+
const type = (await new sdk_1.Types().getType({ path: attributeValue }))?.id;
|
|
173
|
+
logger_1.default.debug(`found type ${type}`);
|
|
174
|
+
logger_1.default.info(`replacing ${attributeKey}:${attributeValue} with ${attributeKey}Id:${type}`);
|
|
175
|
+
assortment.assortmentAtts[`${attributeKey}Id`] = type;
|
|
176
|
+
}
|
|
177
|
+
else if (property.propertyType === types_1.PropertyType.ObjectReference) {
|
|
178
|
+
logger_1.default.debug(`found object reference!${attributeKey}${attributeValue}`);
|
|
179
|
+
let allEntities = [];
|
|
180
|
+
if (property.referencedTypePath.startsWith('custom-entity')) {
|
|
181
|
+
allEntities = await new sdk_1.Entities().get({
|
|
182
|
+
entityName: 'custom-entity',
|
|
183
|
+
criteria: { typePath: property.referencedTypePath },
|
|
184
|
+
});
|
|
193
185
|
}
|
|
194
|
-
else
|
|
195
|
-
|
|
196
|
-
let allEntities = [];
|
|
197
|
-
if (property.referencedTypePath.startsWith('custom-entity')) {
|
|
198
|
-
allEntities = await new sdk_1.Entities().get({
|
|
199
|
-
entityName: 'custom-entity',
|
|
200
|
-
criteria: { typePath: property.referencedTypePath },
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
allEntities = await new sdk_1.Entities().get({ entityName: property.referencedTypePath });
|
|
205
|
-
}
|
|
206
|
-
// special case: handle type references
|
|
207
|
-
const foundAttribute = allEntities.find((x) => x.name === attributeValue)?.id ?? attributeKey;
|
|
208
|
-
logger_1.default.debug(`found attribute ${foundAttribute}`);
|
|
209
|
-
logger_1.default.info(`replacing ${attributeKey}:${attributeValue} with ${attributeKey}Id:${foundAttribute}`);
|
|
210
|
-
assortment.assortmentAtts[`${attributeKey}Id`] = foundAttribute;
|
|
186
|
+
else {
|
|
187
|
+
allEntities = await new sdk_1.Entities().get({ entityName: property.referencedTypePath });
|
|
211
188
|
}
|
|
189
|
+
// special case: handle type references
|
|
190
|
+
const foundAttribute = allEntities.find((x) => x.name === attributeValue)?.id ?? attributeKey;
|
|
191
|
+
logger_1.default.debug(`found attribute ${foundAttribute}`);
|
|
192
|
+
logger_1.default.info(`replacing ${attributeKey}:${attributeValue} with ${attributeKey}Id:${foundAttribute}`);
|
|
193
|
+
assortment.assortmentAtts[`${attributeKey}Id`] = foundAttribute;
|
|
212
194
|
}
|
|
213
|
-
}
|
|
214
|
-
await Promise.all(promises);
|
|
195
|
+
}
|
|
215
196
|
}
|
|
216
197
|
}
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import { AppDeclaration } from '../../interfaces';
|
|
2
2
|
export interface AppConfigValidationError {
|
|
3
|
-
|
|
3
|
+
errors: string[];
|
|
4
|
+
warnings: string[];
|
|
4
5
|
}
|
|
6
|
+
export declare const ERROR_MESSAGES: {
|
|
7
|
+
missingVersionField: string;
|
|
8
|
+
invalidVersionField: string;
|
|
9
|
+
invalidAppVersion: string;
|
|
10
|
+
accessGrantsArray: string;
|
|
11
|
+
invalidOrgSlug: string;
|
|
12
|
+
emptyPermissionsArray: string;
|
|
13
|
+
invalidVisibility: string;
|
|
14
|
+
deprecatedHiddenField: string;
|
|
15
|
+
ignoredAccessGrants: string;
|
|
16
|
+
invalidPermission: (permission: string) => string;
|
|
17
|
+
invalidAccessGrants: (error: string) => string;
|
|
18
|
+
};
|
|
5
19
|
export declare function validateAppConfig(appConfig: AppDeclaration): void;
|
|
6
20
|
export declare function appVersionValidator(appDeclaration: AppDeclaration): AppConfigValidationError;
|
|
7
21
|
export declare function visibilityValidator(appDeclaration: AppDeclaration): AppConfigValidationError;
|
|
22
|
+
export declare function validateAccessGrants(appDeclaration: AppDeclaration): AppConfigValidationError;
|
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.visibilityValidator = exports.appVersionValidator = exports.validateAppConfig = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.validateAccessGrants = exports.visibilityValidator = exports.appVersionValidator = exports.validateAppConfig = exports.ERROR_MESSAGES = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const interfaces_1 = require("../../interfaces");
|
|
6
|
+
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
7
|
+
const VALIDATORS = [appVersionValidator, visibilityValidator, validateAccessGrants];
|
|
8
|
+
exports.ERROR_MESSAGES = {
|
|
9
|
+
missingVersionField: 'Missing "version" field". Semantic App Version looks like "1.0.0". Use "contrail app version [patch|minor|major]" to update the app version.',
|
|
10
|
+
invalidVersionField: '"version" field is not a string. Expecting a version like "1.0.0". Manually update the "version" field to be a string in the app.yml file.',
|
|
11
|
+
invalidAppVersion: 'Invalid app version. Semantic App Version looks like "1.0.0". Use "contrail app version [patch|minor|major]" to update the app version.',
|
|
12
|
+
accessGrantsArray: 'accessGrants must be an array.',
|
|
13
|
+
invalidOrgSlug: 'Invalid or missing orgSlug in one of the accessGrants objects.',
|
|
14
|
+
emptyPermissionsArray: 'Permissions must be a non-empty array in one of the accessGrants objects.',
|
|
15
|
+
invalidVisibility: 'Invalid visibility. Visibility must be "public" or "private".',
|
|
16
|
+
deprecatedHiddenField: 'The "hidden" field is deprecated.',
|
|
17
|
+
ignoredAccessGrants: 'App is set to public. accessGrants will be ignored.',
|
|
18
|
+
invalidPermission: (permission) => `Invalid permission found in one of the accessGrants objects: ${permission}.`,
|
|
19
|
+
invalidAccessGrants: (error) => `Invalid accessGrants. ${error}`,
|
|
20
|
+
};
|
|
5
21
|
function validateAppConfig(appConfig) {
|
|
6
22
|
const errors = [];
|
|
23
|
+
const warnings = [];
|
|
7
24
|
for (const validator of VALIDATORS) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
25
|
+
const validation = validator(appConfig);
|
|
26
|
+
errors.push(...validation.errors);
|
|
27
|
+
warnings.push(...validation.warnings);
|
|
28
|
+
}
|
|
29
|
+
if (warnings.length) {
|
|
30
|
+
logger_1.default.warn(warnings);
|
|
12
31
|
}
|
|
13
32
|
if (errors.length) {
|
|
14
33
|
throw new Error(`Invalid app config: \n ${errors.map((x) => x.error).join('\n')}`);
|
|
@@ -16,36 +35,66 @@ function validateAppConfig(appConfig) {
|
|
|
16
35
|
}
|
|
17
36
|
exports.validateAppConfig = validateAppConfig;
|
|
18
37
|
function appVersionValidator(appDeclaration) {
|
|
38
|
+
const errors = [];
|
|
39
|
+
const warnings = [];
|
|
19
40
|
if (!appDeclaration.version) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
41
|
+
errors.push(exports.ERROR_MESSAGES.missingVersionField);
|
|
42
|
+
return { errors, warnings };
|
|
23
43
|
}
|
|
24
44
|
if (typeof appDeclaration.version !== 'string') {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
45
|
+
errors.push(exports.ERROR_MESSAGES.invalidVersionField);
|
|
46
|
+
return { errors, warnings };
|
|
28
47
|
}
|
|
29
48
|
const parts = appDeclaration.version.split('.');
|
|
30
49
|
if (parts.length !== 3) {
|
|
31
|
-
|
|
32
|
-
error: 'Invalid app version. Semantic App Version looks like "1.0.0". Use "contrail app version [patch|minor|major]" to update the app version.',
|
|
33
|
-
};
|
|
50
|
+
errors.push(exports.ERROR_MESSAGES.invalidAppVersion);
|
|
34
51
|
}
|
|
52
|
+
return { errors, warnings };
|
|
35
53
|
}
|
|
36
54
|
exports.appVersionValidator = appVersionValidator;
|
|
37
55
|
function visibilityValidator(appDeclaration) {
|
|
56
|
+
const errors = [];
|
|
57
|
+
const warnings = [];
|
|
38
58
|
if (!['public', 'private'].includes(appDeclaration.visibility)) {
|
|
39
|
-
|
|
40
|
-
error: 'Invalid visibility. Visibility must be "public" or "private".',
|
|
41
|
-
};
|
|
59
|
+
errors.push(exports.ERROR_MESSAGES.invalidVisibility);
|
|
42
60
|
}
|
|
43
|
-
if (appDeclaration.
|
|
44
|
-
|
|
45
|
-
appDeclaration.hidden === true) {
|
|
46
|
-
return {
|
|
47
|
-
error: 'Apps can not be private and hidden.',
|
|
48
|
-
};
|
|
61
|
+
if (appDeclaration.hasOwnProperty('hidden')) {
|
|
62
|
+
warnings.push(exports.ERROR_MESSAGES.deprecatedHiddenField);
|
|
49
63
|
}
|
|
64
|
+
return { errors, warnings };
|
|
50
65
|
}
|
|
51
66
|
exports.visibilityValidator = visibilityValidator;
|
|
67
|
+
function validateAccessGrants(appDeclaration) {
|
|
68
|
+
const errors = [];
|
|
69
|
+
const warnings = [];
|
|
70
|
+
if (appDeclaration.visibility === 'public' && appDeclaration.hasOwnProperty('accessGrants')) {
|
|
71
|
+
warnings.push(exports.ERROR_MESSAGES.ignoredAccessGrants);
|
|
72
|
+
}
|
|
73
|
+
if (appDeclaration.visibility === 'private' && appDeclaration.hasOwnProperty('accessGrants')) {
|
|
74
|
+
const accessGrantsArray = appDeclaration.accessGrants;
|
|
75
|
+
if (!Array.isArray(accessGrantsArray)) {
|
|
76
|
+
errors.push(exports.ERROR_MESSAGES.accessGrantsArray);
|
|
77
|
+
return { errors, warnings };
|
|
78
|
+
}
|
|
79
|
+
for (const accessGrants of accessGrantsArray) {
|
|
80
|
+
if (!accessGrants?.orgSlug || accessGrants?.orgSlug.trim() === '') {
|
|
81
|
+
errors.push(exports.ERROR_MESSAGES.invalidOrgSlug);
|
|
82
|
+
}
|
|
83
|
+
if (!Array.isArray(accessGrants?.permissions) || accessGrants?.permissions.length === 0) {
|
|
84
|
+
errors.push(exports.ERROR_MESSAGES.emptyPermissionsArray);
|
|
85
|
+
}
|
|
86
|
+
if (Array.isArray(accessGrants?.permissions)) {
|
|
87
|
+
for (const permission of accessGrants.permissions) {
|
|
88
|
+
if (!isValidPermission(permission)) {
|
|
89
|
+
errors.push(exports.ERROR_MESSAGES.invalidPermission(permission));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { errors, warnings };
|
|
96
|
+
}
|
|
97
|
+
exports.validateAccessGrants = validateAccessGrants;
|
|
98
|
+
function isValidPermission(permission) {
|
|
99
|
+
return Object.values(interfaces_1.AppAccessPermission).includes(permission);
|
|
100
|
+
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const app_config_validators_1 = require("./app-config-validators");
|
|
4
|
+
const validResult = {
|
|
5
|
+
errors: [],
|
|
6
|
+
warnings: [],
|
|
7
|
+
};
|
|
4
8
|
describe('appVersionValidator', () => {
|
|
5
9
|
it('should return an error if "version" field is missing', () => {
|
|
6
10
|
const appDeclaration = {};
|
|
7
11
|
const expectedError = {
|
|
8
|
-
|
|
12
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.missingVersionField],
|
|
13
|
+
warnings: [],
|
|
9
14
|
};
|
|
10
15
|
const validationResult = (0, app_config_validators_1.appVersionValidator)(appDeclaration);
|
|
11
16
|
expect(validationResult).toEqual(expectedError);
|
|
@@ -15,7 +20,8 @@ describe('appVersionValidator', () => {
|
|
|
15
20
|
version: 'invalidVersion',
|
|
16
21
|
};
|
|
17
22
|
const expectedError = {
|
|
18
|
-
|
|
23
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.invalidAppVersion],
|
|
24
|
+
warnings: [],
|
|
19
25
|
};
|
|
20
26
|
const validationResult = (0, app_config_validators_1.appVersionValidator)(appDeclaration);
|
|
21
27
|
expect(validationResult).toEqual(expectedError);
|
|
@@ -25,14 +31,18 @@ describe('appVersionValidator', () => {
|
|
|
25
31
|
version: '1.0.0',
|
|
26
32
|
};
|
|
27
33
|
const validationResult = (0, app_config_validators_1.appVersionValidator)(appDeclaration);
|
|
28
|
-
expect(validationResult).
|
|
34
|
+
expect(validationResult).toEqual(validResult);
|
|
29
35
|
});
|
|
30
36
|
it('should gracefully handle bad versions', () => {
|
|
31
37
|
const appDeclaration = {
|
|
32
38
|
version: '1',
|
|
33
39
|
};
|
|
40
|
+
const expectedError = {
|
|
41
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.invalidAppVersion],
|
|
42
|
+
warnings: [],
|
|
43
|
+
};
|
|
34
44
|
const validationResult = (0, app_config_validators_1.appVersionValidator)(appDeclaration);
|
|
35
|
-
expect(validationResult
|
|
45
|
+
expect(validationResult).toEqual(expectedError);
|
|
36
46
|
});
|
|
37
47
|
});
|
|
38
48
|
it('should return an error if "version" field is not a string', () => {
|
|
@@ -40,7 +50,8 @@ it('should return an error if "version" field is not a string', () => {
|
|
|
40
50
|
version: 123,
|
|
41
51
|
};
|
|
42
52
|
const expectedError = {
|
|
43
|
-
|
|
53
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.invalidVersionField],
|
|
54
|
+
warnings: [],
|
|
44
55
|
};
|
|
45
56
|
const validationResult = (0, app_config_validators_1.appVersionValidator)(appDeclaration);
|
|
46
57
|
expect(validationResult).toEqual(expectedError);
|
|
@@ -50,7 +61,8 @@ it('should return an error if "version" field is empty', () => {
|
|
|
50
61
|
version: '',
|
|
51
62
|
};
|
|
52
63
|
const expectedError = {
|
|
53
|
-
|
|
64
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.missingVersionField],
|
|
65
|
+
warnings: [],
|
|
54
66
|
};
|
|
55
67
|
const validationResult = (0, app_config_validators_1.appVersionValidator)(appDeclaration);
|
|
56
68
|
expect(validationResult).toEqual(expectedError);
|
|
@@ -60,7 +72,8 @@ it('should return an error if app version has invalid format', () => {
|
|
|
60
72
|
version: '1.0',
|
|
61
73
|
};
|
|
62
74
|
const expectedError = {
|
|
63
|
-
|
|
75
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.invalidAppVersion],
|
|
76
|
+
warnings: [],
|
|
64
77
|
};
|
|
65
78
|
const validationResult = (0, app_config_validators_1.appVersionValidator)(appDeclaration);
|
|
66
79
|
expect(validationResult).toEqual(expectedError);
|
|
@@ -71,35 +84,227 @@ describe('visibilityValidator', () => {
|
|
|
71
84
|
visibility: 'invalidVisibility',
|
|
72
85
|
};
|
|
73
86
|
const expectedError = {
|
|
74
|
-
|
|
87
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.invalidVisibility],
|
|
88
|
+
warnings: [],
|
|
75
89
|
};
|
|
76
90
|
const validationResult = (0, app_config_validators_1.visibilityValidator)(appDeclaration);
|
|
77
91
|
expect(validationResult).toEqual(expectedError);
|
|
78
92
|
});
|
|
79
|
-
it('should return an error if
|
|
93
|
+
it('should not return an error if visibility is "public"', () => {
|
|
80
94
|
const appDeclaration = {
|
|
81
|
-
visibility: '
|
|
95
|
+
visibility: 'public',
|
|
96
|
+
};
|
|
97
|
+
const validationResult = (0, app_config_validators_1.visibilityValidator)(appDeclaration);
|
|
98
|
+
expect(validationResult).toEqual(validResult);
|
|
99
|
+
});
|
|
100
|
+
it('should warn if "hidden" field is present (deprecated)', () => {
|
|
101
|
+
const appDeclaration = {
|
|
102
|
+
visibility: 'public',
|
|
82
103
|
hidden: true,
|
|
83
104
|
};
|
|
84
|
-
const
|
|
85
|
-
|
|
105
|
+
const warningResult = {
|
|
106
|
+
errors: [],
|
|
107
|
+
warnings: [app_config_validators_1.ERROR_MESSAGES.deprecatedHiddenField],
|
|
86
108
|
};
|
|
87
109
|
const validationResult = (0, app_config_validators_1.visibilityValidator)(appDeclaration);
|
|
88
|
-
expect(validationResult).toEqual(
|
|
110
|
+
expect(validationResult).toEqual(warningResult);
|
|
89
111
|
});
|
|
90
|
-
|
|
112
|
+
});
|
|
113
|
+
describe('validateAccessGrants', () => {
|
|
114
|
+
it('should warn if app is set to public and "accessGrants" field is present', () => {
|
|
91
115
|
const appDeclaration = {
|
|
92
116
|
visibility: 'public',
|
|
117
|
+
accessGrants: [
|
|
118
|
+
{
|
|
119
|
+
orgSlug: 'org1',
|
|
120
|
+
permissions: ['install'],
|
|
121
|
+
},
|
|
122
|
+
],
|
|
93
123
|
};
|
|
94
|
-
const
|
|
95
|
-
|
|
124
|
+
const warningResult = {
|
|
125
|
+
errors: [],
|
|
126
|
+
warnings: [app_config_validators_1.ERROR_MESSAGES.ignoredAccessGrants],
|
|
127
|
+
};
|
|
128
|
+
const validationResult = (0, app_config_validators_1.validateAccessGrants)(appDeclaration);
|
|
129
|
+
expect(validationResult).toEqual(warningResult);
|
|
96
130
|
});
|
|
97
|
-
it('should
|
|
131
|
+
it('should return an error if app is private and "accessGrants" field is present but invalid', () => {
|
|
98
132
|
const appDeclaration = {
|
|
99
133
|
visibility: 'private',
|
|
100
|
-
|
|
134
|
+
accessGrants: [
|
|
135
|
+
{
|
|
136
|
+
orgSlug: '',
|
|
137
|
+
permissions: ['install'],
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
orgSlug: 'org2',
|
|
141
|
+
permissions: ['install'],
|
|
142
|
+
},
|
|
143
|
+
],
|
|
101
144
|
};
|
|
102
|
-
const
|
|
103
|
-
|
|
145
|
+
const expectedError = {
|
|
146
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.invalidOrgSlug],
|
|
147
|
+
warnings: [],
|
|
148
|
+
};
|
|
149
|
+
const validationResult = (0, app_config_validators_1.validateAccessGrants)(appDeclaration);
|
|
150
|
+
expect(validationResult).toEqual(expectedError);
|
|
151
|
+
});
|
|
152
|
+
it('should not return an error if app is private and "accessGrants" field is present and valid', () => {
|
|
153
|
+
const appDeclaration = {
|
|
154
|
+
visibility: 'private',
|
|
155
|
+
accessGrants: [
|
|
156
|
+
{
|
|
157
|
+
orgSlug: 'org1',
|
|
158
|
+
permissions: ['install'],
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
};
|
|
162
|
+
const validationResult = (0, app_config_validators_1.validateAccessGrants)(appDeclaration);
|
|
163
|
+
expect(validationResult).toEqual(validResult);
|
|
164
|
+
});
|
|
165
|
+
it('should return valid if accessGrants is an empty array', () => {
|
|
166
|
+
const appDeclaration = {
|
|
167
|
+
visibility: 'private',
|
|
168
|
+
accessGrants: [],
|
|
169
|
+
};
|
|
170
|
+
const validationResult = (0, app_config_validators_1.validateAccessGrants)(appDeclaration);
|
|
171
|
+
expect(validationResult).toEqual(validResult);
|
|
172
|
+
});
|
|
173
|
+
it('should return valid if accessGrants is an array with valid orgSlug and permissions', () => {
|
|
174
|
+
const appDeclaration = {
|
|
175
|
+
visibility: 'private',
|
|
176
|
+
accessGrants: [
|
|
177
|
+
{
|
|
178
|
+
orgSlug: 'org1',
|
|
179
|
+
permissions: ['install'],
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
};
|
|
183
|
+
const validationResult = (0, app_config_validators_1.validateAccessGrants)(appDeclaration);
|
|
184
|
+
expect(validationResult).toEqual(validResult);
|
|
185
|
+
});
|
|
186
|
+
it('should return invalid if accessGrants is not an array', () => {
|
|
187
|
+
const appDeclaration = {
|
|
188
|
+
visibility: 'private',
|
|
189
|
+
accessGrants: 'invalid',
|
|
190
|
+
};
|
|
191
|
+
const expectedError = {
|
|
192
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.accessGrantsArray],
|
|
193
|
+
warnings: [],
|
|
194
|
+
};
|
|
195
|
+
const validationResult = (0, app_config_validators_1.validateAccessGrants)(appDeclaration);
|
|
196
|
+
expect(validationResult).toEqual(expectedError);
|
|
197
|
+
});
|
|
198
|
+
it('should return invalid if orgSlug is missing in one of the accessGrants objects', () => {
|
|
199
|
+
const appDeclaration = {
|
|
200
|
+
visibility: 'private',
|
|
201
|
+
accessGrants: [
|
|
202
|
+
{
|
|
203
|
+
orgSlug: '',
|
|
204
|
+
permissions: ['install'],
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
orgSlug: 'org2',
|
|
208
|
+
permissions: ['install'],
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
};
|
|
212
|
+
const expectedError = {
|
|
213
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.invalidOrgSlug],
|
|
214
|
+
warnings: [],
|
|
215
|
+
};
|
|
216
|
+
const validationResult = (0, app_config_validators_1.validateAccessGrants)(appDeclaration);
|
|
217
|
+
expect(validationResult).toEqual(expectedError);
|
|
218
|
+
});
|
|
219
|
+
it('should return invalid if permissions is not an array or empty in one of the accessGrants objects', () => {
|
|
220
|
+
const appDeclaration = {
|
|
221
|
+
visibility: 'private',
|
|
222
|
+
accessGrants: [
|
|
223
|
+
{
|
|
224
|
+
orgSlug: 'org1',
|
|
225
|
+
permissions: 'invalid',
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
orgSlug: 'org2',
|
|
229
|
+
permissions: [],
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
};
|
|
233
|
+
const expectedError = {
|
|
234
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.emptyPermissionsArray, app_config_validators_1.ERROR_MESSAGES.emptyPermissionsArray],
|
|
235
|
+
warnings: [],
|
|
236
|
+
};
|
|
237
|
+
const validationResult = (0, app_config_validators_1.validateAccessGrants)(appDeclaration);
|
|
238
|
+
expect(validationResult).toEqual(expectedError);
|
|
239
|
+
});
|
|
240
|
+
it('should return invalid if invalid permission is found in one of the accessGrants objects', () => {
|
|
241
|
+
const appDeclaration = {
|
|
242
|
+
visibility: 'private',
|
|
243
|
+
accessGrants: [
|
|
244
|
+
{
|
|
245
|
+
orgSlug: 'org1',
|
|
246
|
+
permissions: ['install', 'invalid'],
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
orgSlug: 'org2',
|
|
250
|
+
permissions: ['install'],
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
};
|
|
254
|
+
const expectedError = {
|
|
255
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.invalidPermission('invalid')],
|
|
256
|
+
warnings: [],
|
|
257
|
+
};
|
|
258
|
+
const validationResult = (0, app_config_validators_1.validateAccessGrants)(appDeclaration);
|
|
259
|
+
expect(validationResult).toEqual(expectedError);
|
|
260
|
+
});
|
|
261
|
+
it('should return error if case-insensitive permission is found in accessGrants object', () => {
|
|
262
|
+
const appDeclaration = {
|
|
263
|
+
visibility: 'private',
|
|
264
|
+
accessGrants: [
|
|
265
|
+
{
|
|
266
|
+
orgSlug: 'org1',
|
|
267
|
+
permissions: ['Install'],
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
};
|
|
271
|
+
const expectedError = {
|
|
272
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.invalidPermission('Install')],
|
|
273
|
+
warnings: [],
|
|
274
|
+
};
|
|
275
|
+
const validationResult = (0, app_config_validators_1.validateAccessGrants)(appDeclaration);
|
|
276
|
+
expect(validationResult).toEqual(expectedError);
|
|
277
|
+
});
|
|
278
|
+
it('should return invalid if orgSlug is missing from the accessGrants object', () => {
|
|
279
|
+
const appDeclaration = {
|
|
280
|
+
visibility: 'private',
|
|
281
|
+
accessGrants: [
|
|
282
|
+
{
|
|
283
|
+
permissions: ['install'],
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
};
|
|
287
|
+
const expectedError = {
|
|
288
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.invalidOrgSlug],
|
|
289
|
+
warnings: [],
|
|
290
|
+
};
|
|
291
|
+
const validationResult = (0, app_config_validators_1.validateAccessGrants)(appDeclaration);
|
|
292
|
+
expect(validationResult).toEqual(expectedError);
|
|
293
|
+
});
|
|
294
|
+
it('should return invalid if permissions is missing from the accessGrants object', () => {
|
|
295
|
+
const appDeclaration = {
|
|
296
|
+
visibility: 'private',
|
|
297
|
+
accessGrants: [
|
|
298
|
+
{
|
|
299
|
+
orgSlug: 'org2',
|
|
300
|
+
},
|
|
301
|
+
],
|
|
302
|
+
};
|
|
303
|
+
const expectedError = {
|
|
304
|
+
errors: [app_config_validators_1.ERROR_MESSAGES.emptyPermissionsArray],
|
|
305
|
+
warnings: [],
|
|
306
|
+
};
|
|
307
|
+
const validationResult = (0, app_config_validators_1.validateAccessGrants)(appDeclaration);
|
|
308
|
+
expect(validationResult).toEqual(expectedError);
|
|
104
309
|
});
|
|
105
310
|
});
|
|
@@ -4,7 +4,6 @@ exports.createNodePackage = exports.AppDeployer = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const sdk_1 = require("@contrail/sdk");
|
|
6
6
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
|
-
const auth_1 = require("../../auth/auth");
|
|
8
7
|
const actions_deployer_1 = require("./actions-deployer");
|
|
9
8
|
const app_template_parsers_1 = require("./app-template-parsers");
|
|
10
9
|
const workflow_template_definition_deployer_1 = require("../workflow-template-definitions/workflow-template-definition-deployer");
|
|
@@ -43,8 +42,7 @@ class AppDeployer {
|
|
|
43
42
|
return app;
|
|
44
43
|
}
|
|
45
44
|
async getExistingApp(appDeclaration) {
|
|
46
|
-
const
|
|
47
|
-
const apps = await (0, apps_1.getAvailableApps)({ orgId });
|
|
45
|
+
const apps = await (0, apps_1.getAvailableApps)();
|
|
48
46
|
return apps.find((app) => app.identifier === appDeclaration.appIdentifier);
|
|
49
47
|
}
|
|
50
48
|
async createNewApp(appDeclaration) {
|
|
@@ -59,12 +57,16 @@ class AppDeployer {
|
|
|
59
57
|
if (appDeclaration?.triggers) {
|
|
60
58
|
triggerKeyDefinitions = app_template_parsers_1.TriggerKeyDefinitionParser.buildTriggersArray(appDeclaration);
|
|
61
59
|
}
|
|
60
|
+
let accessGrants = [];
|
|
61
|
+
if (appDeclaration?.accessGrants) {
|
|
62
|
+
accessGrants = await app_template_parsers_1.AccessGrantsParser.buildAccessGrants(appDeclaration);
|
|
63
|
+
}
|
|
62
64
|
const newApp = {
|
|
63
65
|
identifier: appDeclaration.appIdentifier,
|
|
64
66
|
name: appDeclaration.appName,
|
|
65
67
|
version: appDeclaration.version,
|
|
66
68
|
public: appDeclaration.visibility === 'public',
|
|
67
|
-
|
|
69
|
+
accessGrants,
|
|
68
70
|
description: appDeclaration.appDescription,
|
|
69
71
|
publisher: appDeclaration.publisher,
|
|
70
72
|
thumbnail: appDeclaration.thumbnail,
|
|
@@ -101,6 +103,10 @@ class AppDeployer {
|
|
|
101
103
|
if (appDeclaration?.triggers) {
|
|
102
104
|
triggerKeyDefinitions = app_template_parsers_1.TriggerKeyDefinitionParser.buildTriggersArray(appDeclaration);
|
|
103
105
|
}
|
|
106
|
+
let accessGrants = [];
|
|
107
|
+
if (appDeclaration?.accessGrants) {
|
|
108
|
+
accessGrants = await app_template_parsers_1.AccessGrantsParser.buildAccessGrants(appDeclaration);
|
|
109
|
+
}
|
|
104
110
|
// does appDeclaration have dockerImageRef
|
|
105
111
|
const isDocker = Object.hasOwnProperty.call(appDeclaration, 'dockerImageRef');
|
|
106
112
|
let appCodePackageId;
|
|
@@ -116,7 +122,7 @@ class AppDeployer {
|
|
|
116
122
|
name: appDeclaration.appName,
|
|
117
123
|
version: appDeclaration.version,
|
|
118
124
|
public: appDeclaration.visibility === 'public',
|
|
119
|
-
|
|
125
|
+
accessGrants,
|
|
120
126
|
description: appDeclaration.appDescription,
|
|
121
127
|
publisher: appDeclaration.publisher,
|
|
122
128
|
thumbnail: appDeclaration.thumbnail,
|
|
@@ -201,8 +207,7 @@ async function createNodePackage(appIdentifier, debug, dryRun) {
|
|
|
201
207
|
return {};
|
|
202
208
|
}
|
|
203
209
|
logger_1.default.info('Uploading package to S3...');
|
|
204
|
-
let apps = await entitiesClient.get({ entityName: 'app'
|
|
205
|
-
apps = apps.concat(await entitiesClient.get({ entityName: 'app', criteria: { private: true } }));
|
|
210
|
+
let apps = await entitiesClient.get({ entityName: 'app' });
|
|
206
211
|
const thisApp = apps.find((x) => x.identifier === appIdentifier);
|
|
207
212
|
if (!thisApp) {
|
|
208
213
|
throw new Error('App not found');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExternalLink } from '@contrail/entity-types';
|
|
2
|
-
import { AppDeclaration, TriggerKeyDefinition, ConfigPropertyElements } from '../../interfaces';
|
|
2
|
+
import { AppDeclaration, TriggerKeyDefinition, ConfigPropertyElements, CreateAppAccessGrantDTO } from '../../interfaces';
|
|
3
3
|
export declare class TriggerKeyDefinitionParser {
|
|
4
4
|
static buildTriggersArray(appDeclaration: AppDeclaration): Array<TriggerKeyDefinition>;
|
|
5
5
|
}
|
|
@@ -9,3 +9,6 @@ export declare class ConfigPropertiesParser {
|
|
|
9
9
|
export declare class ExternalLinkParser {
|
|
10
10
|
static validateAndGetExternalLinks(externalLinks: ExternalLink[]): ExternalLink[];
|
|
11
11
|
}
|
|
12
|
+
export declare class AccessGrantsParser {
|
|
13
|
+
static buildAccessGrants(appDeclaration: AppDeclaration): Promise<CreateAppAccessGrantDTO[]>;
|
|
14
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExternalLinkParser = exports.ConfigPropertiesParser = exports.TriggerKeyDefinitionParser = void 0;
|
|
3
|
+
exports.AccessGrantsParser = exports.ExternalLinkParser = exports.ConfigPropertiesParser = exports.TriggerKeyDefinitionParser = void 0;
|
|
4
|
+
const interfaces_1 = require("../../interfaces");
|
|
5
|
+
const sdk_1 = require("@contrail/sdk");
|
|
4
6
|
class TriggerKeyDefinitionParser {
|
|
5
7
|
static buildTriggersArray(appDeclaration) {
|
|
6
8
|
const triggers = [];
|
|
@@ -73,3 +75,31 @@ class ExternalLinkParser {
|
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
exports.ExternalLinkParser = ExternalLinkParser;
|
|
78
|
+
class AccessGrantsParser {
|
|
79
|
+
static async buildAccessGrants(appDeclaration) {
|
|
80
|
+
const accessGrants = [];
|
|
81
|
+
const currentUser = await (0, sdk_1.getCurrentUser)();
|
|
82
|
+
let currentOrgId = sdk_1.Auth.config.orgId;
|
|
83
|
+
if (!currentOrgId) {
|
|
84
|
+
let currentOrg = currentUser.orgs.find((o) => o.orgSlug === sdk_1.Auth.config.orgSlug);
|
|
85
|
+
currentOrgId = currentOrg.orgId;
|
|
86
|
+
}
|
|
87
|
+
for (const accessGrant of appDeclaration.accessGrants) {
|
|
88
|
+
const recipientOrg = currentUser.orgs.find((o) => o.orgSlug === accessGrant.orgSlug);
|
|
89
|
+
if (!recipientOrg) {
|
|
90
|
+
throw new Error(`You don't have access to the ${accessGrant.orgSlug} organization`);
|
|
91
|
+
}
|
|
92
|
+
if (recipientOrg.role !== 'ADMIN') {
|
|
93
|
+
throw new Error(`Only administrators of the ${accessGrant.orgSlug} organization can share the app`);
|
|
94
|
+
}
|
|
95
|
+
const grant = {
|
|
96
|
+
issuerReference: `org:${currentOrgId}`,
|
|
97
|
+
recipientReference: `org:${recipientOrg.orgId}`,
|
|
98
|
+
scope: interfaces_1.AppAccessGrantScope.install,
|
|
99
|
+
};
|
|
100
|
+
accessGrants.push(grant);
|
|
101
|
+
}
|
|
102
|
+
return accessGrants;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.AccessGrantsParser = AccessGrantsParser;
|
|
@@ -8,9 +8,6 @@ const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
|
8
8
|
const sdk_1 = require("@contrail/sdk");
|
|
9
9
|
const util_1 = require("@contrail/util");
|
|
10
10
|
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
11
|
-
const uuid_1 = require("uuid");
|
|
12
|
-
const pLimit = require('p-limit');
|
|
13
|
-
const limit = pLimit(30);
|
|
14
11
|
function getProjectFile(fileName) {
|
|
15
12
|
const CURRENT_DIR = process.cwd();
|
|
16
13
|
try {
|
|
@@ -55,7 +52,7 @@ async function getAssortmentsAndSubFolders(parentId, assortments, subFolders, al
|
|
|
55
52
|
workspaceId: parentId,
|
|
56
53
|
},
|
|
57
54
|
});
|
|
58
|
-
const integrationAssortments = workspaceAssortments
|
|
55
|
+
const integrationAssortments = workspaceAssortments; //?.filter(a => a.assortmentType === 'INTEGRATION');
|
|
59
56
|
if (integrationAssortments?.length > 0) {
|
|
60
57
|
allAssortments.push(...integrationAssortments);
|
|
61
58
|
for (const a of integrationAssortments) {
|
|
@@ -63,7 +60,7 @@ async function getAssortmentsAndSubFolders(parentId, assortments, subFolders, al
|
|
|
63
60
|
deleteNonUserKeys(integrationAssortmentsCopy);
|
|
64
61
|
const assortmentType = a.assortmentType === 'INTEGRATION' ? 'ASSORTMENT' : a.assortmentType;
|
|
65
62
|
const converted = {
|
|
66
|
-
identifier: a.identifier
|
|
63
|
+
identifier: a.identifier,
|
|
67
64
|
name: a.name,
|
|
68
65
|
type: assortmentType,
|
|
69
66
|
sourceAssortmentIdentifier: [],
|
|
@@ -85,18 +82,20 @@ async function getAssortmentsAndSubFolders(parentId, assortments, subFolders, al
|
|
|
85
82
|
relations: ['entity'],
|
|
86
83
|
});
|
|
87
84
|
const workspaceFolders = workspaceFolderLinks?.map((wfl) => wfl.entity);
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
85
|
+
if (workspaceFolders?.length > 0) {
|
|
86
|
+
for (const folder of workspaceFolders) {
|
|
87
|
+
const converted = {
|
|
88
|
+
identifier: folder.identifier,
|
|
89
|
+
name: folder.name,
|
|
90
|
+
principals: [],
|
|
91
|
+
assortments: [],
|
|
92
|
+
subFolders: [],
|
|
93
|
+
};
|
|
94
|
+
converted.principals = await getFolderPrincipals(folder);
|
|
95
|
+
await getAssortmentsAndSubFolders(folder.id, converted.assortments, converted.subFolders, allAssortments);
|
|
96
|
+
subFolders.push(converted);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
100
99
|
}
|
|
101
100
|
function convertRelationshipsInFolders(folder, allAssortments) {
|
|
102
101
|
if (!(allAssortments.length > 0)) {
|
|
@@ -160,10 +159,6 @@ function deleteNonUserKeys(assortment) {
|
|
|
160
159
|
delete assortment.updatedById;
|
|
161
160
|
delete assortment.updatedOn;
|
|
162
161
|
delete assortment.workspaceId;
|
|
163
|
-
delete assortment.itemTypeId;
|
|
164
|
-
if (assortment.itemType && typeof assortment.itemType === 'object') {
|
|
165
|
-
assortment.itemType = assortment.itemType?.typePath;
|
|
166
|
-
}
|
|
167
162
|
}
|
|
168
163
|
function saveData(data, name) {
|
|
169
164
|
const yamlStr = js_yaml_1.default.dump(data);
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface AppDeclaration {
|
|
|
8
8
|
appName: string;
|
|
9
9
|
appDescription?: string;
|
|
10
10
|
visibility: 'private' | 'public';
|
|
11
|
-
|
|
11
|
+
accessGrants?: AccessGrantConfiguration[];
|
|
12
12
|
publisher: string;
|
|
13
13
|
version: string;
|
|
14
14
|
eventWorkflowTriggerKeyMapping: string;
|
|
@@ -28,6 +28,24 @@ export interface AppDeclaration {
|
|
|
28
28
|
};
|
|
29
29
|
dockerImageRef?: string;
|
|
30
30
|
}
|
|
31
|
+
export interface AccessGrantConfiguration {
|
|
32
|
+
orgSlug: string;
|
|
33
|
+
permissions: AppAccessPermission[];
|
|
34
|
+
}
|
|
35
|
+
export type CreateAppAccessGrantDTO = {
|
|
36
|
+
issuerReference: string;
|
|
37
|
+
recipientReference: string;
|
|
38
|
+
scope: AppAccessGrantScope;
|
|
39
|
+
};
|
|
40
|
+
export interface AppAccessGrant extends CreateAppAccessGrantDTO {
|
|
41
|
+
appId: string;
|
|
42
|
+
}
|
|
43
|
+
export declare enum AppAccessGrantScope {
|
|
44
|
+
install = "INSTALL"
|
|
45
|
+
}
|
|
46
|
+
export declare enum AppAccessPermission {
|
|
47
|
+
INSTALL = "install"
|
|
48
|
+
}
|
|
31
49
|
export interface ExtensionDefinitionDeclaration {
|
|
32
50
|
name: string;
|
|
33
51
|
identifier: string;
|
|
@@ -193,6 +211,7 @@ export declare class AppVersion {
|
|
|
193
211
|
app?: App;
|
|
194
212
|
appOrgs?: AppOrg[];
|
|
195
213
|
versionNumber: number;
|
|
214
|
+
semver: string;
|
|
196
215
|
status: AppVersionStatus;
|
|
197
216
|
eventWorkflowTriggerKeyMapping: string;
|
|
198
217
|
configProperties?: ConfigProperty[];
|
package/dist/interfaces.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AssortmentConfigurationRelationships = exports.AssortmentConfigurationSlim = exports.FolderSlim = exports.ProjectConfigurationTemplate = exports.ProjectConfiguration = exports.Folder = exports.AssortmentConfiguration = exports.AssortmentType = exports.CommonConfiguration = exports.TriggerKeyDefinition = exports.ConfigProperty = exports.AppApiKey = exports.AppVersion = exports.AppRuntime = exports.AppVersionStatus = exports.AppOrgStatus = void 0;
|
|
3
|
+
exports.AssortmentConfigurationRelationships = exports.AssortmentConfigurationSlim = exports.FolderSlim = exports.ProjectConfigurationTemplate = exports.ProjectConfiguration = exports.Folder = exports.AssortmentConfiguration = exports.AssortmentType = exports.CommonConfiguration = exports.TriggerKeyDefinition = exports.ConfigProperty = exports.AppApiKey = exports.AppVersion = exports.AppRuntime = exports.AppVersionStatus = exports.AppOrgStatus = exports.AppAccessPermission = exports.AppAccessGrantScope = void 0;
|
|
4
|
+
var AppAccessGrantScope;
|
|
5
|
+
(function (AppAccessGrantScope) {
|
|
6
|
+
AppAccessGrantScope["install"] = "INSTALL";
|
|
7
|
+
})(AppAccessGrantScope = exports.AppAccessGrantScope || (exports.AppAccessGrantScope = {}));
|
|
8
|
+
var AppAccessPermission;
|
|
9
|
+
(function (AppAccessPermission) {
|
|
10
|
+
AppAccessPermission["INSTALL"] = "install";
|
|
11
|
+
})(AppAccessPermission = exports.AppAccessPermission || (exports.AppAccessPermission = {}));
|
|
4
12
|
var AppOrgStatus;
|
|
5
13
|
(function (AppOrgStatus) {
|
|
6
14
|
AppOrgStatus["INSTALLING"] = "INSTALLING";
|
|
@@ -36,6 +44,7 @@ class AppVersion {
|
|
|
36
44
|
app;
|
|
37
45
|
appOrgs;
|
|
38
46
|
versionNumber;
|
|
47
|
+
semver;
|
|
39
48
|
status;
|
|
40
49
|
eventWorkflowTriggerKeyMapping;
|
|
41
50
|
configProperties;
|
|
@@ -2,7 +2,12 @@ appIdentifier: "APP_IDENTIFIER_STUB" # Change to be your company root domain an
|
|
|
2
2
|
appName: "APP_NAME_STUB" # Give your app a name
|
|
3
3
|
appDescription: "APP_DESCRIPTION_STUB" # Give your app a description
|
|
4
4
|
visibility: private # This should be private unless you want to develop an app for all VibeIQ customers to use
|
|
5
|
-
|
|
5
|
+
# Access Grants
|
|
6
|
+
# Use this section to share this app with other organizations.
|
|
7
|
+
# accessGrants:
|
|
8
|
+
# - orgSlug: "ORG_SLUG"
|
|
9
|
+
# permissions:
|
|
10
|
+
# - install
|
|
6
11
|
publisher: "APP_PUBLISHER_STUB" # Your company name, used for public apps
|
|
7
12
|
version: "1.0.0"
|
|
8
13
|
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.4.0-alpha-0.1",
|
|
3
3
|
"commands": {
|
|
4
4
|
"app:create": {
|
|
5
5
|
"id": "app:create",
|
|
@@ -93,14 +93,6 @@
|
|
|
93
93
|
"description": "\"Install the app's accompanying workflows\"",
|
|
94
94
|
"required": false,
|
|
95
95
|
"allowNo": false
|
|
96
|
-
},
|
|
97
|
-
"showHidden": {
|
|
98
|
-
"name": "showHidden",
|
|
99
|
-
"type": "boolean",
|
|
100
|
-
"char": "h",
|
|
101
|
-
"description": "Show the option to install public but hidden apps",
|
|
102
|
-
"required": false,
|
|
103
|
-
"allowNo": false
|
|
104
96
|
}
|
|
105
97
|
},
|
|
106
98
|
"args": {}
|
|
@@ -537,14 +529,7 @@
|
|
|
537
529
|
"examples": [
|
|
538
530
|
"$ contrail project load <TEMPLATE_FILE_LOCATION>\n"
|
|
539
531
|
],
|
|
540
|
-
"flags": {
|
|
541
|
-
"dumpTransformedFile": {
|
|
542
|
-
"name": "dumpTransformedFile",
|
|
543
|
-
"type": "boolean",
|
|
544
|
-
"description": "If set to true, stores a transformed version of the template file",
|
|
545
|
-
"allowNo": false
|
|
546
|
-
}
|
|
547
|
-
},
|
|
532
|
+
"flags": {},
|
|
548
533
|
"args": {
|
|
549
534
|
"templateFileLocation": {
|
|
550
535
|
"name": "templateFileLocation",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0-alpha-0.1",
|
|
4
4
|
"description": "VibeIQ's Contrail Platform CLI.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"contrail-cli": "./bin/run",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@contrail/entity-types": "^1.1.17",
|
|
26
|
-
"@contrail/sdk": "^1.
|
|
26
|
+
"@contrail/sdk": "^1.3.12",
|
|
27
27
|
"@contrail/types": "^3.0.48",
|
|
28
28
|
"@contrail/util": "^1.0.41",
|
|
29
29
|
"@oclif/core": "^2",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"axios": "^1.3.5",
|
|
38
38
|
"chalk": "^4.0.0",
|
|
39
39
|
"command-line-usage": "^6.1.1",
|
|
40
|
+
"csv-parse": "^5.5.6",
|
|
40
41
|
"csvtojson": "^2.0.10",
|
|
41
42
|
"esm": "^3.2.25",
|
|
42
43
|
"execa": "^5.0.0",
|