@contrail/cli 3.5.5-alpha.5c010ac → 3.5.5-alpha.960e382
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 +1 -1
- package/dist/commands/feature-flags/import.d.ts +10 -0
- package/dist/commands/feature-flags/import.js +38 -7
- package/dist/commands/feature-flags/import.spec.js +49 -0
- package/dist/commands/instance/export.d.ts +9 -0
- package/dist/commands/instance/export.js +18 -3
- package/dist/commands/instance/export.spec.d.ts +1 -0
- 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/oclif.manifest.json +1 -1
- package/package.json +1 -1
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/3.5.5-alpha.
|
|
20
|
+
@contrail/cli/3.5.5-alpha.960e382 linux-x64 node-v24.21.0
|
|
21
21
|
$ contrail --help [COMMAND]
|
|
22
22
|
USAGE
|
|
23
23
|
$ contrail COMMAND
|
|
@@ -16,6 +16,16 @@ export default class ImportFeatureFlags extends BaseCommand {
|
|
|
16
16
|
* the command before it half-applies the file.
|
|
17
17
|
*/
|
|
18
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>;
|
|
19
29
|
/**
|
|
20
30
|
* Makes the target org's enabled feature flags match $dir/feature-flags.yml: enables every
|
|
21
31
|
* flag in the file and disables any flag the target has that the file does not, the same
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uploadFeatureFlags = exports.assertCanManageFeatureFlags = exports.REQUIRED_PLATFORM_ROLES = void 0;
|
|
3
|
+
exports.uploadFeatureFlags = exports.uploadFeatureFlagsIfPermitted = exports.assertCanManageFeatureFlags = exports.REQUIRED_PLATFORM_ROLES = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path = tslib_1.__importStar(require("path"));
|
|
6
6
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
@@ -48,26 +48,57 @@ class ImportFeatureFlags extends basecommand_1.BaseCommand {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
exports.default = ImportFeatureFlags;
|
|
51
|
+
async function getPlatformRoles() {
|
|
52
|
+
try {
|
|
53
|
+
const currentUser = await (0, users_1.getCurrentUserWithPlatformRoles)();
|
|
54
|
+
return normalizePlatformRoles(currentUser?.platformRoles);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
throw new Error(`Could not read your platform roles. ${(0, error_helpers_1.describeError)(e)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
51
60
|
/**
|
|
52
61
|
* The feature flags API only lets a platform admin/manager create or delete flags, and a
|
|
53
62
|
* missing role surfaces as a generic 403 partway through the run. Checking up front stops
|
|
54
63
|
* the command before it half-applies the file.
|
|
55
64
|
*/
|
|
56
65
|
async function assertCanManageFeatureFlags() {
|
|
66
|
+
const platformRoles = await getPlatformRoles();
|
|
67
|
+
if (!platformRoles.some((role) => exports.REQUIRED_PLATFORM_ROLES.includes(role))) {
|
|
68
|
+
throw new Error(`Importing feature flags requires the ${exports.REQUIRED_PLATFORM_ROLES.join(' or ')} platform role. ` +
|
|
69
|
+
`Your roles: ${platformRoles.length ? platformRoles.join(', ') : 'none'}.`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.assertCanManageFeatureFlags = assertCanManageFeatureFlags;
|
|
73
|
+
/**
|
|
74
|
+
* The `instance import` variant: feature flags are one step of a much larger config copy that
|
|
75
|
+
* org admins without a platform role are expected to run, so a missing role (or roles we could
|
|
76
|
+
* not read) logs and skips instead of failing the whole import. Errors from the flag upload
|
|
77
|
+
* itself still propagate — only the permission check is soft here.
|
|
78
|
+
*
|
|
79
|
+
* `contrail feature-flags import` deliberately does the opposite and fails, because there the
|
|
80
|
+
* flags are the entire point of the command.
|
|
81
|
+
*/
|
|
82
|
+
async function uploadFeatureFlagsIfPermitted(dir) {
|
|
57
83
|
let platformRoles;
|
|
58
84
|
try {
|
|
59
|
-
|
|
60
|
-
platformRoles = normalizePlatformRoles(currentUser?.platformRoles);
|
|
85
|
+
platformRoles = await getPlatformRoles();
|
|
61
86
|
}
|
|
62
87
|
catch (e) {
|
|
63
|
-
|
|
88
|
+
logger_1.default.info(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} Skipping feature flags: ${(0, error_helpers_1.describeError)(e)} ` +
|
|
89
|
+
`Ask a platform admin to run 'contrail feature-flags import -d ${dir}'.`);
|
|
90
|
+
return;
|
|
64
91
|
}
|
|
65
92
|
if (!platformRoles.some((role) => exports.REQUIRED_PLATFORM_ROLES.includes(role))) {
|
|
66
|
-
|
|
67
|
-
|
|
93
|
+
logger_1.default.info(`${chalk_1.default.yellow.bold('FEATURE FLAGS')} Skipping feature flags: this requires the ` +
|
|
94
|
+
`${exports.REQUIRED_PLATFORM_ROLES.join(' or ')} platform role and you have ` +
|
|
95
|
+
`${platformRoles.length ? platformRoles.join(', ') : 'none'}. ` +
|
|
96
|
+
`Ask a platform admin to run 'contrail feature-flags import -d ${dir}'.`);
|
|
97
|
+
return;
|
|
68
98
|
}
|
|
99
|
+
await uploadFeatureFlags(dir);
|
|
69
100
|
}
|
|
70
|
-
exports.
|
|
101
|
+
exports.uploadFeatureFlagsIfPermitted = uploadFeatureFlagsIfPermitted;
|
|
71
102
|
/**
|
|
72
103
|
* Makes the target org's enabled feature flags match $dir/feature-flags.yml: enables every
|
|
73
104
|
* flag in the file and disables any flag the target has that the file does not, the same
|
|
@@ -123,3 +123,52 @@ describe('uploadFeatureFlags', () => {
|
|
|
123
123
|
expect(mocked(feature_flags_1.createFeatureFlag)).toHaveBeenCalledWith('PROMOTE');
|
|
124
124
|
});
|
|
125
125
|
});
|
|
126
|
+
describe('uploadFeatureFlagsIfPermitted', () => {
|
|
127
|
+
let existsSyncSpy;
|
|
128
|
+
let infoSpy;
|
|
129
|
+
beforeEach(() => {
|
|
130
|
+
jest.clearAllMocks();
|
|
131
|
+
existsSyncSpy = jest.spyOn(fs_1.default, 'existsSync').mockReturnValue(true);
|
|
132
|
+
infoSpy = jest.spyOn(logger_1.default, 'info').mockImplementation(() => undefined);
|
|
133
|
+
mocked(file_helpers_1.loadData).mockReturnValue([{ featureName: 'SHOWROOM' }]);
|
|
134
|
+
mocked(feature_flags_1.createFeatureFlag).mockResolvedValue({});
|
|
135
|
+
mocked(feature_flags_1.deleteFeatureFlag).mockResolvedValue({});
|
|
136
|
+
mocked(feature_flags_1.getFeatureFlags).mockResolvedValue([]);
|
|
137
|
+
});
|
|
138
|
+
afterEach(() => {
|
|
139
|
+
existsSyncSpy.mockRestore();
|
|
140
|
+
infoSpy.mockRestore();
|
|
141
|
+
});
|
|
142
|
+
const messages = () => infoSpy.mock.calls.map(([message]) => String(message)).join('\n');
|
|
143
|
+
it('applies the flags when the user has a platform role', async () => {
|
|
144
|
+
mocked(users_1.getCurrentUserWithPlatformRoles).mockResolvedValue({
|
|
145
|
+
platformRoles: ['PLATFORM_MANAGER'],
|
|
146
|
+
});
|
|
147
|
+
await (0, import_1.uploadFeatureFlagsIfPermitted)('export-dir');
|
|
148
|
+
expect(mocked(feature_flags_1.createFeatureFlag)).toHaveBeenCalledWith('SHOWROOM');
|
|
149
|
+
});
|
|
150
|
+
it('skips with a log instead of failing when the user has no platform role', async () => {
|
|
151
|
+
mocked(users_1.getCurrentUserWithPlatformRoles).mockResolvedValue({ platformRoles: [] });
|
|
152
|
+
await expect((0, import_1.uploadFeatureFlagsIfPermitted)('export-dir')).resolves.toBeUndefined();
|
|
153
|
+
expect(mocked(feature_flags_1.getFeatureFlags)).not.toHaveBeenCalled();
|
|
154
|
+
expect(mocked(feature_flags_1.createFeatureFlag)).not.toHaveBeenCalled();
|
|
155
|
+
expect(mocked(feature_flags_1.deleteFeatureFlag)).not.toHaveBeenCalled();
|
|
156
|
+
expect(messages()).toContain('Skipping feature flags');
|
|
157
|
+
expect(messages()).toContain('PLATFORM_ADMIN or PLATFORM_MANAGER');
|
|
158
|
+
expect(messages()).toContain('contrail feature-flags import -d export-dir');
|
|
159
|
+
});
|
|
160
|
+
it('skips with a log when the platform roles cannot be read', async () => {
|
|
161
|
+
mocked(users_1.getCurrentUserWithPlatformRoles).mockRejectedValue(new Error('Forbidden resource'));
|
|
162
|
+
await expect((0, import_1.uploadFeatureFlagsIfPermitted)('export-dir')).resolves.toBeUndefined();
|
|
163
|
+
expect(mocked(feature_flags_1.createFeatureFlag)).not.toHaveBeenCalled();
|
|
164
|
+
expect(messages()).toContain('Skipping feature flags');
|
|
165
|
+
expect(messages()).toContain('Forbidden resource');
|
|
166
|
+
});
|
|
167
|
+
it('still propagates a failure from the upload itself', async () => {
|
|
168
|
+
mocked(users_1.getCurrentUserWithPlatformRoles).mockResolvedValue({
|
|
169
|
+
platformRoles: ['PLATFORM_ADMIN'],
|
|
170
|
+
});
|
|
171
|
+
mocked(feature_flags_1.createFeatureFlag).mockRejectedValue(new Error('boom'));
|
|
172
|
+
await expect((0, import_1.uploadFeatureFlagsIfPermitted)('export-dir')).rejects.toThrow('could not enable SHOWROOM: boom');
|
|
173
|
+
});
|
|
174
|
+
});
|
|
@@ -10,3 +10,12 @@ export default class ExportInstance extends BaseCommand {
|
|
|
10
10
|
};
|
|
11
11
|
run(): Promise<void>;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Exports everything `contrail instance import` loads back: types, users, groups and the
|
|
15
|
+
* org's enabled feature flags. Org config (branding, sorting, admin-console settings) is
|
|
16
|
+
* written by getAllTypes, so it is not repeated here.
|
|
17
|
+
*
|
|
18
|
+
* Exporting feature flags is a plain read, so it works for any user — only the import side
|
|
19
|
+
* needs a platform role.
|
|
20
|
+
*/
|
|
21
|
+
export declare function exportInstance(outDir: string, overwrite: boolean): Promise<void>;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exportInstance = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const path = tslib_1.__importStar(require("path"));
|
|
5
6
|
const core_1 = require("@oclif/core");
|
|
6
7
|
const getAll_1 = require("../types/getAll");
|
|
7
8
|
const export_1 = require("../users/export");
|
|
8
9
|
const export_2 = require("../groups/export");
|
|
10
|
+
const export_3 = require("../feature-flags/export");
|
|
9
11
|
const basecommand_1 = require("../../basecommand");
|
|
10
12
|
class ExportInstance extends basecommand_1.BaseCommand {
|
|
11
13
|
static description = 'Exports an data of an instance including types and users';
|
|
@@ -29,9 +31,22 @@ class ExportInstance extends basecommand_1.BaseCommand {
|
|
|
29
31
|
}),
|
|
30
32
|
};
|
|
31
33
|
async run() {
|
|
32
|
-
await (
|
|
33
|
-
await (0, export_1.exportUsers)(path.join(this.flags.outDir, 'users.yml'), this.flags.overwrite);
|
|
34
|
-
await (0, export_2.exportGroups)(path.join(this.flags.outDir, 'groups.yml'), this.flags.overwrite);
|
|
34
|
+
await exportInstance(this.flags.outDir, this.flags.overwrite);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
exports.default = ExportInstance;
|
|
38
|
+
/**
|
|
39
|
+
* Exports everything `contrail instance import` loads back: types, users, groups and the
|
|
40
|
+
* org's enabled feature flags. Org config (branding, sorting, admin-console settings) is
|
|
41
|
+
* written by getAllTypes, so it is not repeated here.
|
|
42
|
+
*
|
|
43
|
+
* Exporting feature flags is a plain read, so it works for any user — only the import side
|
|
44
|
+
* needs a platform role.
|
|
45
|
+
*/
|
|
46
|
+
async function exportInstance(outDir, overwrite) {
|
|
47
|
+
await (0, getAll_1.getAll)(outDir, overwrite);
|
|
48
|
+
await (0, export_1.exportUsers)(path.join(outDir, 'users.yml'), overwrite);
|
|
49
|
+
await (0, export_2.exportGroups)(path.join(outDir, 'groups.yml'), overwrite);
|
|
50
|
+
await (0, export_3.exportFeatureFlags)(outDir, overwrite);
|
|
51
|
+
}
|
|
52
|
+
exports.exportInstance = exportInstance;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const export_1 = require("./export");
|
|
4
|
+
const getAll_1 = require("../types/getAll");
|
|
5
|
+
const export_2 = require("../users/export");
|
|
6
|
+
const export_3 = require("../groups/export");
|
|
7
|
+
const export_4 = require("../feature-flags/export");
|
|
8
|
+
jest.mock('../types/getAll');
|
|
9
|
+
jest.mock('../users/export');
|
|
10
|
+
jest.mock('../groups/export');
|
|
11
|
+
jest.mock('../feature-flags/export');
|
|
12
|
+
const mocked = (fn) => fn;
|
|
13
|
+
const STEPS = [getAll_1.getAll, export_2.exportUsers, export_3.exportGroups, export_4.exportFeatureFlags];
|
|
14
|
+
describe('exportInstance', () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
jest.clearAllMocks();
|
|
17
|
+
for (const fn of STEPS) {
|
|
18
|
+
mocked(fn).mockResolvedValue(undefined);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
it('exports everything the import loads back, including feature flags', async () => {
|
|
22
|
+
await (0, export_1.exportInstance)('out-dir', true);
|
|
23
|
+
expect(mocked(getAll_1.getAll)).toHaveBeenCalledWith('out-dir', true);
|
|
24
|
+
expect(mocked(export_2.exportUsers)).toHaveBeenCalledWith('out-dir/users.yml', true);
|
|
25
|
+
expect(mocked(export_3.exportGroups)).toHaveBeenCalledWith('out-dir/groups.yml', true);
|
|
26
|
+
expect(mocked(export_4.exportFeatureFlags)).toHaveBeenCalledWith('out-dir', true);
|
|
27
|
+
});
|
|
28
|
+
it('passes the overwrite flag through to the feature flags export', async () => {
|
|
29
|
+
await (0, export_1.exportInstance)('out-dir', false);
|
|
30
|
+
expect(mocked(export_4.exportFeatureFlags)).toHaveBeenCalledWith('out-dir', false);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -17,6 +17,9 @@ export default class ImportInstance extends BaseCommand {
|
|
|
17
17
|
* 4. type overrides — after policies, because they reference policies, rule sets and option
|
|
18
18
|
* set hierarchies by slug and the API rejects the whole upload if any of them is missing
|
|
19
19
|
* 5. org config
|
|
20
|
+
* 6. feature flags — skipped with a log message when the user has no platform role,
|
|
21
|
+
* since applying them needs PLATFORM_ADMIN/PLATFORM_MANAGER but the rest of the
|
|
22
|
+
* import does not, and org admins are expected to run this command
|
|
20
23
|
*
|
|
21
24
|
* Fails (rejects) if the type overrides could not be applied, so the import does not
|
|
22
25
|
* report success while the org is missing customizations carried by overrides
|
|
@@ -11,6 +11,7 @@ const uploadTypePropertyPolicies_1 = require("../types/uploadTypePropertyPolicie
|
|
|
11
11
|
const uploadTypePolicies_1 = require("../types/uploadTypePolicies");
|
|
12
12
|
const uploadTypeOverrides_1 = require("../types/uploadTypeOverrides");
|
|
13
13
|
const import_3 = require("../org-config/import");
|
|
14
|
+
const import_4 = require("../feature-flags/import");
|
|
14
15
|
const basecommand_1 = require("../../basecommand");
|
|
15
16
|
class ImportInstance extends basecommand_1.BaseCommand {
|
|
16
17
|
static description = 'Import the data to an instance, including types and users';
|
|
@@ -40,6 +41,9 @@ exports.default = ImportInstance;
|
|
|
40
41
|
* 4. type overrides — after policies, because they reference policies, rule sets and option
|
|
41
42
|
* set hierarchies by slug and the API rejects the whole upload if any of them is missing
|
|
42
43
|
* 5. org config
|
|
44
|
+
* 6. feature flags — skipped with a log message when the user has no platform role,
|
|
45
|
+
* since applying them needs PLATFORM_ADMIN/PLATFORM_MANAGER but the rest of the
|
|
46
|
+
* import does not, and org admins are expected to run this command
|
|
43
47
|
*
|
|
44
48
|
* Fails (rejects) if the type overrides could not be applied, so the import does not
|
|
45
49
|
* report success while the org is missing customizations carried by overrides
|
|
@@ -53,5 +57,6 @@ async function importInstance(dir) {
|
|
|
53
57
|
await (0, uploadTypePolicies_1.uploadTypePolicies)(dir);
|
|
54
58
|
await (0, uploadTypeOverrides_1.uploadTypeOverrides)(dir);
|
|
55
59
|
await (0, import_3.uploadOrgConfig)(dir);
|
|
60
|
+
await (0, import_4.uploadFeatureFlagsIfPermitted)(dir);
|
|
56
61
|
}
|
|
57
62
|
exports.importInstance = importInstance;
|
|
@@ -8,6 +8,7 @@ const uploadTypePropertyPolicies_1 = require("../types/uploadTypePropertyPolicie
|
|
|
8
8
|
const uploadTypePolicies_1 = require("../types/uploadTypePolicies");
|
|
9
9
|
const uploadTypeOverrides_1 = require("../types/uploadTypeOverrides");
|
|
10
10
|
const import_4 = require("../org-config/import");
|
|
11
|
+
const import_5 = require("../feature-flags/import");
|
|
11
12
|
jest.mock('../types/loadAll');
|
|
12
13
|
jest.mock('../users/import');
|
|
13
14
|
jest.mock('../groups/import');
|
|
@@ -15,6 +16,7 @@ jest.mock('../types/uploadTypePropertyPolicies');
|
|
|
15
16
|
jest.mock('../types/uploadTypePolicies');
|
|
16
17
|
jest.mock('../types/uploadTypeOverrides');
|
|
17
18
|
jest.mock('../org-config/import');
|
|
19
|
+
jest.mock('../feature-flags/import');
|
|
18
20
|
const mocked = (fn) => fn;
|
|
19
21
|
const STEPS = [
|
|
20
22
|
loadAll_1.loadAll,
|
|
@@ -24,6 +26,7 @@ const STEPS = [
|
|
|
24
26
|
uploadTypePolicies_1.uploadTypePolicies,
|
|
25
27
|
uploadTypeOverrides_1.uploadTypeOverrides,
|
|
26
28
|
import_4.uploadOrgConfig,
|
|
29
|
+
import_5.uploadFeatureFlagsIfPermitted,
|
|
27
30
|
];
|
|
28
31
|
describe('importInstance', () => {
|
|
29
32
|
beforeEach(() => {
|
|
@@ -37,6 +40,7 @@ describe('importInstance', () => {
|
|
|
37
40
|
expect(mocked(loadAll_1.loadAll)).toHaveBeenCalledWith('export-dir', true, false);
|
|
38
41
|
expect(mocked(uploadTypeOverrides_1.uploadTypeOverrides)).toHaveBeenCalledWith('export-dir');
|
|
39
42
|
expect(mocked(import_4.uploadOrgConfig)).toHaveBeenCalledWith('export-dir');
|
|
43
|
+
expect(mocked(import_5.uploadFeatureFlagsIfPermitted)).toHaveBeenCalledWith('export-dir');
|
|
40
44
|
const order = STEPS.map((fn) => mocked(fn).mock.invocationCallOrder[0]);
|
|
41
45
|
// strictly increasing => called in exactly this order
|
|
42
46
|
for (let i = 1; i < order.length; i++) {
|
package/oclif.manifest.json
CHANGED