@contrail/cli 2.0.3 → 2.0.4

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.
Files changed (31) hide show
  1. package/README.md +289 -186
  2. package/dist/commands/instance/export.d.ts +10 -0
  3. package/dist/commands/instance/export.js +24 -0
  4. package/dist/commands/instance/import.d.ts +9 -0
  5. package/dist/commands/instance/import.js +23 -0
  6. package/dist/commands/types/getAll.d.ts +5 -1
  7. package/dist/commands/types/getAll.js +31 -11
  8. package/dist/commands/types/loadAll.d.ts +5 -2
  9. package/dist/commands/types/loadAll.js +17 -13
  10. package/dist/commands/types/uploadOptionSetHierarchies.d.ts +4 -1
  11. package/dist/commands/types/uploadOptionSetHierarchies.js +13 -9
  12. package/dist/commands/types/uploadOptionSets.d.ts +4 -1
  13. package/dist/commands/types/uploadOptionSets.js +13 -9
  14. package/dist/commands/types/uploadRuleSets.d.ts +4 -1
  15. package/dist/commands/types/uploadRuleSets.js +12 -8
  16. package/dist/commands/types/uploadTypePropertyPolicies.d.ts +4 -1
  17. package/dist/commands/types/uploadTypePropertyPolicies.js +12 -8
  18. package/dist/commands/types/uploadUsageInfo.d.ts +4 -1
  19. package/dist/commands/types/uploadUsageInfo.js +9 -6
  20. package/dist/commands/users/export.d.ts +2 -0
  21. package/dist/commands/users/export.js +14 -6
  22. package/dist/commands/users/upload.d.ts +1 -0
  23. package/dist/commands/users/upload.js +2 -0
  24. package/dist/helpers/file-helpers.d.ts +1 -0
  25. package/dist/helpers/file-helpers.js +23 -0
  26. package/dist/helpers/types/type-uploader.d.ts +1 -1
  27. package/dist/helpers/types/type-uploader.js +8 -8
  28. package/dist/templates/typescript/src/actions/logItem.ts +3 -8
  29. package/dist/templates/typescript/src/framework/app-config.ts +1 -4
  30. package/oclif.manifest.json +147 -11
  31. package/package.json +8 -3
