@contrail/cli 3.6.0-alpha-8-alpha.694fd70 → 3.6.0-alpha-8-alpha.351376b
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 +80 -58
- package/dist/api/feature-flags.d.ts +3 -0
- package/dist/api/feature-flags.js +29 -0
- package/dist/api/users.d.ts +1 -0
- package/dist/api/users.js +10 -1
- package/dist/auth/login.js +41 -24
- package/dist/auth/login.spec.js +124 -0
- package/dist/basecommand.js +1 -1
- package/dist/commands/app/getApiKey.js +2 -2
- package/dist/commands/entities/create.d.ts +1 -12
- package/dist/commands/entities/create.js +30 -93
- package/dist/commands/entities/create.spec.js +3 -28
- package/dist/commands/entities/delete.d.ts +2 -5
- package/dist/commands/entities/delete.js +52 -68
- package/dist/commands/entities/get.d.ts +0 -3
- package/dist/commands/entities/get.js +15 -63
- package/dist/commands/entities/update.d.ts +2 -14
- package/dist/commands/entities/update.js +44 -77
- package/dist/commands/feature-flags/export.d.ts +19 -0
- package/dist/commands/feature-flags/export.js +66 -0
- package/dist/commands/feature-flags/export.spec.js +109 -0
- package/dist/commands/feature-flags/import.d.ts +42 -0
- package/dist/commands/feature-flags/import.js +191 -0
- package/dist/commands/feature-flags/import.spec.js +194 -0
- package/dist/commands/instance/export.d.ts +9 -0
- package/dist/commands/instance/export.js +18 -3
- package/dist/commands/instance/export.spec.js +32 -0
- package/dist/commands/instance/import.d.ts +3 -0
- package/dist/commands/instance/import.js +5 -0
- package/dist/commands/instance/import.spec.js +4 -0
- package/dist/common.d.ts +0 -2
- package/dist/common.js +1 -13
- package/dist/helpers/config/config.d.ts +2 -0
- package/dist/helpers/config/config.js +6 -1
- package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +0 -8
- package/dist/helpers/propertySpecifications/propertySpecifications.js +9 -21
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +10 -20
- package/dist/logger.js +1 -4
- package/node_modules/@contrail/entity-compare/package.json +3 -6
- package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
- package/node_modules/@contrail/loader/lib/constants.d.ts +8 -0
- package/node_modules/@contrail/loader/lib/constants.js +9 -1
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +4 -0
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +57 -0
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +492 -34
- package/node_modules/@contrail/loader/lib/pipeline/validate.js +2 -52
- package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +0 -85
- package/node_modules/@contrail/loader/package.json +2 -2
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +34 -0
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/image-search.js +42 -0
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/index.d.ts +1 -0
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/index.js +17 -0
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.d.ts +1 -0
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.js +1 -0
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/package.json +1 -1
- package/oclif.manifest.json +137 -99
- package/package.json +4 -1
- package/dist/commands/entities/grammar.spec.js +0 -80
- package/dist/commands/entities/output.spec.js +0 -72
- package/dist/logger.spec.js +0 -12
- /package/dist/commands/{entities/grammar.spec.d.ts → feature-flags/export.spec.d.ts} +0 -0
- /package/dist/commands/{entities/output.spec.d.ts → feature-flags/import.spec.d.ts} +0 -0
- /package/dist/{logger.spec.d.ts → commands/instance/export.spec.d.ts} +0 -0
|
@@ -6,17 +6,14 @@ const core_1 = require("@oclif/core");
|
|
|
6
6
|
const basecommand_1 = require("../../basecommand");
|
|
7
7
|
const sdk_1 = require("@contrail/sdk");
|
|
8
8
|
const login_1 = require("../../auth/login");
|
|
9
|
-
const common_1 = require("../../common");
|
|
10
9
|
const types_1 = require("../../api/types");
|
|
11
10
|
const propertySpecifications_1 = require("../../helpers/propertySpecifications/propertySpecifications");
|
|
12
11
|
const batchFetch_1 = require("../../helpers/entities/batchFetch");
|
|
13
12
|
let SHOULD_USE_PAGINATED_FIND = false;
|
|
14
13
|
let MAX_NUMBER_OF_ENTITIES_TO_FETCH = undefined;
|
|
15
14
|
class GetEntity extends basecommand_1.BaseCommand {
|
|
16
|
-
static description = 'Get an entity';
|
|
15
|
+
static description = '(BETA) Get an entity';
|
|
17
16
|
static examples = [
|
|
18
|
-
'contrail entities get color 123',
|
|
19
|
-
'contrail entities get color id1 id2 id3',
|
|
20
17
|
'contrail entities get color -- id=123',
|
|
21
18
|
'contrail entities get loader-processes -- createdOn=2025-09-15..2025-09-16',
|
|
22
19
|
'contrail entities get orders -- updatedAt=2025-09-15T04:00:00Z..',
|
|
@@ -62,53 +59,28 @@ class GetEntity extends basecommand_1.BaseCommand {
|
|
|
62
59
|
description: 'Comma-separated list of relations to include in the output',
|
|
63
60
|
required: false,
|
|
64
61
|
}),
|
|
65
|
-
suffix: core_1.Flags.string({
|
|
66
|
-
description: 'Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets /<entities>/synchronous)',
|
|
67
|
-
required: false,
|
|
68
|
-
}),
|
|
69
|
-
apiVersion: core_1.Flags.string({
|
|
70
|
-
description: 'Api-Version header to send; selects the V1 or V2 variant of the endpoint',
|
|
71
|
-
options: ['1', '2'],
|
|
72
|
-
required: false,
|
|
73
|
-
}),
|
|
74
62
|
};
|
|
75
63
|
static args = {
|
|
76
64
|
typePath: core_1.Args.string({
|
|
77
65
|
description: 'The name of the entity type to fetch',
|
|
78
66
|
required: true,
|
|
79
67
|
}),
|
|
80
|
-
ids: core_1.Args.string({
|
|
81
|
-
description: 'One or more entity ids; shorthand for the id/ids criteria',
|
|
82
|
-
required: false,
|
|
83
|
-
}),
|
|
84
68
|
};
|
|
85
69
|
static strict = false;
|
|
86
70
|
async run() {
|
|
87
|
-
(
|
|
71
|
+
this.log('🚨 This command is in BETA and may change or be removed at any time.');
|
|
88
72
|
await (0, login_1.authUser)();
|
|
89
73
|
const { args, flags, argv } = await this.parse(GetEntity);
|
|
90
74
|
const { typePath } = args;
|
|
91
|
-
const { outputFile, paginated: shouldUsePaginatedFind, propertySlugs, relations: relationString, skip, skipHydrateRelationships,
|
|
75
|
+
const { outputFile, paginated: shouldUsePaginatedFind, propertySlugs, relations: relationString, skip, skipHydrateRelationships, take, } = flags;
|
|
92
76
|
SHOULD_USE_PAGINATED_FIND = shouldUsePaginatedFind;
|
|
93
77
|
MAX_NUMBER_OF_ENTITIES_TO_FETCH = take;
|
|
94
78
|
if (MAX_NUMBER_OF_ENTITIES_TO_FETCH)
|
|
95
|
-
console.
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.error('Pass ids positionally or as -- id=/ids= criteria, not both.');
|
|
101
|
-
}
|
|
102
|
-
if (propertySpecBySlug.size > 0) {
|
|
103
|
-
this.error('Positional ids cannot be combined with other -- criteria. Use -- ids= alongside the other criteria instead.');
|
|
104
|
-
}
|
|
105
|
-
if (positionalIds.length === 1) {
|
|
106
|
-
propertySpecBySlug.set('id', positionalIds[0]);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
propertySpecBySlug.set('ids', positionalIds);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
79
|
+
console.log(`Will limit output to ${MAX_NUMBER_OF_ENTITIES_TO_FETCH} entities.`);
|
|
80
|
+
const propertySpecificationArgs = argv
|
|
81
|
+
.slice(1, argv.length)
|
|
82
|
+
.filter(propertySpecifications_1.isValidPropertySpecification);
|
|
83
|
+
const propertySpecBySlug = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(propertySpecificationArgs);
|
|
112
84
|
const relations = relationString
|
|
113
85
|
? relationString
|
|
114
86
|
.split(',')
|
|
@@ -129,8 +101,6 @@ class GetEntity extends basecommand_1.BaseCommand {
|
|
|
129
101
|
criteria: convertPropertySpecIntoCriteria(propertySpecBySlug),
|
|
130
102
|
skipHydrateRelationships,
|
|
131
103
|
skip,
|
|
132
|
-
suffix,
|
|
133
|
-
apiVersion: apiVersion,
|
|
134
104
|
relations,
|
|
135
105
|
propertySlugs: propertySlugsArray,
|
|
136
106
|
});
|
|
@@ -145,7 +115,7 @@ class GetEntity extends basecommand_1.BaseCommand {
|
|
|
145
115
|
}
|
|
146
116
|
writer.write('\n]\n');
|
|
147
117
|
if (outputFile)
|
|
148
|
-
|
|
118
|
+
this.log(`Output saved to ${outputFile}`);
|
|
149
119
|
}
|
|
150
120
|
else {
|
|
151
121
|
const response = await getEntityByTypePath(typePath, propertySpecBySlug, {
|
|
@@ -153,16 +123,11 @@ class GetEntity extends basecommand_1.BaseCommand {
|
|
|
153
123
|
relations,
|
|
154
124
|
propertySlugs: propertySlugsArray,
|
|
155
125
|
skip,
|
|
156
|
-
suffix,
|
|
157
|
-
apiVersion: apiVersion,
|
|
158
126
|
take,
|
|
159
127
|
});
|
|
160
|
-
if (response === null) {
|
|
161
|
-
this.error(`Entity not found: ${propertySpecBySlug.get('id')}`, { exit: 1 });
|
|
162
|
-
}
|
|
163
128
|
if (outputFile) {
|
|
164
129
|
fs_1.default.writeFileSync(outputFile, JSON.stringify(response, null, 2));
|
|
165
|
-
|
|
130
|
+
this.log(`Output saved to ${outputFile}`);
|
|
166
131
|
}
|
|
167
132
|
else {
|
|
168
133
|
this.log(JSON.stringify(response, null, 2));
|
|
@@ -170,16 +135,13 @@ class GetEntity extends basecommand_1.BaseCommand {
|
|
|
170
135
|
}
|
|
171
136
|
}
|
|
172
137
|
catch (e) {
|
|
173
|
-
if (e.message?.startsWith('Entity not found:')) {
|
|
174
|
-
throw e;
|
|
175
|
-
}
|
|
176
138
|
this.error(`Error fetching entity: ${e.message}`);
|
|
177
139
|
}
|
|
178
140
|
}
|
|
179
141
|
}
|
|
180
142
|
exports.default = GetEntity;
|
|
181
143
|
async function getEntityByTypePath(typePath, propertySpec, options = {}) {
|
|
182
|
-
const { propertySlugs, relations, skipHydrateRelationships, skip,
|
|
144
|
+
const { propertySlugs, relations, skipHydrateRelationships, skip, take } = options;
|
|
183
145
|
const id = propertySpec?.get('id')?.toString() || undefined;
|
|
184
146
|
const criteria = convertPropertySpecIntoCriteria(propertySpec || new Map());
|
|
185
147
|
const { root: entityName } = (0, types_1.parseTypePath)(typePath);
|
|
@@ -188,15 +150,11 @@ async function getEntityByTypePath(typePath, propertySpec, options = {}) {
|
|
|
188
150
|
}
|
|
189
151
|
return find(entityName, {
|
|
190
152
|
id,
|
|
191
|
-
// a missing id returns null (no retries); the command turns it into a clean not-found error
|
|
192
|
-
ignore404: id !== undefined,
|
|
193
153
|
skipHydrateRelationships,
|
|
194
154
|
relations,
|
|
195
155
|
propertySlugs,
|
|
196
156
|
criteria,
|
|
197
157
|
skip,
|
|
198
|
-
suffix,
|
|
199
|
-
apiVersion,
|
|
200
158
|
take,
|
|
201
159
|
});
|
|
202
160
|
}
|
|
@@ -209,24 +167,19 @@ function convertPropertySpecIntoCriteria(propertySpec) {
|
|
|
209
167
|
}
|
|
210
168
|
async function find(entityName, options = {}) {
|
|
211
169
|
const client = new sdk_1.Entities();
|
|
212
|
-
const { criteria, id,
|
|
170
|
+
const { criteria, id, propertySlugs, skipHydrateRelationships, relations, skip, take } = options;
|
|
213
171
|
const queryOptions = {
|
|
214
172
|
entityName,
|
|
215
|
-
ignore404,
|
|
216
173
|
skipHydrateRelationships,
|
|
217
174
|
relations,
|
|
218
175
|
skip,
|
|
219
|
-
suffix,
|
|
220
|
-
apiVersion,
|
|
221
176
|
take,
|
|
222
177
|
};
|
|
223
178
|
if (propertySlugs && propertySlugs.length > 0) {
|
|
224
179
|
queryOptions.customParams = { propertySlugs: propertySlugs.join(',') };
|
|
225
180
|
}
|
|
226
181
|
const payload = id ? { id, ...queryOptions } : { criteria, ...queryOptions };
|
|
227
|
-
|
|
228
|
-
// through the plain client (batch-fetch only understands criteria)
|
|
229
|
-
if ((0, batchFetch_1.canBatchFetchEntity)(entityName) && !suffix && !id) {
|
|
182
|
+
if ((0, batchFetch_1.canBatchFetchEntity)(entityName)) {
|
|
230
183
|
return (0, batchFetch_1.batchFetch)(entityName, payload);
|
|
231
184
|
}
|
|
232
185
|
else {
|
|
@@ -242,8 +195,7 @@ async function* streamPaginatedFind(typePath, options = {}) {
|
|
|
242
195
|
const opts = {
|
|
243
196
|
...options,
|
|
244
197
|
entityName,
|
|
245
|
-
|
|
246
|
-
apiVersion: options.apiVersion ?? sdk_1.API_VERSION.V2,
|
|
198
|
+
apiVersion: sdk_1.API_VERSION.V2,
|
|
247
199
|
nextPageKey,
|
|
248
200
|
};
|
|
249
201
|
if (options.propertySlugs?.length > 0) {
|
|
@@ -260,7 +212,7 @@ async function* streamPaginatedFind(typePath, options = {}) {
|
|
|
260
212
|
if (MAX_NUMBER_OF_ENTITIES_TO_FETCH && count >= MAX_NUMBER_OF_ENTITIES_TO_FETCH)
|
|
261
213
|
return;
|
|
262
214
|
}
|
|
263
|
-
console.
|
|
215
|
+
console.log(`Fetched ${count} entities`);
|
|
264
216
|
if (!nextPageKey || results.length === 0)
|
|
265
217
|
return;
|
|
266
218
|
}
|
|
@@ -6,26 +6,14 @@ export default class UpdateEntity extends BaseCommand {
|
|
|
6
6
|
skipHydrateRelationships: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
7
7
|
dryRun: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
8
8
|
inputFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
|
-
|
|
10
|
-
apiVersion: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
|
+
force: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
10
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
12
11
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
13
12
|
};
|
|
14
13
|
static args: {
|
|
15
14
|
entityName: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
16
|
-
|
|
15
|
+
id: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
17
16
|
};
|
|
18
17
|
static strict: boolean;
|
|
19
18
|
run(): Promise<void>;
|
|
20
19
|
}
|
|
21
|
-
export type UpdateSummary = {
|
|
22
|
-
updated: any[];
|
|
23
|
-
failed: {
|
|
24
|
-
id: string;
|
|
25
|
-
error: string;
|
|
26
|
-
}[];
|
|
27
|
-
skipped: number;
|
|
28
|
-
};
|
|
29
|
-
export declare function summarizeSettledUpdates(inputs: {
|
|
30
|
-
id: string;
|
|
31
|
-
}[], settled: PromiseSettledResult<any>[], skipped: number): UpdateSummary;
|
|
@@ -1,48 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.summarizeSettledUpdates = void 0;
|
|
4
3
|
const tslib_1 = require("tslib");
|
|
5
4
|
const p_limit_1 = tslib_1.__importDefault(require("p-limit"));
|
|
6
5
|
const core_1 = require("@oclif/core");
|
|
7
6
|
const basecommand_1 = require("../../basecommand");
|
|
8
7
|
const sdk_1 = require("@contrail/sdk");
|
|
9
8
|
const login_1 = require("../../auth/login");
|
|
10
|
-
const common_1 = require("../../common");
|
|
11
9
|
const propertySpecifications_1 = require("../../helpers/propertySpecifications/propertySpecifications");
|
|
12
10
|
const file_helpers_1 = require("../../helpers/file-helpers");
|
|
13
11
|
class UpdateEntity extends basecommand_1.BaseCommand {
|
|
14
|
-
static description = 'Update an entity';
|
|
12
|
+
static description = '(BETA) Update an entity';
|
|
15
13
|
static examples = [
|
|
16
14
|
'contrail entities update color 123 -- name=obsidian hex=000000',
|
|
17
|
-
'contrail entities update item id1 id2 id3 -- status=archived # apply the same change to several entities',
|
|
18
15
|
'contrail entities update color 123 -- description= notes=\'""\' # Unset description, set notes to empty string',
|
|
19
16
|
];
|
|
20
17
|
static flags = {
|
|
21
18
|
...basecommand_1.BaseCommand.baseFlags,
|
|
22
19
|
skipHydrateRelationships: core_1.Flags.boolean({
|
|
23
|
-
char: '
|
|
20
|
+
char: 's',
|
|
24
21
|
description: 'Skip hydrating relationships when updating the entity',
|
|
25
22
|
required: false,
|
|
26
23
|
default: false,
|
|
27
24
|
}),
|
|
28
25
|
dryRun: core_1.Flags.boolean({
|
|
29
26
|
char: 'd',
|
|
30
|
-
description: 'If true, does not
|
|
27
|
+
description: 'If true, does not create the entity but simulates the creation',
|
|
31
28
|
required: false,
|
|
32
29
|
default: false,
|
|
33
30
|
}),
|
|
34
31
|
inputFile: core_1.Flags.string({
|
|
35
32
|
char: 'i',
|
|
36
|
-
description: '
|
|
33
|
+
description: 'File containing properties to update the entity (optional)',
|
|
37
34
|
required: false,
|
|
38
35
|
}),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}),
|
|
43
|
-
apiVersion: core_1.Flags.string({
|
|
44
|
-
description: 'Api-Version header to send; selects the V1 or V2 variant of the endpoint',
|
|
45
|
-
options: ['1', '2'],
|
|
36
|
+
force: core_1.Flags.boolean({
|
|
37
|
+
char: 'F',
|
|
38
|
+
description: 'Force update without validation. Internal use only',
|
|
46
39
|
required: false,
|
|
47
40
|
}),
|
|
48
41
|
};
|
|
@@ -51,37 +44,33 @@ class UpdateEntity extends basecommand_1.BaseCommand {
|
|
|
51
44
|
description: 'The name of the entity type to update',
|
|
52
45
|
required: true,
|
|
53
46
|
}),
|
|
54
|
-
|
|
55
|
-
description: '
|
|
47
|
+
id: core_1.Args.string({
|
|
48
|
+
description: 'The unique identifier of the entity',
|
|
56
49
|
required: false,
|
|
57
50
|
}),
|
|
58
51
|
};
|
|
59
52
|
static strict = false;
|
|
60
53
|
async run() {
|
|
61
|
-
(
|
|
54
|
+
this.log('🚨 This command is in BETA and may change or be removed at any time.');
|
|
62
55
|
await (0, login_1.authUser)();
|
|
63
56
|
const { args, argv } = await this.parse(UpdateEntity);
|
|
64
|
-
const { entityName } = args;
|
|
65
|
-
const { dryRun: isDryRun, inputFile: inputFilename, skipHydrateRelationships,
|
|
66
|
-
const
|
|
67
|
-
const propertySpec = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
if (inputFilename && positionalIds.length > 0) {
|
|
72
|
-
this.error('You cannot use --inputFile and positional ids together. Please specify one or the other.');
|
|
73
|
-
}
|
|
74
|
-
if (!inputFilename && positionalIds.length === 0) {
|
|
75
|
-
this.error('You must provide one or more ids or an input file (-i) of entities to update.');
|
|
76
|
-
}
|
|
77
|
-
if (positionalIds.length > 0 && propertySpec.size === 0) {
|
|
78
|
-
this.error('Nothing to update: pass values to write after --, e.g. -- name=jet');
|
|
57
|
+
const { id: specifiedId, entityName } = args;
|
|
58
|
+
const { dryRun: isDryRun, inputFile: inputFilename, skipHydrateRelationships, force, } = this.flags;
|
|
59
|
+
const propertySpecArgs = argv.slice(1, argv.length).filter(propertySpecifications_1.isValidPropertySpecification);
|
|
60
|
+
const propertySpec = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(propertySpecArgs);
|
|
61
|
+
if (inputFilename && specifiedId) {
|
|
62
|
+
throw new Error('You cannot use --input and --id together. Please specify one or the other.');
|
|
79
63
|
}
|
|
80
64
|
const entitiesToUpdate = inputFilename
|
|
81
65
|
? (0, file_helpers_1.parseFileAsJsonArray)(inputFilename)
|
|
82
|
-
:
|
|
83
|
-
const
|
|
66
|
+
: [{ id: specifiedId }];
|
|
67
|
+
const results = {
|
|
68
|
+
idsSuccessfullyUpdated: new Set(),
|
|
69
|
+
idsFailedToUpdate: new Set(),
|
|
70
|
+
numEntriesSkipped: entitiesToUpdate.filter(({ id }) => !id).length,
|
|
71
|
+
};
|
|
84
72
|
const entitiesWithId = entitiesToUpdate.filter(({ id }) => id);
|
|
73
|
+
propertySpec.delete('id'); // Remove 'id' from the property spec if it exists
|
|
85
74
|
// will be applied to all entities
|
|
86
75
|
const fixedValues = [...propertySpec.entries()].reduce((acc, [key, value]) => {
|
|
87
76
|
acc[key] = value;
|
|
@@ -90,61 +79,39 @@ class UpdateEntity extends basecommand_1.BaseCommand {
|
|
|
90
79
|
async function updateEntity(entity) {
|
|
91
80
|
const newEntityState = { ...entity, ...fixedValues };
|
|
92
81
|
const id = entity.id;
|
|
93
|
-
|
|
82
|
+
const promise = isDryRun
|
|
94
83
|
? mockUpdateById(entityName, id, newEntityState, { skipHydrateRelationships })
|
|
95
|
-
: updateEntityById(entityName, id, newEntityState, {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
84
|
+
: updateEntityById(entityName, id, newEntityState, { skipHydrateRelationships, force });
|
|
85
|
+
promise
|
|
86
|
+
.catch(() => {
|
|
87
|
+
results.idsFailedToUpdate.add(id);
|
|
88
|
+
})
|
|
89
|
+
.then(() => {
|
|
90
|
+
results.idsSuccessfullyUpdated.add(id);
|
|
91
|
+
});
|
|
92
|
+
return promise;
|
|
100
93
|
}
|
|
101
94
|
try {
|
|
102
95
|
const limit = (0, p_limit_1.default)(20);
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
this.log(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
process.exitCode = 1;
|
|
112
|
-
}
|
|
96
|
+
const responses = await Promise.all(entitiesWithId.map((entity) => limit(() => updateEntity(entity))));
|
|
97
|
+
const messagePrefix = isDryRun
|
|
98
|
+
? 'Dry run. Update skipped. Changes would be:'
|
|
99
|
+
: 'Entity updated successfully:';
|
|
100
|
+
this.log(`${messagePrefix}\n\n${JSON.stringify(responses, null, 2)}`);
|
|
101
|
+
this.log(`\nIDs successfully updated: ${Array.from(results.idsSuccessfullyUpdated).join(', ')}`);
|
|
102
|
+
this.log(`IDs failed to update: ${Array.from(results.idsFailedToUpdate).join(', ')}`);
|
|
103
|
+
this.log(`Number of entries skipped due to missing IDs: ${results.numEntriesSkipped}`);
|
|
113
104
|
}
|
|
114
105
|
catch (e) {
|
|
115
|
-
this.error(`Error
|
|
106
|
+
this.error(`Error fetching entity: ${e.message}`);
|
|
116
107
|
}
|
|
117
108
|
}
|
|
118
109
|
}
|
|
119
110
|
exports.default = UpdateEntity;
|
|
120
|
-
function summarizeSettledUpdates(inputs, settled, skipped) {
|
|
121
|
-
const updated = [];
|
|
122
|
-
const failed = [];
|
|
123
|
-
settled.forEach((result, index) => {
|
|
124
|
-
if (result.status === 'fulfilled') {
|
|
125
|
-
updated.push(result.value);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
failed.push({
|
|
129
|
-
id: inputs[index].id,
|
|
130
|
-
error: (0, common_1.sdkErrorMessage)(result.reason),
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
return { updated, failed, skipped };
|
|
135
|
-
}
|
|
136
|
-
exports.summarizeSettledUpdates = summarizeSettledUpdates;
|
|
137
111
|
async function updateEntityById(entityName, id, changes, options = {}) {
|
|
138
112
|
const client = new sdk_1.Entities();
|
|
139
|
-
const { skipHydrateRelationships,
|
|
140
|
-
return client.update({
|
|
141
|
-
entityName,
|
|
142
|
-
id,
|
|
143
|
-
object: changes,
|
|
144
|
-
skipHydrateRelationships,
|
|
145
|
-
suffix,
|
|
146
|
-
apiVersion,
|
|
147
|
-
});
|
|
113
|
+
const { skipHydrateRelationships, force } = options;
|
|
114
|
+
return client.update({ entityName, id, object: changes, skipHydrateRelationships });
|
|
148
115
|
}
|
|
149
116
|
async function mockUpdateById(entityName, id, changes, options = {}) {
|
|
150
117
|
const client = new sdk_1.Entities();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseCommand } from '../../basecommand';
|
|
2
|
+
export declare const FEATURE_FLAGS_FILE = "feature-flags.yml";
|
|
3
|
+
export default class ExportFeatureFlags extends BaseCommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
outDir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
|
+
overwrite: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
10
|
+
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Writes the org's enabled feature flags to $outDir/feature-flags.yml as a list of
|
|
16
|
+
* `- featureName: X` entries. An org with no flags enabled still gets a file (an empty
|
|
17
|
+
* list), so the export stays a faithful snapshot of what is turned on.
|
|
18
|
+
*/
|
|
19
|
+
export declare function exportFeatureFlags(outDir: string, overwrite: boolean): Promise<void>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exportFeatureFlags = exports.FEATURE_FLAGS_FILE = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path = tslib_1.__importStar(require("path"));
|
|
6
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
8
|
+
const login_1 = require("../../auth/login");
|
|
9
|
+
const core_1 = require("@oclif/core");
|
|
10
|
+
const file_helpers_1 = require("../../helpers/file-helpers");
|
|
11
|
+
const error_helpers_1 = require("../../helpers/error-helpers");
|
|
12
|
+
const feature_flags_1 = require("../../api/feature-flags");
|
|
13
|
+
const basecommand_1 = require("../../basecommand");
|
|
14
|
+
exports.FEATURE_FLAGS_FILE = 'feature-flags.yml';
|
|
15
|
+
class ExportFeatureFlags extends basecommand_1.BaseCommand {
|
|
16
|
+
static description = 'Export the enabled feature flags for your Org';
|
|
17
|
+
static examples = [
|
|
18
|
+
`$ contrail feature-flags export
|
|
19
|
+
`,
|
|
20
|
+
];
|
|
21
|
+
static flags = {
|
|
22
|
+
...basecommand_1.BaseCommand.baseFlags,
|
|
23
|
+
outDir: core_1.Flags.string({
|
|
24
|
+
char: 'd',
|
|
25
|
+
description: 'The directory to which to export the feature flags. Defaults to the current directory',
|
|
26
|
+
required: false,
|
|
27
|
+
default: '.',
|
|
28
|
+
}),
|
|
29
|
+
overwrite: core_1.Flags.boolean({
|
|
30
|
+
char: 'f',
|
|
31
|
+
description: 'Replaces any existing export files in outDir',
|
|
32
|
+
required: false,
|
|
33
|
+
default: false,
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
async run() {
|
|
37
|
+
try {
|
|
38
|
+
await (0, login_1.authUser)();
|
|
39
|
+
this.log(`${chalk_1.default.blue.bold('START')} Getting Feature Flags.`);
|
|
40
|
+
this.log(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} Exporting`);
|
|
41
|
+
await exportFeatureFlags(this.flags.outDir, this.flags.overwrite);
|
|
42
|
+
this.log(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} Exported`);
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
this.log(`${chalk_1.default.red.bold('FAIL')} Feature Flags Export Failed. ${(0, error_helpers_1.describeError)(e)}`);
|
|
46
|
+
process.exitCode = 1;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.log(`${chalk_1.default.green.bold('COMPLETE')} Feature Flags Export Complete.`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.default = ExportFeatureFlags;
|
|
53
|
+
/**
|
|
54
|
+
* Writes the org's enabled feature flags to $outDir/feature-flags.yml as a list of
|
|
55
|
+
* `- featureName: X` entries. An org with no flags enabled still gets a file (an empty
|
|
56
|
+
* list), so the export stays a faithful snapshot of what is turned on.
|
|
57
|
+
*/
|
|
58
|
+
async function exportFeatureFlags(outDir, overwrite) {
|
|
59
|
+
const featureFlags = await (0, feature_flags_1.getFeatureFlags)();
|
|
60
|
+
const featureNames = [
|
|
61
|
+
...new Set((featureFlags ?? []).map((flag) => flag?.featureName).filter(Boolean)),
|
|
62
|
+
].sort();
|
|
63
|
+
fs_1.default.mkdirSync(path.resolve(outDir), { recursive: true });
|
|
64
|
+
await (0, file_helpers_1.saveData)(featureNames.map((featureName) => ({ featureName })), path.join(outDir, exports.FEATURE_FLAGS_FILE), overwrite);
|
|
65
|
+
}
|
|
66
|
+
exports.exportFeatureFlags = exportFeatureFlags;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
5
|
+
const export_1 = tslib_1.__importStar(require("./export"));
|
|
6
|
+
const file_helpers_1 = require("../../helpers/file-helpers");
|
|
7
|
+
const feature_flags_1 = require("../../api/feature-flags");
|
|
8
|
+
const login_1 = require("../../auth/login");
|
|
9
|
+
jest.mock('../../helpers/file-helpers');
|
|
10
|
+
jest.mock('../../api/feature-flags');
|
|
11
|
+
jest.mock('../../auth/login');
|
|
12
|
+
const mocked = (fn) => fn;
|
|
13
|
+
describe('exportFeatureFlags', () => {
|
|
14
|
+
let mkdirSyncSpy;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
jest.clearAllMocks();
|
|
17
|
+
mkdirSyncSpy = jest.spyOn(fs_1.default, 'mkdirSync').mockReturnValue(undefined);
|
|
18
|
+
mocked(file_helpers_1.saveData).mockResolvedValue(undefined);
|
|
19
|
+
});
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
mkdirSyncSpy.mockRestore();
|
|
22
|
+
});
|
|
23
|
+
it('writes the enabled flags sorted, without org specific fields', async () => {
|
|
24
|
+
mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([
|
|
25
|
+
{ id: '1', orgId: 'org-a', featureName: 'SHOWROOM' },
|
|
26
|
+
{ id: '2', orgId: 'org-a', featureName: 'DEV_TABS' },
|
|
27
|
+
]);
|
|
28
|
+
await (0, export_1.exportFeatureFlags)('out-dir', true);
|
|
29
|
+
expect(mocked(file_helpers_1.saveData)).toHaveBeenCalledWith([{ featureName: 'DEV_TABS' }, { featureName: 'SHOWROOM' }], 'out-dir/feature-flags.yml', true);
|
|
30
|
+
});
|
|
31
|
+
it('still writes a file when no flags are enabled, so the export is a full snapshot', async () => {
|
|
32
|
+
mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([]);
|
|
33
|
+
await (0, export_1.exportFeatureFlags)('out-dir', false);
|
|
34
|
+
expect(mocked(file_helpers_1.saveData)).toHaveBeenCalledWith([], 'out-dir/feature-flags.yml', false);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('ExportFeatureFlags command', () => {
|
|
38
|
+
let mkdirSyncSpy;
|
|
39
|
+
let logs;
|
|
40
|
+
// oclif's init() parses argv and reads the on-disk config, so drive run() with flags set directly
|
|
41
|
+
const runCommand = async () => {
|
|
42
|
+
const command = new export_1.default([], {});
|
|
43
|
+
command.flags = { outDir: 'out-dir', overwrite: true };
|
|
44
|
+
jest.spyOn(command, 'log').mockImplementation((message) => logs.push(String(message)));
|
|
45
|
+
await command.run();
|
|
46
|
+
};
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
jest.clearAllMocks();
|
|
49
|
+
logs = [];
|
|
50
|
+
process.exitCode = undefined;
|
|
51
|
+
mkdirSyncSpy = jest.spyOn(fs_1.default, 'mkdirSync').mockReturnValue(undefined);
|
|
52
|
+
mocked(login_1.authUser).mockResolvedValue({});
|
|
53
|
+
mocked(file_helpers_1.saveData).mockResolvedValue(undefined);
|
|
54
|
+
mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([]);
|
|
55
|
+
});
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
mkdirSyncSpy.mockRestore();
|
|
58
|
+
process.exitCode = undefined;
|
|
59
|
+
});
|
|
60
|
+
it('leaves the exit code alone on success', async () => {
|
|
61
|
+
await runCommand();
|
|
62
|
+
expect(process.exitCode).toBeUndefined();
|
|
63
|
+
expect(logs.join('\n')).toContain('Feature Flags Export Complete');
|
|
64
|
+
});
|
|
65
|
+
const failures = [
|
|
66
|
+
[
|
|
67
|
+
'authentication fails',
|
|
68
|
+
() => {
|
|
69
|
+
mocked(login_1.authUser).mockRejectedValue(new Error('boom'));
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
'the API read fails',
|
|
74
|
+
() => {
|
|
75
|
+
mocked(feature_flags_1.getFeatureFlags).mockRejectedValue(new Error('boom'));
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
[
|
|
79
|
+
'the directory cannot be created',
|
|
80
|
+
() => {
|
|
81
|
+
mkdirSyncSpy.mockImplementation(() => {
|
|
82
|
+
throw new Error('boom');
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
'the file write fails',
|
|
88
|
+
() => {
|
|
89
|
+
mocked(file_helpers_1.saveData).mockRejectedValue(new Error('boom'));
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
];
|
|
93
|
+
it.each(failures)('exits non-zero when %s, so automation does not read it as a success', async (_, fail) => {
|
|
94
|
+
fail();
|
|
95
|
+
await runCommand();
|
|
96
|
+
expect(process.exitCode).toBe(1);
|
|
97
|
+
const output = logs.join('\n');
|
|
98
|
+
expect(output).toContain('Feature Flags Export Failed');
|
|
99
|
+
expect(output).not.toContain('Feature Flags Export Complete');
|
|
100
|
+
});
|
|
101
|
+
it('reports the API message rather than a bare "Error"', async () => {
|
|
102
|
+
// the SDK's ApiError has an undefined message and keeps the body in details
|
|
103
|
+
mocked(feature_flags_1.getFeatureFlags).mockRejectedValue({
|
|
104
|
+
details: '{"message":"Forbidden resource","statusCode":403}',
|
|
105
|
+
});
|
|
106
|
+
await runCommand();
|
|
107
|
+
expect(logs.join('\n')).toContain('Forbidden resource');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BaseCommand } from '../../basecommand';
|
|
2
|
+
export declare const REQUIRED_PLATFORM_ROLES: string[];
|
|
3
|
+
export default class ImportFeatureFlags extends BaseCommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
dir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
|
+
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
|
+
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
10
|
+
};
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The feature flags API only lets a platform admin/manager create or delete flags, and a
|
|
15
|
+
* missing role surfaces as a generic 403 partway through the run. Checking up front stops
|
|
16
|
+
* the command before it half-applies the file.
|
|
17
|
+
*/
|
|
18
|
+
export declare function assertCanManageFeatureFlags(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* The `instance import` variant: feature flags are one step of a much larger config copy that
|
|
21
|
+
* org admins without a platform role are expected to run, so a missing role (or roles we could
|
|
22
|
+
* not read) logs and skips instead of failing the whole import. Errors from the flag upload
|
|
23
|
+
* itself still propagate — only the permission check is soft here.
|
|
24
|
+
*
|
|
25
|
+
* `contrail feature-flags import` deliberately does the opposite and fails, because there the
|
|
26
|
+
* flags are the entire point of the command.
|
|
27
|
+
*/
|
|
28
|
+
export declare function uploadFeatureFlagsIfPermitted(dir: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Makes the target org's enabled feature flags match $dir/feature-flags.yml: enables every
|
|
31
|
+
* flag in the file and disables any flag the target has that the file does not, the same
|
|
32
|
+
* way groups import reconciles groups. Feature flags are not editable in place, so there is
|
|
33
|
+
* no update step.
|
|
34
|
+
*
|
|
35
|
+
* Failures are collected and rethrown so an import never reports success while the org is
|
|
36
|
+
* missing flags.
|
|
37
|
+
*
|
|
38
|
+
* A file that lists no flags at all is skipped rather than applied: reconciling against an
|
|
39
|
+
* empty list would disable every flag in the target org, which is almost never what a copy
|
|
40
|
+
* is meant to do. Flags that should be off in the target have to be disabled by hand.
|
|
41
|
+
*/
|
|
42
|
+
export declare function uploadFeatureFlags(dir: string): Promise<void>;
|