@contrail/cli 3.6.0-alpha-8-alpha.2ab4f80 → 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 +44 -26
- package/dist/auth/login.spec.js +124 -0
- package/dist/basecommand.js +3 -3
- package/dist/commands/app/getApiKey.js +2 -2
- package/dist/commands/entities/create.d.ts +1 -13
- package/dist/commands/entities/create.js +31 -98
- package/dist/commands/entities/create.spec.js +3 -32
- package/dist/commands/entities/delete.d.ts +2 -6
- package/dist/commands/entities/delete.js +53 -72
- package/dist/commands/entities/get.d.ts +0 -4
- package/dist/commands/entities/get.js +15 -66
- package/dist/commands/entities/update.d.ts +2 -15
- package/dist/commands/entities/update.js +44 -80
- 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 -3
- package/dist/common.js +1 -18
- package/dist/helpers/config/config.d.ts +2 -0
- package/dist/helpers/config/config.js +6 -1
- package/dist/helpers/entities/assortment-items.d.ts +2 -4
- package/dist/helpers/entities/assortment-items.js +1 -4
- package/dist/helpers/file-helpers.js +2 -2
- 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
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.6.0-alpha-8-alpha.
|
|
20
|
+
@contrail/cli/3.6.0-alpha-8-alpha.351376b linux-x64 node-v24.22.1
|
|
21
21
|
$ contrail --help [COMMAND]
|
|
22
22
|
USAGE
|
|
23
23
|
$ contrail COMMAND
|
|
@@ -52,9 +52,11 @@ To get instructions on how to set up autocomplete for your shell, run `contrail
|
|
|
52
52
|
* [`contrail config set`](#contrail-config-set)
|
|
53
53
|
* [`contrail config use [NAME]`](#contrail-config-use-name)
|
|
54
54
|
* [`contrail entities create PATH`](#contrail-entities-create-path)
|
|
55
|
-
* [`contrail entities delete ENTITYNAME
|
|
56
|
-
* [`contrail entities get TYPEPATH
|
|
57
|
-
* [`contrail entities update ENTITYNAME [
|
|
55
|
+
* [`contrail entities delete ENTITYNAME`](#contrail-entities-delete-entityname)
|
|
56
|
+
* [`contrail entities get TYPEPATH`](#contrail-entities-get-typepath)
|
|
57
|
+
* [`contrail entities update ENTITYNAME [ID]`](#contrail-entities-update-entityname-id)
|
|
58
|
+
* [`contrail feature-flags export`](#contrail-feature-flags-export)
|
|
59
|
+
* [`contrail feature-flags import`](#contrail-feature-flags-import)
|
|
58
60
|
* [`contrail file upload FILELOCATION CONTENTTYPE`](#contrail-file-upload-filelocation-contenttype)
|
|
59
61
|
* [`contrail groups export`](#contrail-groups-export)
|
|
60
62
|
* [`contrail groups import GROUPSFILE`](#contrail-groups-import-groupsfile)
|
|
@@ -543,18 +545,17 @@ EXAMPLES
|
|
|
543
545
|
|
|
544
546
|
## `contrail entities create PATH`
|
|
545
547
|
|
|
546
|
-
Create entities
|
|
548
|
+
(BETA) Create entities
|
|
547
549
|
|
|
548
550
|
```
|
|
549
551
|
USAGE
|
|
550
552
|
$ contrail entities create PATH [-l error|warn|info|debug] [-e true|false] [-n <value>] [-d] [-i <value>] [-o
|
|
551
|
-
<value>] [-g] [-r] [-
|
|
553
|
+
<value>] [-g] [-r] [-s]
|
|
552
554
|
|
|
553
555
|
ARGUMENTS
|
|
554
556
|
PATH Path of the entity type to create
|
|
555
557
|
|
|
556
558
|
FLAGS
|
|
557
|
-
-S, --skipHydrateRelationships If true, does not hydrate relationships for the created entities
|
|
558
559
|
-d, --dryRun If true, does not create the entity but simulates the creation
|
|
559
560
|
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
560
561
|
<options: true|false>
|
|
@@ -568,13 +569,10 @@ FLAGS
|
|
|
568
569
|
-n, --count=<value> Number of random entities to create
|
|
569
570
|
-o, --outputFile=<value> File to save the output (optional)
|
|
570
571
|
-r, --readableIds If true, uses readable IDs for the created entities
|
|
571
|
-
|
|
572
|
-
<options: 1|2>
|
|
573
|
-
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
574
|
-
/<entities>/synchronous)
|
|
572
|
+
-s, --skipHydrateRelationships If true, does not hydrate relationships for the created entities
|
|
575
573
|
|
|
576
574
|
DESCRIPTION
|
|
577
|
-
Create entities
|
|
575
|
+
(BETA) Create entities
|
|
578
576
|
|
|
579
577
|
EXAMPLES
|
|
580
578
|
$ contrail entities create color -g -n=10 # creates 10 random colors
|
|
@@ -596,55 +594,46 @@ EXAMPLES
|
|
|
596
594
|
$ contrail entities create color -o /tmp/colors.json -- name=Blue green=1 red=2 blue=3 # creates a color and saves the output to /tmp/colors.json
|
|
597
595
|
```
|
|
598
596
|
|
|
599
|
-
## `contrail entities delete ENTITYNAME
|
|
597
|
+
## `contrail entities delete ENTITYNAME`
|
|
600
598
|
|
|
601
|
-
Delete
|
|
599
|
+
(BETA) Delete an entity
|
|
602
600
|
|
|
603
601
|
```
|
|
604
602
|
USAGE
|
|
605
|
-
$ contrail entities delete ENTITYNAME [
|
|
606
|
-
<value>] [--apiVersion 1|2]
|
|
603
|
+
$ contrail entities delete ENTITYNAME [-l error|warn|info|debug] [-e true|false] [-d] [-i <value>] [--id <value>]
|
|
607
604
|
|
|
608
605
|
ARGUMENTS
|
|
609
606
|
ENTITYNAME The name of the entity type to delete
|
|
610
|
-
IDS One or more entity ids to delete
|
|
611
607
|
|
|
612
608
|
FLAGS
|
|
613
|
-
-d, --dryRun If true, does not delete the
|
|
609
|
+
-d, --dryRun If true, does not delete the entity but simulates the deletion
|
|
614
610
|
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
615
611
|
<options: true|false>
|
|
616
|
-
-i, --
|
|
617
|
-
|
|
612
|
+
-i, --input=<value> A JSON array of objects where each object is one entity to create. Cannot be used
|
|
613
|
+
with --count. Unless --precise is specified, any missing values will be populated
|
|
614
|
+
with random values.
|
|
618
615
|
-l, --logLevel=<option> The Log Level
|
|
619
616
|
<options: error|warn|info|debug>
|
|
620
|
-
--
|
|
621
|
-
<options: 1|2>
|
|
622
|
-
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
623
|
-
/<entities>/synchronous)
|
|
617
|
+
--id=<value> The unique identifier of the entity
|
|
624
618
|
|
|
625
619
|
DESCRIPTION
|
|
626
|
-
Delete
|
|
620
|
+
(BETA) Delete an entity
|
|
627
621
|
|
|
628
622
|
EXAMPLES
|
|
629
623
|
$ contrail entities delete color 123
|
|
630
|
-
|
|
631
|
-
$ contrail entities delete color id1 id2 id3
|
|
632
|
-
|
|
633
|
-
$ contrail entities delete item -i ids.json
|
|
634
624
|
```
|
|
635
625
|
|
|
636
|
-
## `contrail entities get TYPEPATH
|
|
626
|
+
## `contrail entities get TYPEPATH`
|
|
637
627
|
|
|
638
|
-
Get an entity
|
|
628
|
+
(BETA) Get an entity
|
|
639
629
|
|
|
640
630
|
```
|
|
641
631
|
USAGE
|
|
642
|
-
$ contrail entities get TYPEPATH [
|
|
643
|
-
|
|
632
|
+
$ contrail entities get TYPEPATH [-l error|warn|info|debug] [-e true|false] [-o <value>] [-p <value>] [-P] [-s
|
|
633
|
+
<value>] [-S] [-t <value>] [-r <value>]
|
|
644
634
|
|
|
645
635
|
ARGUMENTS
|
|
646
636
|
TYPEPATH The name of the entity type to fetch
|
|
647
|
-
IDS One or more entity ids; shorthand for the id/ids criteria
|
|
648
637
|
|
|
649
638
|
FLAGS
|
|
650
639
|
-P, --paginated If true, fetches all entities in a paginated manner
|
|
@@ -658,19 +647,11 @@ FLAGS
|
|
|
658
647
|
-r, --relations=<value> Comma-separated list of relations to include in the output
|
|
659
648
|
-s, --skip=<value> Number of entities to skip (used with paginated fetch)
|
|
660
649
|
-t, --take=<value> Number of entities to fetch in a single request (default is 100)
|
|
661
|
-
--apiVersion=<option> Api-Version header to send; selects the V1 or V2 variant of the endpoint
|
|
662
|
-
<options: 1|2>
|
|
663
|
-
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
664
|
-
/<entities>/synchronous)
|
|
665
650
|
|
|
666
651
|
DESCRIPTION
|
|
667
|
-
Get an entity
|
|
652
|
+
(BETA) Get an entity
|
|
668
653
|
|
|
669
654
|
EXAMPLES
|
|
670
|
-
$ contrail entities get color 123
|
|
671
|
-
|
|
672
|
-
$ contrail entities get color id1 id2 id3
|
|
673
|
-
|
|
674
655
|
$ contrail entities get color -- id=123
|
|
675
656
|
|
|
676
657
|
$ contrail entities get loader-processes -- createdOn=2025-09-15..2025-09-16
|
|
@@ -680,43 +661,84 @@ EXAMPLES
|
|
|
680
661
|
$ contrail entities get events -- timestamp=..2025-09-16T23:59:59Z
|
|
681
662
|
```
|
|
682
663
|
|
|
683
|
-
## `contrail entities update ENTITYNAME [
|
|
664
|
+
## `contrail entities update ENTITYNAME [ID]`
|
|
684
665
|
|
|
685
|
-
Update an entity
|
|
666
|
+
(BETA) Update an entity
|
|
686
667
|
|
|
687
668
|
```
|
|
688
669
|
USAGE
|
|
689
|
-
$ contrail entities update ENTITYNAME [
|
|
690
|
-
[--suffix <value>] [--apiVersion 1|2]
|
|
670
|
+
$ contrail entities update ENTITYNAME [ID] [-l error|warn|info|debug] [-e true|false] [-s] [-d] [-i <value>] [-F]
|
|
691
671
|
|
|
692
672
|
ARGUMENTS
|
|
693
673
|
ENTITYNAME The name of the entity type to update
|
|
694
|
-
|
|
674
|
+
ID The unique identifier of the entity
|
|
695
675
|
|
|
696
676
|
FLAGS
|
|
697
|
-
-
|
|
698
|
-
-d, --dryRun If true, does not
|
|
677
|
+
-F, --force Force update without validation. Internal use only
|
|
678
|
+
-d, --dryRun If true, does not create the entity but simulates the creation
|
|
699
679
|
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
700
680
|
<options: true|false>
|
|
701
|
-
-i, --inputFile=<value>
|
|
681
|
+
-i, --inputFile=<value> File containing properties to update the entity (optional)
|
|
702
682
|
-l, --logLevel=<option> The Log Level
|
|
703
683
|
<options: error|warn|info|debug>
|
|
704
|
-
|
|
705
|
-
<options: 1|2>
|
|
706
|
-
--suffix=<value> Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets
|
|
707
|
-
/<entities>/synchronous)
|
|
684
|
+
-s, --skipHydrateRelationships Skip hydrating relationships when updating the entity
|
|
708
685
|
|
|
709
686
|
DESCRIPTION
|
|
710
|
-
Update an entity
|
|
687
|
+
(BETA) Update an entity
|
|
711
688
|
|
|
712
689
|
EXAMPLES
|
|
713
690
|
$ contrail entities update color 123 -- name=obsidian hex=000000
|
|
714
691
|
|
|
715
|
-
$ contrail entities update item id1 id2 id3 -- status=archived # apply the same change to several entities
|
|
716
|
-
|
|
717
692
|
$ contrail entities update color 123 -- description= notes='""' # Unset description, set notes to empty string
|
|
718
693
|
```
|
|
719
694
|
|
|
695
|
+
## `contrail feature-flags export`
|
|
696
|
+
|
|
697
|
+
Export the enabled feature flags for your Org
|
|
698
|
+
|
|
699
|
+
```
|
|
700
|
+
USAGE
|
|
701
|
+
$ contrail feature-flags export [-l error|warn|info|debug] [-e true|false] [-d <value>] [-f]
|
|
702
|
+
|
|
703
|
+
FLAGS
|
|
704
|
+
-d, --outDir=<value> [default: .] The directory to which to export the feature flags. Defaults to the
|
|
705
|
+
current directory
|
|
706
|
+
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
707
|
+
<options: true|false>
|
|
708
|
+
-f, --overwrite Replaces any existing export files in outDir
|
|
709
|
+
-l, --logLevel=<option> The Log Level
|
|
710
|
+
<options: error|warn|info|debug>
|
|
711
|
+
|
|
712
|
+
DESCRIPTION
|
|
713
|
+
Export the enabled feature flags for your Org
|
|
714
|
+
|
|
715
|
+
EXAMPLES
|
|
716
|
+
$ contrail feature-flags export
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
## `contrail feature-flags import`
|
|
720
|
+
|
|
721
|
+
Upload an extracted set of feature flags
|
|
722
|
+
|
|
723
|
+
```
|
|
724
|
+
USAGE
|
|
725
|
+
$ contrail feature-flags import [-l error|warn|info|debug] [-e true|false] [-d <value>]
|
|
726
|
+
|
|
727
|
+
FLAGS
|
|
728
|
+
-d, --dir=<value> [default: .] The directory from which to import the feature flags. Defaults to the
|
|
729
|
+
current directory. The feature flags will be loaded from $dir/feature-flags.yml
|
|
730
|
+
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
731
|
+
<options: true|false>
|
|
732
|
+
-l, --logLevel=<option> The Log Level
|
|
733
|
+
<options: error|warn|info|debug>
|
|
734
|
+
|
|
735
|
+
DESCRIPTION
|
|
736
|
+
Upload an extracted set of feature flags
|
|
737
|
+
|
|
738
|
+
EXAMPLES
|
|
739
|
+
$ contrail feature-flags import
|
|
740
|
+
```
|
|
741
|
+
|
|
720
742
|
## `contrail file upload FILELOCATION CONTENTTYPE`
|
|
721
743
|
|
|
722
744
|
Uploads a file to the VibeIQ platform
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteFeatureFlag = exports.createFeatureFlag = exports.getFeatureFlags = void 0;
|
|
4
|
+
const sdk_1 = require("@contrail/sdk");
|
|
5
|
+
// a feature flag record exists only for features that are turned ON for the org,
|
|
6
|
+
// and carries no configuration beyond its featureName
|
|
7
|
+
async function getFeatureFlags(options) {
|
|
8
|
+
return new sdk_1.Entities().get({
|
|
9
|
+
entityName: 'feature-flag',
|
|
10
|
+
...options,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
exports.getFeatureFlags = getFeatureFlags;
|
|
14
|
+
// the API treats create as an upsert on featureName, so creating an already
|
|
15
|
+
// enabled flag returns the existing record instead of failing
|
|
16
|
+
async function createFeatureFlag(featureName) {
|
|
17
|
+
return new sdk_1.Entities().create({
|
|
18
|
+
entityName: 'feature-flag',
|
|
19
|
+
object: { featureName },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.createFeatureFlag = createFeatureFlag;
|
|
23
|
+
async function deleteFeatureFlag(id) {
|
|
24
|
+
return new sdk_1.Entities().delete({
|
|
25
|
+
entityName: 'feature-flag',
|
|
26
|
+
id,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.deleteFeatureFlag = deleteFeatureFlag;
|
package/dist/api/users.d.ts
CHANGED
package/dist/api/users.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getGroups = exports.getUserOrgs = void 0;
|
|
3
|
+
exports.getCurrentUserWithPlatformRoles = exports.getGroups = exports.getUserOrgs = void 0;
|
|
4
4
|
const sdk_1 = require("@contrail/sdk");
|
|
5
5
|
async function getUserOrgs(options) {
|
|
6
6
|
return new sdk_1.Entities().get({
|
|
@@ -16,3 +16,12 @@ async function getGroups(options) {
|
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
exports.getGroups = getGroups;
|
|
19
|
+
// GET /users/current only populates platformRoles when it is asked for as a relation
|
|
20
|
+
async function getCurrentUserWithPlatformRoles() {
|
|
21
|
+
return new sdk_1.Entities().get({
|
|
22
|
+
entityName: 'user',
|
|
23
|
+
id: 'current',
|
|
24
|
+
relations: ['platformRoles'],
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.getCurrentUserWithPlatformRoles = getCurrentUserWithPlatformRoles;
|
package/dist/auth/login.js
CHANGED
|
@@ -3,16 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getVersionFromPackageJson = exports.authUser = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const amazon_cognito_identity_js_1 = require("amazon-cognito-identity-js");
|
|
6
|
+
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
6
7
|
const sdk_1 = require("@contrail/sdk");
|
|
7
8
|
const config_1 = require("../helpers/config/config");
|
|
8
9
|
const logger_1 = tslib_1.__importDefault(require("../logger"));
|
|
9
10
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
11
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
11
12
|
const common_1 = require("../common");
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const DEFAULT_API_GATEWAY = config_1.ENVIRONMENTS.prod;
|
|
14
|
+
const COGNITO_CONFIGS = {
|
|
15
|
+
dev: { userPoolId: 'us-east-1_e2cA0nJWu', clientId: '209s9c62o165cqab0fu5ihjtu9' },
|
|
16
|
+
prod: { userPoolId: 'us-east-1_qIaNZdUfm', clientId: '7knkt34gfacbgd0ghnuspefdfg' },
|
|
16
17
|
};
|
|
17
18
|
async function authUser() {
|
|
18
19
|
logger_1.default.debug('authorizing user...');
|
|
@@ -62,7 +63,7 @@ exports.authUser = authUser;
|
|
|
62
63
|
async function getOrgSlug(config) {
|
|
63
64
|
const orgSlug = config?.orgSlug || process.env.CONTRAIL_CLI_ORG_SLUG;
|
|
64
65
|
if (!orgSlug) {
|
|
65
|
-
const answers = await
|
|
66
|
+
const answers = await inquirer_1.default.prompt([
|
|
66
67
|
{
|
|
67
68
|
type: 'input',
|
|
68
69
|
name: 'orgSlug',
|
|
@@ -75,7 +76,7 @@ async function getOrgSlug(config) {
|
|
|
75
76
|
return orgSlug;
|
|
76
77
|
}
|
|
77
78
|
async function authenticateWithApiKey(config, apiKey, orgSlug) {
|
|
78
|
-
const apiGateway = config
|
|
79
|
+
const apiGateway = getApiGateway(config);
|
|
79
80
|
sdk_1.Auth.config = {
|
|
80
81
|
apiUserToken: apiKey,
|
|
81
82
|
apiRefreshToken: undefined,
|
|
@@ -88,6 +89,12 @@ async function authenticateWithApiKey(config, apiKey, orgSlug) {
|
|
|
88
89
|
return Object.assign({}, sdk_1.Auth.config);
|
|
89
90
|
}
|
|
90
91
|
async function authenticateWithUsernamePassword(config) {
|
|
92
|
+
const apiGateway = getApiGateway(config);
|
|
93
|
+
const environment = (0, config_1.findEnvironmentName)(apiGateway);
|
|
94
|
+
const cognitoConfig = environment ? COGNITO_CONFIGS[environment] : undefined;
|
|
95
|
+
if (!environment || !cognitoConfig) {
|
|
96
|
+
throw new Error(`No Cognito user pool is known for ${apiGateway}. Email and password sign-in works for ${Object.keys(COGNITO_CONFIGS).join(' and ')}; use CONTRAIL_CLI_API_KEY for other environments.`);
|
|
97
|
+
}
|
|
91
98
|
const questions = [];
|
|
92
99
|
if (!process.env.CONTRAIL_CLI_EMAIL) {
|
|
93
100
|
questions.push({
|
|
@@ -105,19 +112,20 @@ async function authenticateWithUsernamePassword(config) {
|
|
|
105
112
|
message: 'Password',
|
|
106
113
|
});
|
|
107
114
|
}
|
|
108
|
-
const answers = await
|
|
115
|
+
const answers = await inquirer_1.default.prompt(questions);
|
|
109
116
|
const params = {
|
|
110
117
|
email: process.env.CONTRAIL_CLI_EMAIL || answers.email,
|
|
111
118
|
password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
|
|
112
119
|
orgSlug: await getOrgSlug(config),
|
|
113
|
-
|
|
120
|
+
apiGateway,
|
|
121
|
+
environment,
|
|
114
122
|
};
|
|
115
123
|
if (!params.email || !params.password) {
|
|
116
124
|
throw new Error('Email and Password required');
|
|
117
125
|
}
|
|
118
126
|
const poolData = {
|
|
119
|
-
UserPoolId:
|
|
120
|
-
ClientId:
|
|
127
|
+
UserPoolId: cognitoConfig.userPoolId,
|
|
128
|
+
ClientId: cognitoConfig.clientId,
|
|
121
129
|
};
|
|
122
130
|
const userPool = new amazon_cognito_identity_js_1.CognitoUserPool(poolData);
|
|
123
131
|
const authData = {
|
|
@@ -133,19 +141,26 @@ async function authenticateWithUsernamePassword(config) {
|
|
|
133
141
|
return new Promise((resolve, reject) => {
|
|
134
142
|
cognitoUser.authenticateUser(authDetails, {
|
|
135
143
|
onSuccess: async (result) => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
144
|
+
try {
|
|
145
|
+
resolve(await setAuthContext(result, params));
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
reject(e);
|
|
149
|
+
}
|
|
139
150
|
},
|
|
140
151
|
onFailure: (err) => {
|
|
152
|
+
if (err?.code === 'ResourceNotFoundException') {
|
|
153
|
+
reject(new Error(`This version of the CLI has outdated ${environment} sign-in settings (${err.message}). Update the CLI: npm i -g @contrail/cli`));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
141
156
|
reject(err);
|
|
142
157
|
},
|
|
143
158
|
});
|
|
144
159
|
});
|
|
145
160
|
}
|
|
146
161
|
async function setAuthContext(user, params) {
|
|
147
|
-
const apiGateway = params
|
|
148
|
-
const { vibeAccessToken, vibeRefreshToken } = await getVibeAccessTokenFromCognitoAccessToken(user.idToken.jwtToken, apiGateway);
|
|
162
|
+
const apiGateway = params.apiGateway;
|
|
163
|
+
const { vibeAccessToken, vibeRefreshToken } = await getVibeAccessTokenFromCognitoAccessToken(user.idToken.jwtToken, apiGateway, params.environment);
|
|
149
164
|
sdk_1.Auth.config = {
|
|
150
165
|
apiUserToken: vibeAccessToken,
|
|
151
166
|
apiRefreshToken: vibeRefreshToken,
|
|
@@ -160,7 +175,7 @@ async function refreshCurrentUserOrg() {
|
|
|
160
175
|
const currentUser = await (0, sdk_1.getCurrentUser)().catch((e) => {
|
|
161
176
|
console.error('error getting current user', e.message);
|
|
162
177
|
if (isExpiredTokenError(e)) {
|
|
163
|
-
console.
|
|
178
|
+
console.log('try frefreshing');
|
|
164
179
|
return;
|
|
165
180
|
}
|
|
166
181
|
throw e;
|
|
@@ -175,7 +190,7 @@ async function refreshCurrentUserOrg() {
|
|
|
175
190
|
apiGateway: config.apiGateway,
|
|
176
191
|
orgSlug: config.orgSlug,
|
|
177
192
|
};
|
|
178
|
-
(
|
|
193
|
+
console.log('fetched new access token from refresh token', newVibeAccessToken);
|
|
179
194
|
}
|
|
180
195
|
catch (e) {
|
|
181
196
|
throw Error(`Could not get refresh token: ${e}`);
|
|
@@ -190,7 +205,10 @@ async function refreshCurrentUserOrg() {
|
|
|
190
205
|
function isExpiredTokenError(e) {
|
|
191
206
|
return e?.message?.includes('token is expired');
|
|
192
207
|
}
|
|
193
|
-
|
|
208
|
+
function getApiGateway(config) {
|
|
209
|
+
return config?.apiGateway ?? DEFAULT_API_GATEWAY;
|
|
210
|
+
}
|
|
211
|
+
async function getVibeAccessTokenFromCognitoAccessToken(cognitoAccessToken, apiGateway, environment) {
|
|
194
212
|
const url = `${apiGateway}/auth/cognito/`;
|
|
195
213
|
const response = await fetch(url, {
|
|
196
214
|
method: 'POST',
|
|
@@ -200,9 +218,11 @@ async function getVibeAccessTokenFromCognitoAccessToken(cognitoAccessToken, apiG
|
|
|
200
218
|
},
|
|
201
219
|
body: JSON.stringify({ accessToken: cognitoAccessToken }),
|
|
202
220
|
});
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
221
|
+
if (!response.ok) {
|
|
222
|
+
throw new Error(`${environment} rejected the sign-in (${response.status}).`);
|
|
223
|
+
}
|
|
224
|
+
const data = await response.json();
|
|
225
|
+
return { vibeAccessToken: data.accessToken, vibeRefreshToken: data.refreshToken };
|
|
206
226
|
}
|
|
207
227
|
async function requestRefreshedAccessToken(vibeRefreshToken, apiGateway) {
|
|
208
228
|
const url = `${apiGateway}/auth/jwt_refresh/`;
|
|
@@ -214,11 +234,9 @@ async function requestRefreshedAccessToken(vibeRefreshToken, apiGateway) {
|
|
|
214
234
|
},
|
|
215
235
|
body: JSON.stringify({ refreshToken: vibeRefreshToken }),
|
|
216
236
|
});
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
return data.accessToken;
|
|
237
|
+
return await response.json().then((data) => {
|
|
238
|
+
return data.accessToken;
|
|
239
|
+
});
|
|
222
240
|
}
|
|
223
241
|
function getVersionFromPackageJson() {
|
|
224
242
|
// Get the path to the package.json file
|
package/dist/auth/login.spec.js
CHANGED
|
@@ -1,6 +1,130 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const amazon_cognito_identity_js_1 = require("amazon-cognito-identity-js");
|
|
4
|
+
const sdk_1 = require("@contrail/sdk");
|
|
5
|
+
const config_1 = require("../helpers/config/config");
|
|
3
6
|
const login_1 = require("./login");
|
|
7
|
+
const mockAuthenticateUser = jest.fn();
|
|
8
|
+
jest.mock('amazon-cognito-identity-js', () => ({
|
|
9
|
+
CognitoUserPool: jest.fn(),
|
|
10
|
+
AuthenticationDetails: jest.fn(),
|
|
11
|
+
CognitoUser: jest.fn().mockImplementation(() => ({
|
|
12
|
+
authenticateUser: (details, callbacks) => mockAuthenticateUser(details, callbacks),
|
|
13
|
+
})),
|
|
14
|
+
}));
|
|
15
|
+
jest.mock('@contrail/sdk', () => ({
|
|
16
|
+
Auth: { config: {} },
|
|
17
|
+
getCurrentUser: jest.fn(),
|
|
18
|
+
setConfig: jest.fn(),
|
|
19
|
+
}));
|
|
20
|
+
jest.mock('../helpers/config/config', () => ({
|
|
21
|
+
...jest.requireActual('../helpers/config/config'),
|
|
22
|
+
getConfig: jest.fn(),
|
|
23
|
+
storeConfig: jest.fn(),
|
|
24
|
+
}));
|
|
25
|
+
jest.mock('../logger', () => ({
|
|
26
|
+
__esModule: true,
|
|
27
|
+
default: { debug: jest.fn(), info: jest.fn() },
|
|
28
|
+
}));
|
|
29
|
+
const DEV_GATEWAY = 'https://api.dev.vibeiq.com/dev/api';
|
|
30
|
+
function restoreEnv(name, value) {
|
|
31
|
+
if (value === undefined) {
|
|
32
|
+
delete process.env[name];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
process.env[name] = value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function jsonResponse(status, body = {}) {
|
|
39
|
+
return new Response(JSON.stringify(body), { status });
|
|
40
|
+
}
|
|
41
|
+
describe('authUser with email and password', () => {
|
|
42
|
+
const originalFetch = global.fetch;
|
|
43
|
+
const originalEmail = process.env.CONTRAIL_CLI_EMAIL;
|
|
44
|
+
const originalPassword = process.env.CONTRAIL_CLI_PASSWORD;
|
|
45
|
+
let fetchMock;
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
jest.clearAllMocks();
|
|
48
|
+
process.env.CONTRAIL_CLI_EMAIL = 'dev@vibeiq.com';
|
|
49
|
+
process.env.CONTRAIL_CLI_PASSWORD = 'secret';
|
|
50
|
+
config_1.getConfig.mockResolvedValue({ apiGateway: DEV_GATEWAY, orgSlug: 'adam-zone-1' });
|
|
51
|
+
sdk_1.getCurrentUser.mockResolvedValue({ id: 'user-1' });
|
|
52
|
+
mockAuthenticateUser.mockImplementation((_details, callbacks) => callbacks.onSuccess({ idToken: { jwtToken: 'cognito-id-token' } }));
|
|
53
|
+
fetchMock = jest.fn();
|
|
54
|
+
global.fetch = fetchMock;
|
|
55
|
+
});
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
global.fetch = originalFetch;
|
|
58
|
+
restoreEnv('CONTRAIL_CLI_EMAIL', originalEmail);
|
|
59
|
+
restoreEnv('CONTRAIL_CLI_PASSWORD', originalPassword);
|
|
60
|
+
});
|
|
61
|
+
it('should sign in through the dev pool when the config points at dev', async () => {
|
|
62
|
+
fetchMock.mockResolvedValueOnce(jsonResponse(200, { accessToken: 'vibe-access', refreshToken: 'vibe-refresh' }));
|
|
63
|
+
const context = await (0, login_1.authUser)();
|
|
64
|
+
expect(amazon_cognito_identity_js_1.CognitoUserPool).toHaveBeenCalledWith({
|
|
65
|
+
UserPoolId: 'us-east-1_e2cA0nJWu',
|
|
66
|
+
ClientId: '209s9c62o165cqab0fu5ihjtu9',
|
|
67
|
+
});
|
|
68
|
+
expect(context).toEqual({
|
|
69
|
+
apiUserToken: 'vibe-access',
|
|
70
|
+
apiRefreshToken: 'vibe-refresh',
|
|
71
|
+
apiGateway: DEV_GATEWAY,
|
|
72
|
+
orgSlug: 'adam-zone-1',
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
it('should sign in through the prod pool when the config points at prod', async () => {
|
|
76
|
+
config_1.getConfig.mockResolvedValue({
|
|
77
|
+
apiGateway: 'https://api.vibeiq.com/prod/api',
|
|
78
|
+
orgSlug: 'adam-zone-1',
|
|
79
|
+
});
|
|
80
|
+
fetchMock.mockResolvedValueOnce(jsonResponse(200, { accessToken: 'vibe-access', refreshToken: 'vibe-refresh' }));
|
|
81
|
+
await (0, login_1.authUser)();
|
|
82
|
+
expect(amazon_cognito_identity_js_1.CognitoUserPool).toHaveBeenCalledWith({
|
|
83
|
+
UserPoolId: 'us-east-1_qIaNZdUfm',
|
|
84
|
+
ClientId: '7knkt34gfacbgd0ghnuspefdfg',
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it('should match the dev pool despite a trailing slash or different case in the gateway', async () => {
|
|
88
|
+
config_1.getConfig.mockResolvedValue({
|
|
89
|
+
apiGateway: 'https://API.dev.vibeiq.com/dev/api/',
|
|
90
|
+
orgSlug: 'adam-zone-1',
|
|
91
|
+
});
|
|
92
|
+
fetchMock.mockResolvedValueOnce(jsonResponse(200, { accessToken: 'vibe-access', refreshToken: 'vibe-refresh' }));
|
|
93
|
+
await (0, login_1.authUser)();
|
|
94
|
+
expect(amazon_cognito_identity_js_1.CognitoUserPool).toHaveBeenCalledWith({
|
|
95
|
+
UserPoolId: 'us-east-1_e2cA0nJWu',
|
|
96
|
+
ClientId: '209s9c62o165cqab0fu5ihjtu9',
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
it('should explain an unknown gateway even when it has no scheme', async () => {
|
|
100
|
+
config_1.getConfig.mockResolvedValue({
|
|
101
|
+
apiGateway: 'api.dev.vibeiq.com/dev/api',
|
|
102
|
+
orgSlug: 'adam-zone-1',
|
|
103
|
+
});
|
|
104
|
+
await expect((0, login_1.authUser)()).rejects.toThrow('No Cognito user pool is known for api.dev.vibeiq.com/dev/api.');
|
|
105
|
+
});
|
|
106
|
+
it('should fail without saving tokens when no pool is known for the environment', async () => {
|
|
107
|
+
config_1.getConfig.mockResolvedValue({
|
|
108
|
+
apiGateway: 'http://localhost:3000/api',
|
|
109
|
+
orgSlug: 'adam-zone-1',
|
|
110
|
+
});
|
|
111
|
+
await expect((0, login_1.authUser)()).rejects.toThrow('No Cognito user pool is known for http://localhost:3000/api.');
|
|
112
|
+
expect(config_1.storeConfig).not.toHaveBeenCalled();
|
|
113
|
+
});
|
|
114
|
+
it('should tell the user to update the CLI when its Cognito client or pool no longer exists', async () => {
|
|
115
|
+
mockAuthenticateUser.mockImplementation((_details, callbacks) => callbacks.onFailure({
|
|
116
|
+
code: 'ResourceNotFoundException',
|
|
117
|
+
message: 'User pool client 209s9c62o165cqab0fu5ihjtu9 does not exist.',
|
|
118
|
+
}));
|
|
119
|
+
await expect((0, login_1.authUser)()).rejects.toThrow('This version of the CLI has outdated dev sign-in settings (User pool client 209s9c62o165cqab0fu5ihjtu9 does not exist.). Update the CLI: npm i -g @contrail/cli');
|
|
120
|
+
expect(config_1.storeConfig).not.toHaveBeenCalled();
|
|
121
|
+
});
|
|
122
|
+
it('should fail without saving tokens when the environment rejects the sign-in', async () => {
|
|
123
|
+
fetchMock.mockResolvedValueOnce(jsonResponse(401, { message: 'Unauthorized' }));
|
|
124
|
+
await expect((0, login_1.authUser)()).rejects.toThrow('dev rejected the sign-in (401).');
|
|
125
|
+
expect(config_1.storeConfig).not.toHaveBeenCalled();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
4
128
|
describe('getVersionFromPackageJson', () => {
|
|
5
129
|
it('should return the version value from package.json', () => {
|
|
6
130
|
const version = (0, login_1.getVersionFromPackageJson)();
|
package/dist/basecommand.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BaseCommand = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
|
-
const common_1 = require("./common");
|
|
7
6
|
const logger_1 = tslib_1.__importDefault(require("./logger"));
|
|
7
|
+
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
8
8
|
const config_1 = require("./helpers/config/config");
|
|
9
9
|
const lodash_1 = require("lodash");
|
|
10
10
|
const login_1 = require("./auth/login");
|
|
@@ -60,7 +60,7 @@ class BaseCommand extends core_1.Command {
|
|
|
60
60
|
const data = (0, lodash_1.pick)(config, ['orgSlug', 'apiGateway']);
|
|
61
61
|
let env = '';
|
|
62
62
|
if (data.apiGateway) {
|
|
63
|
-
env =
|
|
63
|
+
env = (0, config_1.findEnvironmentName)(data.apiGateway);
|
|
64
64
|
}
|
|
65
65
|
data.environment = env;
|
|
66
66
|
delete data.apiGateway;
|
|
@@ -73,7 +73,7 @@ class BaseCommand extends core_1.Command {
|
|
|
73
73
|
choices: ['yes', 'no'],
|
|
74
74
|
default: 'no',
|
|
75
75
|
});
|
|
76
|
-
const { confirm } = await
|
|
76
|
+
const { confirm } = await inquirer_1.default.prompt(questions);
|
|
77
77
|
if (confirm === 'no') {
|
|
78
78
|
logger_1.default.info('Please use `contrail config use` command to choose the configuration or `contrail config set --environment=prod` to set different environment.');
|
|
79
79
|
this.exit(1);
|
|
@@ -35,7 +35,7 @@ class GetAPIKeyApp extends basecommand_1.BaseCommand {
|
|
|
35
35
|
},
|
|
36
36
|
];
|
|
37
37
|
const answers = await inquirer_1.default.prompt(questions);
|
|
38
|
-
|
|
38
|
+
logger_1.default.info(`App API key: (app:${answers.appApiKey})`);
|
|
39
39
|
}
|
|
40
40
|
else {
|
|
41
41
|
const appFound = installedApps.find((x) => x.app.identifier === this.flags.appIdentifier);
|
|
@@ -43,7 +43,7 @@ class GetAPIKeyApp extends basecommand_1.BaseCommand {
|
|
|
43
43
|
logger_1.default.info('You do not have such an app installed');
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
logger_1.default.info(`App API key: (app:${appFound.apiKey.apiKey})`);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|