@@ -0,0 +1,10 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class ExportInstance extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ outDir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ overwrite: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
+ };
9
+ run(): Promise<void>;
10
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const path = tslib_1.__importStar(require("path"));
5
+ const core_1 = require("@oclif/core");
6
+ const getAll_1 = require("../types/getAll");
7
+ const export_1 = require("../users/export");
8
+ class ExportInstance extends core_1.Command {
9
+ async run() {
10
+ const { flags } = await this.parse(ExportInstance);
11
+ await (0, getAll_1.getAll)(flags.outDir, flags.overwrite);
12
+ await (0, export_1.exportUsers)(path.join(flags.outDir, 'users.yml'), flags.overwrite);
13
+ }
14
+ }
15
+ exports.default = ExportInstance;
16
+ ExportInstance.description = 'Exports an data of an instance including types and users';
17
+ ExportInstance.examples = [
18
+ `$ contrail instance export
19
+ `,
20
+ ];
21
+ ExportInstance.flags = {
22
+ outDir: core_1.Flags.string({ description: 'The directory to which to export the instance data. Defaults to the current directory', required: false, default: '.' }),
23
+ overwrite: core_1.Flags.boolean({ description: 'Replaces any existing export files in outDir', required: false, default: false })
24
+ };
@@ -0,0 +1,9 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class ImportInstance extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ dir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ };
8
+ run(): Promise<void>;
9
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const path = tslib_1.__importStar(require("path"));
5
+ const core_1 = require("@oclif/core");
6
+ const loadAll_1 = require("../types/loadAll");
7
+ const upload_1 = require("../users/upload");
8
+ class ImportInstance extends core_1.Command {
9
+ async run() {
10
+ const { flags } = await this.parse(ImportInstance);
11
+ await (0, loadAll_1.loadAll)(flags.dir);
12
+ await (0, upload_1.uploadUsers)(path.join(flags.dir, 'users.yml'));
13
+ }
14
+ }
15
+ exports.default = ImportInstance;
16
+ ImportInstance.description = 'Import the data to an instance, including types and users';
17
+ ImportInstance.examples = [
18
+ `$ contrail instance import
19
+ `,
20
+ ];
21
+ ImportInstance.flags = {
22
+ dir: core_1.Flags.string({ description: 'The directory from which to export the instance data. Defaults to the current directory', required: false, default: '.' }),
23
+ };
@@ -22,8 +22,12 @@ export interface ReducedDataHolder {
22
22
  export default class GetAllTypes extends Command {
23
23
  static description: string;
24
24
  static examples: string[];
25
+ static flags: {
26
+ outDir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
27
+ overwrite: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
28
+ };
25
29
  run(): Promise<void>;
26
30
  }
27
- export declare function getAll(): Promise<void>;
31
+ export declare function getAll(outDir: string, overwrite: boolean): Promise<void>;
28
32
  export declare function reduceTypes(dataHolder: DataHolder): any[];
29
33
  export declare function reduceData(data: DataHolder): ReducedDataHolder;
@@ -9,10 +9,12 @@ const login_1 = require("../../auth/login");
9
9
  const path = tslib_1.__importStar(require("path"));
10
10
  const type_extractor_1 = require("../../helpers/types/type-extractor");
11
11
  const types_1 = require("../../api/types");
12
+ const file_helpers_1 = require("../../helpers/file-helpers");
12
13
  const yaml = require('js-yaml');
13
14
  class GetAllTypes extends core_1.Command {
14
15
  async run() {
15
- await getAll();
16
+ const { flags } = await this.parse(GetAllTypes);
17
+ await getAll(flags.outDir, flags.overwrite);
16
18
  }
17
19
  }
18
20
  exports.default = GetAllTypes;
@@ -21,13 +23,18 @@ GetAllTypes.examples = [
21
23
  `$ contrail types getAll
22
24
  `,
23
25
  ];
24
- async function getAll() {
26
+ GetAllTypes.flags = {
27
+ outDir: core_1.Flags.string({ description: 'The directory to which to export the type data. Defaults to the current directory', required: false, default: '.' }),
28
+ overwrite: core_1.Flags.boolean({ description: 'Replaces any existing export files in outDir', required: false, default: false })
29
+ };
30
+ async function getAll(outDir, overwrite) {
25
31
  try {
26
32
  const userConfig = await (0, login_1.authUser)();
27
33
  console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk_1.default.blue.bold('START'));
28
34
  // make directory to house exports
29
- const dir = `./contrail-export-${Date.now()}`;
30
- fs_1.default.mkdirSync(dir);
35
+ if (!fs_1.default.existsSync(path.resolve(outDir))) {
36
+ fs_1.default.mkdirSync(path.resolve(outDir));
37
+ }
31
38
  const data = {
32
39
  types: await (0, type_extractor_1.getTypes)(),
33
40
  optionSets: await (0, types_1.getOptionSets)(),
@@ -39,7 +46,7 @@ async function getAll() {
39
46
  typePropertyPolicyLinks: await (0, types_1.getTypePropertyPolicyLinks)(),
40
47
  };
41
48
  const reducedData = reduceData(data);
42
- saveData(reducedData, dir);
49
+ await saveData(reducedData, outDir, overwrite);
43
50
  console.log('%s Retrieved', chalk_1.default.yellow.bold('TYPES'));
44
51
  }
45
52
  catch (e) {
@@ -196,7 +203,7 @@ function reduceData(data) {
196
203
  };
197
204
  }
198
205
  exports.reduceData = reduceData;
199
- const saveTypesFunction = function (data, dir) {
206
+ const saveTypesFunction = async (data, dir, overwrite) => {
200
207
  const roots = {};
201
208
  for (const type of data.reducedTypes) {
202
209
  const typePathParts = type.typePath.split(':');
@@ -222,10 +229,14 @@ const saveTypesFunction = function (data, dir) {
222
229
  if (!fileLabel) {
223
230
  console.warn('skipping bad type root:', root);
224
231
  }
225
- fs_1.default.writeFileSync(path.join(subDir, `${removeSlash(fileLabel)}.yml`), yamlStr, 'utf8');
232
+ const pathToWrite = path.join(subDir, `${removeSlash(fileLabel)}.yml`);
233
+ if (fs_1.default.existsSync(pathToWrite)) {
234
+ await (0, file_helpers_1.safeFileOverwrite)(pathToWrite, overwrite);
235
+ }
236
+ fs_1.default.writeFileSync(pathToWrite, yamlStr, 'utf8');
226
237
  }
227
238
  };
228
- function saveData(reducedData, dir) {
239
+ async function saveData(reducedData, dir, overwrite) {
229
240
  const propertyToFolderMap = {
230
241
  reducedTypes: { filename: 'types', split: false, fileLabel: 'slug', saveFunction: saveTypesFunction },
231
242
  reducedOptionSets: { filename: 'option-sets', split: true, fileLabel: 'name' },
@@ -239,7 +250,7 @@ function saveData(reducedData, dir) {
239
250
  for (const [key, folder] of Object.entries(propertyToFolderMap)) {
240
251
  const CURRENT_DIR = process.cwd();
241
252
  if (folder['saveFunction']) {
242
- folder['saveFunction'](reducedData, dir);
253
+ await folder['saveFunction'](reducedData, dir, overwrite);
243
254
  }
244
255
  else if (folder.split) {
245
256
  const subDir = path.join(CURRENT_DIR, dir, folder.filename);
@@ -251,13 +262,22 @@ function saveData(reducedData, dir) {
251
262
  const fileLabel = item[folder.fileLabel];
252
263
  if (!fileLabel) {
253
264
  console.warn('skipping bad data:', item);
265
+ continue;
254
266
  }
255
- fs_1.default.writeFileSync(path.join(subDir, `${removeSlash(fileLabel)}.yml`), yamlStr, 'utf8');
267
+ const pathToWrite = path.join(subDir, `${removeSlash(fileLabel)}.yml`);
268
+ if (fs_1.default.existsSync(pathToWrite)) {
269
+ await (0, file_helpers_1.safeFileOverwrite)(pathToWrite, overwrite);
270
+ }
271
+ fs_1.default.writeFileSync(pathToWrite, yamlStr, 'utf8');
256
272
  }
257
273
  }
258
274
  else {
259
275
  const yamlStr = yaml.dump(reducedData[key]);
260
- fs_1.default.writeFileSync(path.join(CURRENT_DIR, dir, `${folder.filename}.yml`), yamlStr, 'utf8');
276
+ const pathToWrite = path.join(CURRENT_DIR, dir, `${folder.filename}.yml`);
277
+ if (fs_1.default.existsSync(pathToWrite)) {
278
+ await (0, file_helpers_1.safeFileOverwrite)(pathToWrite, overwrite);
279
+ }
280
+ fs_1.default.writeFileSync(pathToWrite, yamlStr, 'utf8');
261
281
  }
262
282
  }
263
283
  }
@@ -1,7 +1,10 @@
1
1
  import { Command } from '@oclif/core';
2
- export default class GetAllTypes extends Command {
2
+ export default class LoadAllTypes extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
5
+ static flags: {
6
+ dir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ };
5
8
  run(): Promise<void>;
6
9
  }
7
- export declare function loadAll(): Promise<void>;
10
+ export declare function loadAll(dir: string): Promise<void>;
@@ -11,26 +11,30 @@ const uploadUsageInfo_1 = require("./uploadUsageInfo");
11
11
  const uploadRuleSets_1 = require("./uploadRuleSets");
12
12
  const uploadTypePropertyPolicies_1 = require("./uploadTypePropertyPolicies");
13
13
  const type_uploader_1 = require("../../helpers/types/type-uploader");
14
- class GetAllTypes extends core_1.Command {
14
+ class LoadAllTypes extends core_1.Command {
15
15
  async run() {
16
- await loadAll();
16
+ const { flags } = await this.parse(LoadAllTypes);
17
+ await loadAll(flags.dir);
17
18
  }
18
19
  }
19
- exports.default = GetAllTypes;
20
- GetAllTypes.description = 'Get all Types and associated data for your Org';
21
- GetAllTypes.examples = [
22
- `$ contrail types getAll
20
+ exports.default = LoadAllTypes;
21
+ LoadAllTypes.description = 'loads all the type data that has been exported by getAll';
22
+ LoadAllTypes.examples = [
23
+ `$ contrail types loadAll
23
24
  `,
24
25
  ];
25
- async function loadAll() {
26
+ LoadAllTypes.flags = {
27
+ dir: core_1.Flags.string({ char: 'd', description: 'The directory from which to load the types data. Defaults to the current directory.', required: false, default: '.' }),
28
+ };
29
+ async function loadAll(dir) {
26
30
  try {
27
31
  await (0, login_1.authUser)();
28
- await (0, uploadOptionSets_1.uploadOptionSets)();
29
- await (0, uploadOptionSetHierarchies_1.uploadOptionSetHierarchies)();
30
- await (0, type_uploader_1.uploadTypes)();
31
- await (0, uploadUsageInfo_1.uploadUsageInfo)();
32
- await (0, uploadRuleSets_1.uploadRuleSets)();
33
- await (0, uploadTypePropertyPolicies_1.uploadTypePropertyPolicies)();
32
+ await (0, uploadOptionSets_1.uploadOptionSets)(dir);
33
+ await (0, uploadOptionSetHierarchies_1.uploadOptionSetHierarchies)(dir);
34
+ await (0, type_uploader_1.uploadTypes)(dir);
35
+ await (0, uploadUsageInfo_1.uploadUsageInfo)(dir);
36
+ await (0, uploadRuleSets_1.uploadRuleSets)(dir);
37
+ await (0, uploadTypePropertyPolicies_1.uploadTypePropertyPolicies)(dir);
34
38
  }
35
39
  catch (e) {
36
40
  console.log(`%s Types Upload Failed. ${e}`, chalk_1.default.red.bold('FAIL'));
@@ -2,6 +2,9 @@ import { Command } from '@oclif/core';
2
2
  export default class UploadOptionSetHierarchies extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
5
+ static flags: {
6
+ dir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ };
5
8
  run(): Promise<void>;
6
9
  }
7
- export declare function uploadOptionSetHierarchies(): Promise<void>;
10
+ export declare function uploadOptionSetHierarchies(dir: string): Promise<void>;
@@ -11,20 +11,24 @@ const core_1 = require("@oclif/core");
11
11
  const yaml = require('js-yaml');
12
12
  class UploadOptionSetHierarchies extends core_1.Command {
13
13
  async run() {
14
- return await uploadOptionSetHierarchies();
14
+ const { flags } = await this.parse(UploadOptionSetHierarchies);
15
+ return await uploadOptionSetHierarchies(flags.dir);
15
16
  }
16
17
  }
17
18
  exports.default = UploadOptionSetHierarchies;
18
- UploadOptionSetHierarchies.description = 'Upload OptionSets for your Org. OptionSets are loaded from .yml files in the option-sets directory.';
19
+ UploadOptionSetHierarchies.description = 'Upload Option Set Hierarchies for your Org. Option set hierarchies are loaded from .yml files in the option-set-hierarchies directory.';
19
20
  UploadOptionSetHierarchies.examples = [
20
21
  `$ contrail types uploadOptionSetHierarchies
21
22
  `,
22
23
  ];
23
- async function uploadOptionSetHierarchies() {
24
+ UploadOptionSetHierarchies.flags = {
25
+ dir: core_1.Flags.string({ char: 'd', description: 'The directory from which to export the option set hierarchies data. Defaults to the current directory. The option set data will be loaded from $dir/option-set-hierarchies', required: false, default: '.' }),
26
+ };
27
+ async function uploadOptionSetHierarchies(dir) {
24
28
  try {
25
29
  await (0, login_1.authUser)();
26
30
  console.log('%s Uploading', chalk_1.default.yellow.bold('OPTION SET HIERARCHIES'));
27
- const optionSetHierarchies = await loadOptionSetHierarchies();
31
+ const optionSetHierarchies = await loadOptionSetHierarchies(dir);
28
32
  await uploadOSH(optionSetHierarchies);
29
33
  console.log('%s Uploaded', chalk_1.default.yellow.bold('OPTION SET HIERARCHIES'));
30
34
  }
@@ -35,13 +39,13 @@ async function uploadOptionSetHierarchies() {
35
39
  console.log('%s Option set hierarchy Upload Complete.', chalk_1.default.green.bold('COMPLETE'));
36
40
  }
37
41
  exports.uploadOptionSetHierarchies = uploadOptionSetHierarchies;
38
- function loadOptionSetHierarchies() {
39
- const TARGET_DIR = process.cwd();
42
+ function loadOptionSetHierarchies(fromDir) {
40
43
  try {
41
- const files = fs_1.default.readdirSync(path.join(TARGET_DIR, 'option-set-hierarchies'));
44
+ const dir = path.resolve(path.join(fromDir, 'option-set-hierarchies'));
45
+ const files = fs_1.default.readdirSync(dir);
42
46
  const OSHs = [];
43
47
  for (const file of files) {
44
- OSHs.push(yaml.load(fs_1.default.readFileSync(path.join(TARGET_DIR, 'option-set-hierarchies', file), 'utf8')));
48
+ OSHs.push(yaml.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
45
49
  }
46
50
  return OSHs;
47
51
  }
@@ -117,7 +121,7 @@ async function uploadOSH(loadedOSHs) {
117
121
  }
118
122
  // transforms the passed hierarchy from names to ids, and returns true if operation succeeded.
119
123
  function transformOSHNameToID(hierarchy, optionSets) {
120
- console.log('passed hierarhy:', hierarchy);
124
+ console.log('passed hierarchy:', hierarchy);
121
125
  for (let i = 0; i < hierarchy.length; i++) {
122
126
  const os = optionSets.find(os => os.name === hierarchy[i]);
123
127
  if (!os) {
@@ -2,6 +2,9 @@ import { Command } from '@oclif/core';
2
2
  export default class UploadOptionSets extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
5
+ static flags: {
6
+ dir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ };
5
8
  run(): Promise<void>;
6
9
  }
7
- export declare function uploadOptionSets(): Promise<void>;
10
+ export declare function uploadOptionSets(dir: string): Promise<void>;
@@ -11,7 +11,8 @@ const core_1 = require("@oclif/core");
11
11
  const yaml = require('js-yaml');
12
12
  class UploadOptionSets extends core_1.Command {
13
13
  async run() {
14
- return await uploadOptionSets();
14
+ const { flags } = await this.parse(UploadOptionSets);
15
+ return await uploadOptionSets(flags.dir);
15
16
  }
16
17
  }
17
18
  exports.default = UploadOptionSets;
@@ -20,12 +21,15 @@ UploadOptionSets.examples = [
20
21
  `$ contrail types uploadOptionSets
21
22
  `,
22
23
  ];
23
- async function uploadOptionSets() {
24
+ UploadOptionSets.flags = {
25
+ dir: core_1.Flags.string({ char: 'd', description: 'The directory from which to export the option set data. Defaults to the current directory. The option set data will be loaded from $dir/option-sets', required: false, default: '.' }),
26
+ };
27
+ async function uploadOptionSets(dir) {
24
28
  try {
25
29
  const userConfig = await (0, login_1.authUser)();
26
30
  console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk_1.default.blue.bold('START'));
27
31
  console.log('%s Uploading', chalk_1.default.yellow.bold('OPTION SETS'));
28
- await uploadOS();
32
+ await uploadOS(dir);
29
33
  console.log('%s Uploaded', chalk_1.default.yellow.bold('OPTION SETS'));
30
34
  }
31
35
  catch (e) {
@@ -35,13 +39,13 @@ async function uploadOptionSets() {
35
39
  console.log('%s Types Upload Complete.', chalk_1.default.green.bold('COMPLETE'));
36
40
  }
37
41
  exports.uploadOptionSets = uploadOptionSets;
38
- function loadOptionSets() {
39
- const TARGET_DIR = process.cwd();
42
+ function loadOptionSets(fromDir) {
40
43
  try {
41
- const files = fs_1.default.readdirSync(path.join(TARGET_DIR, 'option-sets'));
44
+ const dir = path.resolve(path.join(fromDir, 'option-sets'));
45
+ const files = fs_1.default.readdirSync(dir);
42
46
  const optionSets = [];
43
47
  for (const file of files) {
44
- optionSets.push(yaml.load(fs_1.default.readFileSync(path.join(TARGET_DIR, 'option-sets', file), 'utf8')));
48
+ optionSets.push(yaml.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
45
49
  }
46
50
  return optionSets;
47
51
  }
@@ -49,8 +53,8 @@ function loadOptionSets() {
49
53
  throw new Error(`ERROR PARSING YAML: ${e}`);
50
54
  }
51
55
  }
52
- async function uploadOS() {
53
- const optionSets = loadOptionSets();
56
+ async function uploadOS(dir) {
57
+ const optionSets = loadOptionSets(dir);
54
58
  const currentOptionSets = await new sdk_1.Entities().get({
55
59
  entityName: 'type-property-option-set',
56
60
  });
@@ -2,6 +2,9 @@ import { Command } from '@oclif/core';
2
2
  export default class UploadRuleSets extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
5
+ static flags: {
6
+ dir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ };
5
8
  run(): Promise<void>;
6
9
  }
7
- export declare function uploadRuleSets(): Promise<void>;
10
+ export declare function uploadRuleSets(dir: string): Promise<void>;
@@ -11,7 +11,8 @@ const core_1 = require("@oclif/core");
11
11
  const yaml = require('js-yaml');
12
12
  class UploadRuleSets extends core_1.Command {
13
13
  async run() {
14
- await uploadRuleSets();
14
+ const { flags } = await this.parse(UploadRuleSets);
15
+ await uploadRuleSets(flags.dir);
15
16
  }
16
17
  }
17
18
  exports.default = UploadRuleSets;
@@ -20,11 +21,14 @@ UploadRuleSets.examples = [
20
21
  `$ contrail types uploadRuleSets
21
22
  `,
22
23
  ];
23
- async function uploadRuleSets() {
24
+ UploadRuleSets.flags = {
25
+ dir: core_1.Flags.string({ char: 'd', description: 'The directory from which to export the rule set data. Defaults to the current directory. The rule set data will be loaded from $dir/rule-sets/*.yml', required: false, default: '.' }),
26
+ };
27
+ async function uploadRuleSets(dir) {
24
28
  try {
25
29
  await (0, login_1.authUser)();
26
30
  console.log('%s Uploading', chalk_1.default.yellow.bold('RULE SET'));
27
- const [reducedRuleSets, reducedRuleSetLinks] = await loadReducedRuleSets();
31
+ const [reducedRuleSets, reducedRuleSetLinks] = await loadReducedRuleSets(dir);
28
32
  await uploadRuleSetObjects(reducedRuleSets);
29
33
  await uploadRuleSetLinkObjects(reducedRuleSetLinks);
30
34
  console.log('%s Uploaded', chalk_1.default.yellow.bold('RULE SET'));
@@ -36,16 +40,16 @@ async function uploadRuleSets() {
36
40
  console.log('%s Rule set Upload Complete.', chalk_1.default.green.bold('COMPLETE'));
37
41
  }
38
42
  exports.uploadRuleSets = uploadRuleSets;
39
- function loadReducedRuleSets() {
43
+ function loadReducedRuleSets(fromDir) {
40
44
  const ruleSets = [];
41
45
  let ruleSetLinks = [];
42
- const TARGET_DIR = process.cwd();
46
+ const dir = path.join(fromDir, 'rule-sets');
43
47
  try {
44
- const files = fs_1.default.readdirSync(path.join(TARGET_DIR, 'rule-sets'));
48
+ const files = fs_1.default.readdirSync(dir);
45
49
  for (const file of files) {
46
- ruleSets.push(yaml.load(fs_1.default.readFileSync(path.join(TARGET_DIR, 'rule-sets', file), 'utf8')));
50
+ ruleSets.push(yaml.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
47
51
  }
48
- ruleSetLinks = yaml.load(fs_1.default.readFileSync(path.join(TARGET_DIR, 'rule-set-links.yml'), 'utf8'));
52
+ ruleSetLinks = yaml.load(fs_1.default.readFileSync(path.join(fromDir, 'rule-set-links.yml'), 'utf8'));
49
53
  return [ruleSets, ruleSetLinks];
50
54
  }
51
55
  catch (e) {
@@ -2,6 +2,9 @@ import { Command } from '@oclif/core';
2
2
  export default class UploadTypePropertyPolicies extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
5
+ static flags: {
6
+ dir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ };
5
8
  run(): Promise<void>;
6
9
  }
7
- export declare function uploadTypePropertyPolicies(): Promise<void>;
10
+ export declare function uploadTypePropertyPolicies(dir: string): Promise<void>;
@@ -12,7 +12,8 @@ const type_extractor_1 = require("../../helpers/types/type-extractor");
12
12
  const yaml = require('js-yaml');
13
13
  class UploadTypePropertyPolicies extends core_1.Command {
14
14
  async run() {
15
- return await uploadTypePropertyPolicies();
15
+ const { flags } = await this.parse(UploadTypePropertyPolicies);
16
+ return await uploadTypePropertyPolicies(flags.dir);
16
17
  }
17
18
  }
18
19
  exports.default = UploadTypePropertyPolicies;
@@ -21,11 +22,14 @@ UploadTypePropertyPolicies.examples = [
21
22
  `$ contrail types uploadTypePropertyPolicies
22
23
  `,
23
24
  ];
24
- async function uploadTypePropertyPolicies() {
25
+ UploadTypePropertyPolicies.flags = {
26
+ dir: core_1.Flags.string({ char: 'd', description: 'The directory from which to export the type property policy data. Defaults to the current directory. The type property policy data will be loaded from $dir/type-property-policies/*.yml', required: false, default: '.' }),
27
+ };
28
+ async function uploadTypePropertyPolicies(dir) {
25
29
  try {
26
30
  await (0, login_1.authUser)();
27
31
  console.log('%s Uploading', chalk_1.default.yellow.bold('TYPE PROPERTY POLICY'));
28
- const [reducedTypePropertyPolicies, reducedTypePropertyPolicyLinks] = await loadTPPolicies();
32
+ const [reducedTypePropertyPolicies, reducedTypePropertyPolicyLinks] = await loadTPPolicies(dir);
29
33
  await uploadTPPolicyObjects(reducedTypePropertyPolicies);
30
34
  await uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks);
31
35
  console.log('%s Uploaded', chalk_1.default.yellow.bold('TYPE PROPERTY POLICY'));
@@ -37,16 +41,16 @@ async function uploadTypePropertyPolicies() {
37
41
  console.log('%s Type Property Policy Upload Complete.', chalk_1.default.green.bold('COMPLETE'));
38
42
  }
39
43
  exports.uploadTypePropertyPolicies = uploadTypePropertyPolicies;
40
- function loadTPPolicies() {
44
+ function loadTPPolicies(fromDir) {
41
45
  const tpps = [];
42
46
  let tppLinks = [];
43
- const TARGET_DIR = process.cwd();
47
+ const dir = path.join(fromDir, 'type-property-policies');
44
48
  try {
45
- const files = fs_1.default.readdirSync(path.join(TARGET_DIR, 'type-property-policies'));
49
+ const files = fs_1.default.readdirSync(dir);
46
50
  for (const file of files) {
47
- tpps.push(yaml.load(fs_1.default.readFileSync(path.join(TARGET_DIR, 'type-property-policies', file), 'utf8')));
51
+ tpps.push(yaml.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
48
52
  }
49
- tppLinks = yaml.load(fs_1.default.readFileSync(path.join(TARGET_DIR, 'type-property-policy-links.yml'), 'utf8'));
53
+ tppLinks = yaml.load(fs_1.default.readFileSync(path.join(fromDir, 'type-property-policy-links.yml'), 'utf8'));
50
54
  return [tpps, tppLinks];
51
55
  }
52
56
  catch (e) {
@@ -2,6 +2,9 @@ import { Command } from '@oclif/core';
2
2
  export default class UploadUsageInfo extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
5
+ static flags: {
6
+ dir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ };
5
8
  run(): Promise<void>;
6
9
  }
7
- export declare function uploadUsageInfo(): Promise<void>;
10
+ export declare function uploadUsageInfo(dir: string): Promise<void>;
@@ -12,7 +12,8 @@ const type_extractor_1 = require("../../helpers/types/type-extractor");
12
12
  const yaml = require('js-yaml');
13
13
  class UploadUsageInfo extends core_1.Command {
14
14
  async run() {
15
- await uploadUsageInfo();
15
+ const { flags } = await this.parse(UploadUsageInfo);
16
+ await uploadUsageInfo(flags.dir);
16
17
  }
17
18
  }
18
19
  exports.default = UploadUsageInfo;
@@ -21,11 +22,14 @@ UploadUsageInfo.examples = [
21
22
  `$ contrail types uploadUsageInfo
22
23
  `,
23
24
  ];
24
- async function uploadUsageInfo() {
25
+ UploadUsageInfo.flags = {
26
+ dir: core_1.Flags.string({ char: 'd', description: 'The directory from which to export the usage info data. Defaults to the current directory. The option set data will be loaded from $dir/usage-info.yml', required: false, default: '.' }),
27
+ };
28
+ async function uploadUsageInfo(dir) {
25
29
  try {
26
30
  await (0, login_1.authUser)();
27
31
  console.log('%s Uploading', chalk_1.default.yellow.bold('USAGE INFO'));
28
- const reducedUsageInfo = await loadUsageInfo();
32
+ const reducedUsageInfo = await loadUsageInfo(dir);
29
33
  await uploadUsageInfoObjects(reducedUsageInfo);
30
34
  console.log('%s Uploaded', chalk_1.default.yellow.bold('USAGE INFO'));
31
35
  }
@@ -36,10 +40,9 @@ async function uploadUsageInfo() {
36
40
  console.log('%s Usage Info Upload Complete.', chalk_1.default.green.bold('COMPLETE'));
37
41
  }
38
42
  exports.uploadUsageInfo = uploadUsageInfo;
39
- function loadUsageInfo() {
40
- const TARGET_DIR = process.cwd();
43
+ function loadUsageInfo(dir) {
41
44
  try {
42
- const doc = yaml.load(fs_1.default.readFileSync(path.join(TARGET_DIR, 'usage-info.yml'), 'utf8'));
45
+ const doc = yaml.load(fs_1.default.readFileSync(path.join(dir, 'usage-info.yml'), 'utf8'));
43
46
  return doc;
44
47
  }
45
48
  catch (e) {
@@ -4,6 +4,8 @@ export default class ExportUsers extends Command {
4
4
  static examples: string[];
5
5
  static flags: {
6
6
  fileOut: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ overwrite: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
8
  };
8
9
  run(): Promise<void>;
9
10
  }
11
+ export declare function exportUsers(fileLocation: string, overwrite: boolean): Promise<void>;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exportUsers = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  const path = tslib_1.__importStar(require("path"));
5
6
  const sdk_1 = require("@contrail/sdk");
@@ -8,14 +9,15 @@ const fs_1 = tslib_1.__importDefault(require("fs"));
8
9
  const login_1 = require("../../auth/login");
9
10
  const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
10
11
  const core_1 = require("@oclif/core");
12
+ const file_helpers_1 = require("../../helpers/file-helpers");
11
13
  class ExportUsers extends core_1.Command {
12
14
  async run() {
13
15
  var _a;
14
- const { args, flags } = await this.parse(ExportUsers);
16
+ const { flags } = await this.parse(ExportUsers);
15
17
  try {
16
18
  await (0, login_1.authUser)();
17
19
  this.log('%s Getting Users.', chalk_1.default.blue.bold('START'));
18
- await exportUsers((_a = flags.fileOut) !== null && _a !== void 0 ? _a : 'users.yml');
20
+ await exportUsers((_a = flags.fileOut) !== null && _a !== void 0 ? _a : 'users.yml', flags.overwrite);
19
21
  this.log('%s Done', chalk_1.default.yellow.bold('USERS'));
20
22
  }
21
23
  catch (e) {
@@ -33,8 +35,9 @@ ExportUsers.examples = [
33
35
  ];
34
36
  ExportUsers.flags = {
35
37
  fileOut: core_1.Flags.string({ char: 'f', description: 'The location for the file to be saved', required: false }),
38
+ overwrite: core_1.Flags.boolean({ description: 'Replaces existing files if they exist', required: false, default: false })
36
39
  };
37
- async function exportUsers(fileLocation) {
40
+ async function exportUsers(fileLocation, overwrite) {
38
41
  const allUsersInOrg = await new sdk_1.Entities().get({
39
42
  entityName: 'user-org',
40
43
  });
@@ -51,10 +54,15 @@ async function exportUsers(fileLocation) {
51
54
  ...userInOrg.user
52
55
  });
53
56
  }
54
- saveData({ users: users }, fileLocation);
57
+ saveData({ users: users }, fileLocation, overwrite);
55
58
  }
56
- function saveData(data, fileLocation) {
59
+ exports.exportUsers = exportUsers;
60
+ function saveData(data, fileLocation, overwrite) {
57
61
  const yamlStr = js_yaml_1.default.dump(data);
58
62
  const CURRENT_DIR = process.cwd();
59
- fs_1.default.writeFileSync(path.resolve(path.join(CURRENT_DIR, fileLocation)), yamlStr, 'utf8');
63
+ const pathToWrite = path.resolve(path.join(CURRENT_DIR, fileLocation));
64
+ if (fs_1.default.existsSync(pathToWrite)) {
65
+ (0, file_helpers_1.safeFileOverwrite)(pathToWrite, overwrite);
66
+ }
67
+ fs_1.default.writeFileSync(pathToWrite, yamlStr, 'utf8');
60
68
  }
@@ -7,3 +7,4 @@ export default class ImportUsers extends Command {
7
7
  };
8
8
  run(): Promise<void>;
9
9
  }
10
+ export declare function uploadUsers(fileLocation: string): Promise<void>;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uploadUsers = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  const path = tslib_1.__importStar(require("path"));
5
6
  const sdk_1 = require("@contrail/sdk");
@@ -63,3 +64,4 @@ async function uploadUsers(fileLocation) {
63
64
  });
64
65
  }
65
66
  }
67
+ exports.uploadUsers = uploadUsers;