@contrail/cli 2.3.4 → 2.4.0-alpha
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 +2 -3
- 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 +2 -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/types/mergeOptionSets.js +3 -1
- package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +9 -7
- package/dist/commands/types/parseOptionSetsLocalFiles.js +33 -14
- package/dist/commands/types/uploadOptionSets.d.ts +1 -0
- package/dist/commands/types/uploadOptionSets.js +33 -20
- 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 +28 -1
- package/dist/helpers/types/parseOptionSetsLocalFiles.spec.d.ts +1 -0
- package/dist/helpers/types/parseOptionSetsLocalFiles.spec.js +285 -0
- package/dist/helpers/types/uploadOptionSets.spec.d.ts +1 -0
- package/dist/helpers/types/uploadOptionSets.spec.js +19 -0
- package/dist/helpers/workflow-template-definitions/workflow-template-definition-deployer.js +4 -0
- package/dist/helpers/workflow-templates/helper.js +4 -0
- package/dist/interfaces.d.ts +22 -1
- package/dist/interfaces.js +10 -1
- package/dist/templates/typescript/app.yml +10 -2
- package/oclif.manifest.json +1 -9
- package/package.json +3 -3
|
@@ -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, AppAccessGrant } 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<AppAccessGrant[]>;
|
|
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,28 @@ 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
|
+
const orgs = await new sdk_1.Entities().get({
|
|
88
|
+
entityName: 'org',
|
|
89
|
+
});
|
|
90
|
+
for (const accessGrant of appDeclaration.accessGrants) {
|
|
91
|
+
const recipientOrg = orgs.find((o) => o.slug === accessGrant.orgSlug);
|
|
92
|
+
const grant = {
|
|
93
|
+
issuerReference: `org:${currentOrgId}`,
|
|
94
|
+
recipientReference: `org:${recipientOrg.id}`,
|
|
95
|
+
scope: interfaces_1.AppAccessGrantScope.install,
|
|
96
|
+
};
|
|
97
|
+
accessGrants.push(grant);
|
|
98
|
+
}
|
|
99
|
+
return accessGrants;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.AccessGrantsParser = AccessGrantsParser;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|