@contrail/cli 3.6.0-alpha.f45f126 → 3.7.0-alpha.51db987
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 +182 -1
- package/dist/api/types.d.ts +35 -0
- package/dist/api/types.js +49 -1
- package/dist/auth/login.d.ts +1 -1
- package/dist/auth/login.js +46 -29
- package/dist/auth/login.spec.js +31 -15
- package/dist/auth/sign-in-error.d.ts +7 -0
- package/dist/auth/sign-in-error.js +24 -0
- package/dist/auth/sign-in-error.spec.d.ts +1 -0
- package/dist/auth/sign-in-error.spec.js +22 -0
- package/dist/auth/sso.d.ts +5 -3
- package/dist/auth/sso.js +34 -18
- package/dist/auth/sso.spec.js +63 -10
- package/dist/basecommand.d.ts +3 -0
- package/dist/basecommand.js +10 -3
- package/dist/commands/app/getApiKey.js +2 -2
- package/dist/commands/entities/create.d.ts +49 -0
- package/dist/commands/entities/create.js +618 -0
- package/dist/commands/entities/create.spec.d.ts +1 -0
- package/dist/commands/entities/create.spec.js +581 -0
- package/dist/commands/entities/delete.d.ts +20 -0
- package/dist/commands/entities/delete.js +146 -0
- package/dist/commands/entities/get.d.ts +25 -0
- package/dist/commands/entities/get.js +298 -0
- package/dist/commands/entities/grammar.spec.d.ts +1 -0
- package/dist/commands/entities/grammar.spec.js +79 -0
- package/dist/commands/entities/output.spec.d.ts +1 -0
- package/dist/commands/entities/output.spec.js +72 -0
- package/dist/commands/entities/update.d.ts +32 -0
- package/dist/commands/entities/update.js +212 -0
- package/dist/commands/login.js +1 -1
- package/dist/commands/webhooks/delete.js +2 -3
- package/dist/common.d.ts +10 -1
- package/dist/common.js +37 -1
- package/dist/common.spec.d.ts +1 -0
- package/dist/common.spec.js +40 -0
- package/dist/helpers/config/config.d.ts +3 -3
- package/dist/helpers/config/config.js +3 -3
- package/dist/helpers/entities/assortment-items.d.ts +11 -0
- package/dist/helpers/entities/assortment-items.js +76 -0
- package/dist/helpers/entities/batchFetch.d.ts +11 -0
- package/dist/helpers/entities/batchFetch.js +50 -0
- package/dist/helpers/entities/index.d.ts +3 -0
- package/dist/helpers/entities/index.js +6 -0
- package/dist/helpers/entities/items.d.ts +6 -0
- package/dist/helpers/entities/items.js +60 -0
- package/dist/helpers/entities/items.spec.d.ts +1 -0
- package/dist/helpers/entities/items.spec.js +19 -0
- package/dist/helpers/entities/project-items.d.ts +2 -0
- package/dist/helpers/entities/project-items.js +44 -0
- package/dist/helpers/file-helpers.d.ts +1 -0
- package/dist/helpers/file-helpers.js +20 -3
- package/dist/helpers/propertySpecifications/dateRanges.d.ts +34 -0
- package/dist/helpers/propertySpecifications/dateRanges.js +91 -0
- package/dist/helpers/propertySpecifications/dateRanges.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/dateRanges.spec.js +97 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +39 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.js +102 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +387 -0
- package/dist/helpers/propertySpecifications/propertyValues.d.ts +31 -0
- package/dist/helpers/propertySpecifications/propertyValues.js +132 -0
- package/dist/helpers/propertySpecifications/propertyValues.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/propertyValues.spec.js +156 -0
- package/dist/logger.js +4 -1
- package/dist/logger.spec.d.ts +1 -0
- package/dist/logger.spec.js +12 -0
- package/node_modules/@contrail/entity-compare/package.json +6 -3
- package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
- package/node_modules/@contrail/loader/lib/constants.d.ts +0 -8
- package/node_modules/@contrail/loader/lib/constants.js +1 -9
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +0 -4
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +0 -57
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +34 -492
- package/node_modules/@contrail/loader/lib/pipeline/validate.js +52 -2
- package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +85 -0
- package/node_modules/@contrail/loader/package.json +2 -2
- package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +1 -4
- package/node_modules/@contrail/sdk/lib/auth/login.js +1 -1
- package/node_modules/@contrail/sdk/lib/config/config.d.ts +3 -0
- package/node_modules/@contrail/sdk/lib/config/config.js +13 -7
- package/node_modules/@contrail/sdk/lib/core/request.js +6 -2
- package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +2 -0
- package/node_modules/@contrail/sdk/lib/entities/entities.client.js +3 -1
- package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +1 -0
- package/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +34 -0
- package/node_modules/@contrail/sdk/lib/image-search/image-search.js +42 -0
- package/node_modules/@contrail/sdk/lib/image-search/index.d.ts +1 -0
- package/node_modules/@contrail/sdk/lib/image-search/index.js +17 -0
- package/node_modules/@contrail/sdk/lib/index.d.ts +1 -0
- package/node_modules/@contrail/sdk/lib/index.js +1 -0
- package/node_modules/@contrail/sdk/package.json +1 -1
- package/node_modules/@contrail/sdk/scripts/replicate-bug.js +69 -0
- package/oclif.manifest.json +449 -1
- package/package.json +6 -12
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatErrorForTerminal = exports.SignInError = void 0;
|
|
4
|
+
class SignInError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
details;
|
|
7
|
+
constructor(code, message, details = {}) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.details = details;
|
|
11
|
+
this.name = 'SignInError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.SignInError = SignInError;
|
|
15
|
+
function formatErrorForTerminal(error) {
|
|
16
|
+
if (!(error instanceof SignInError)) {
|
|
17
|
+
return error.message;
|
|
18
|
+
}
|
|
19
|
+
const details = Object.entries(error.details)
|
|
20
|
+
.filter(([, value]) => value !== undefined)
|
|
21
|
+
.map(([name, value]) => `${name}: ${value}`);
|
|
22
|
+
return details.length ? `${error.message} (${details.join(', ')})` : error.message;
|
|
23
|
+
}
|
|
24
|
+
exports.formatErrorForTerminal = formatErrorForTerminal;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sign_in_error_1 = require("./sign-in-error");
|
|
4
|
+
describe('formatErrorForTerminal', () => {
|
|
5
|
+
it('should follow a sign-in error message with its details', () => {
|
|
6
|
+
const error = new sign_in_error_1.SignInError('SSO_TOKEN_REQUEST_FAILED', 'Cognito rejected the token request.', {
|
|
7
|
+
status: 400,
|
|
8
|
+
oauthError: 'invalid_grant',
|
|
9
|
+
});
|
|
10
|
+
expect((0, sign_in_error_1.formatErrorForTerminal)(error)).toBe('Cognito rejected the token request. (status: 400, oauthError: invalid_grant)');
|
|
11
|
+
});
|
|
12
|
+
it('should leave out details that are not set', () => {
|
|
13
|
+
const error = new sign_in_error_1.SignInError('SSO_TOKEN_REQUEST_FAILED', 'Cognito rejected the token request.', {
|
|
14
|
+
status: 400,
|
|
15
|
+
oauthError: undefined,
|
|
16
|
+
});
|
|
17
|
+
expect((0, sign_in_error_1.formatErrorForTerminal)(error)).toBe('Cognito rejected the token request. (status: 400)');
|
|
18
|
+
});
|
|
19
|
+
it('should show only the message for other errors', () => {
|
|
20
|
+
expect((0, sign_in_error_1.formatErrorForTerminal)(new Error('Something else.'))).toBe('Something else.');
|
|
21
|
+
});
|
|
22
|
+
});
|
package/dist/auth/sso.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface SsoTokens {
|
|
|
9
9
|
accessToken: string;
|
|
10
10
|
refreshToken: string;
|
|
11
11
|
}
|
|
12
|
-
export interface
|
|
12
|
+
export interface SignInAttempt {
|
|
13
13
|
verifier: string;
|
|
14
14
|
challenge: string;
|
|
15
15
|
state: string;
|
|
@@ -23,14 +23,16 @@ export type SsoDomainCheck = {
|
|
|
23
23
|
kind: 'none';
|
|
24
24
|
};
|
|
25
25
|
export declare function fetchSsoDomainCheck(email: string, apiGateway: string): Promise<SsoDomainCheck>;
|
|
26
|
-
export declare function
|
|
27
|
-
export declare function buildAuthorizeUrl(client: SsoClient, identityProvider: string, redirectUri: string,
|
|
26
|
+
export declare function createSignInAttempt(): SignInAttempt;
|
|
27
|
+
export declare function buildAuthorizeUrl(client: SsoClient, identityProvider: string, redirectUri: string, signInAttempt: SignInAttempt): string;
|
|
28
28
|
export declare function parsePastedSignInCode(pasted: string, expectedState: string): string;
|
|
29
29
|
export interface LoopbackListener {
|
|
30
30
|
code: Promise<string>;
|
|
31
|
+
stop: () => void;
|
|
31
32
|
}
|
|
32
33
|
export declare function listenForLoopbackCode(expectedState: string): Promise<LoopbackListener>;
|
|
33
34
|
export declare function canOpenBrowser(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): boolean;
|
|
34
35
|
export declare function openBrowser(url: string): Promise<void>;
|
|
36
|
+
export declare function buildOpenBrowserCommand(url: string, platform: NodeJS.Platform): [string, string[]];
|
|
35
37
|
export declare function exchangeCodeForTokens(client: SsoClient, code: string, redirectUri: string, verifier: string): Promise<SsoTokens>;
|
|
36
38
|
export declare function refreshSsoAccessToken(client: SsoClient, refreshToken: string): Promise<string>;
|
package/dist/auth/sso.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.refreshSsoAccessToken = exports.exchangeCodeForTokens = exports.openBrowser = exports.canOpenBrowser = exports.listenForLoopbackCode = exports.parsePastedSignInCode = exports.buildAuthorizeUrl = exports.
|
|
3
|
+
exports.refreshSsoAccessToken = exports.exchangeCodeForTokens = exports.buildOpenBrowserCommand = exports.openBrowser = exports.canOpenBrowser = exports.listenForLoopbackCode = exports.parsePastedSignInCode = exports.buildAuthorizeUrl = exports.createSignInAttempt = exports.fetchSsoDomainCheck = exports.LOOPBACK_CALLBACK_URL = exports.LOOPBACK_PORT = void 0;
|
|
4
4
|
const node_crypto_1 = require("node:crypto");
|
|
5
5
|
const node_http_1 = require("node:http");
|
|
6
6
|
const node_child_process_1 = require("node:child_process");
|
|
7
|
+
const sign_in_error_1 = require("./sign-in-error");
|
|
8
|
+
// Must match the CLI client's loopback callback URL in contrail-api resources/cognito.
|
|
7
9
|
exports.LOOPBACK_PORT = 7731;
|
|
8
10
|
exports.LOOPBACK_CALLBACK_URL = `http://localhost:${exports.LOOPBACK_PORT}/callback`;
|
|
9
11
|
const BROWSER_SIGN_IN_TIMEOUT_MS = 5 * 60 * 1000;
|
|
@@ -12,7 +14,7 @@ async function fetchSsoDomainCheck(email, apiGateway) {
|
|
|
12
14
|
const domain = email.split('@').pop().toLowerCase();
|
|
13
15
|
const response = await fetch(`${apiGateway}/sso-login/domain-check/${encodeURIComponent(domain)}`);
|
|
14
16
|
if (!response.ok) {
|
|
15
|
-
throw new
|
|
17
|
+
throw new sign_in_error_1.SignInError('SSO_DOMAIN_CHECK_FAILED', 'Could not check whether your email domain signs in with SSO.', { domain, status: response.status });
|
|
16
18
|
}
|
|
17
19
|
const body = await response.text();
|
|
18
20
|
if (!body) {
|
|
@@ -22,25 +24,27 @@ async function fetchSsoDomainCheck(email, apiGateway) {
|
|
|
22
24
|
return identityProvider ? { kind: 'cognito', identityProvider } : { kind: 'legacy' };
|
|
23
25
|
}
|
|
24
26
|
exports.fetchSsoDomainCheck = fetchSsoDomainCheck;
|
|
25
|
-
function
|
|
27
|
+
function createSignInAttempt() {
|
|
28
|
+
// RFC 7636 needs a 43-128 character verifier: 32 random bytes encode to 43.
|
|
26
29
|
const verifier = (0, node_crypto_1.randomBytes)(32).toString('base64url');
|
|
27
30
|
return {
|
|
28
31
|
verifier,
|
|
29
32
|
challenge: (0, node_crypto_1.createHash)('sha256').update(verifier).digest('base64url'),
|
|
33
|
+
// RFC 6749 section 10.10 asks for at most a 2^-128 chance of guessing state.
|
|
30
34
|
state: (0, node_crypto_1.randomBytes)(16).toString('base64url'),
|
|
31
35
|
};
|
|
32
36
|
}
|
|
33
|
-
exports.
|
|
34
|
-
function buildAuthorizeUrl(client, identityProvider, redirectUri,
|
|
37
|
+
exports.createSignInAttempt = createSignInAttempt;
|
|
38
|
+
function buildAuthorizeUrl(client, identityProvider, redirectUri, signInAttempt) {
|
|
35
39
|
const params = new URLSearchParams({
|
|
36
40
|
response_type: 'code',
|
|
37
41
|
client_id: client.clientId,
|
|
38
42
|
redirect_uri: redirectUri,
|
|
39
43
|
scope: OAUTH_SCOPES.join(' '),
|
|
40
44
|
identity_provider: identityProvider,
|
|
41
|
-
code_challenge:
|
|
45
|
+
code_challenge: signInAttempt.challenge,
|
|
42
46
|
code_challenge_method: 'S256',
|
|
43
|
-
state:
|
|
47
|
+
state: signInAttempt.state,
|
|
44
48
|
});
|
|
45
49
|
return `${client.domain}/oauth2/authorize?${params}`;
|
|
46
50
|
}
|
|
@@ -48,7 +52,7 @@ exports.buildAuthorizeUrl = buildAuthorizeUrl;
|
|
|
48
52
|
function parsePastedSignInCode(pasted, expectedState) {
|
|
49
53
|
const [code, state] = pasted.trim().split('#');
|
|
50
54
|
if (!code || state !== expectedState) {
|
|
51
|
-
throw new
|
|
55
|
+
throw new sign_in_error_1.SignInError('SSO_SIGN_IN_CODE_MISMATCH', 'That sign-in code is not from this login attempt. Run the command again.');
|
|
52
56
|
}
|
|
53
57
|
return code;
|
|
54
58
|
}
|
|
@@ -78,32 +82,40 @@ function listenForLoopbackCode(expectedState) {
|
|
|
78
82
|
: 'Sign-in failed. Return to your terminal.';
|
|
79
83
|
response
|
|
80
84
|
.writeHead(signedIn ? 200 : 400, { 'Content-Type': 'text/plain', Connection: 'close' })
|
|
81
|
-
.end(page, () => stopListening(() => {
|
|
85
|
+
.end(page, () => stopListening(request.socket, () => {
|
|
82
86
|
if (error) {
|
|
83
|
-
rejectCode(new
|
|
87
|
+
rejectCode(new sign_in_error_1.SignInError('SSO_SIGN_IN_REJECTED', 'Your identity provider did not complete the sign-in. Run the command again.', { oauthError: error }));
|
|
84
88
|
}
|
|
85
89
|
else if (!signedIn) {
|
|
86
|
-
rejectCode(new
|
|
90
|
+
rejectCode(new sign_in_error_1.SignInError('SSO_UNEXPECTED_CALLBACK', 'SSO sign-in returned an unexpected response. Run the command again.'));
|
|
87
91
|
}
|
|
88
92
|
else {
|
|
89
93
|
resolveCode(receivedCode);
|
|
90
94
|
}
|
|
91
95
|
}));
|
|
92
96
|
});
|
|
93
|
-
const
|
|
94
|
-
|
|
97
|
+
const openSockets = new Set();
|
|
98
|
+
server.on('connection', (socket) => {
|
|
99
|
+
openSockets.add(socket);
|
|
100
|
+
socket.once('close', () => openSockets.delete(socket));
|
|
101
|
+
});
|
|
102
|
+
const timeout = setTimeout(() => stopListening(undefined, () => rejectCode(new sign_in_error_1.SignInError('SSO_SIGN_IN_TIMED_OUT', 'Timed out waiting for the browser sign-in.'))), BROWSER_SIGN_IN_TIMEOUT_MS);
|
|
103
|
+
function stopListening(respondingSocket, settle) {
|
|
95
104
|
clearTimeout(timeout);
|
|
96
105
|
server.close();
|
|
106
|
+
openSockets.forEach((socket) => socket !== respondingSocket && socket.destroy());
|
|
97
107
|
settle();
|
|
98
108
|
}
|
|
99
109
|
return new Promise((resolve, reject) => {
|
|
100
110
|
server.once('error', (error) => {
|
|
101
111
|
clearTimeout(timeout);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
112
|
+
if (error.code !== 'EADDRINUSE') {
|
|
113
|
+
reject(error);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
reject(new sign_in_error_1.SignInError('SSO_LOOPBACK_PORT_IN_USE', 'The sign-in port is in use. Run contrail login --no-browser instead.', { port: exports.LOOPBACK_PORT }));
|
|
105
117
|
});
|
|
106
|
-
server.listen(exports.LOOPBACK_PORT, 'localhost', () => resolve({ code }));
|
|
118
|
+
server.listen(exports.LOOPBACK_PORT, 'localhost', () => resolve({ code, stop: () => stopListening(undefined, () => undefined) }));
|
|
107
119
|
});
|
|
108
120
|
}
|
|
109
121
|
exports.listenForLoopbackCode = listenForLoopbackCode;
|
|
@@ -134,6 +146,7 @@ function buildOpenBrowserCommand(url, platform) {
|
|
|
134
146
|
}
|
|
135
147
|
return ['xdg-open', [url]];
|
|
136
148
|
}
|
|
149
|
+
exports.buildOpenBrowserCommand = buildOpenBrowserCommand;
|
|
137
150
|
async function exchangeCodeForTokens(client, code, redirectUri, verifier) {
|
|
138
151
|
const tokens = await postToTokenEndpoint(client, {
|
|
139
152
|
grant_type: 'authorization_code',
|
|
@@ -162,7 +175,10 @@ async function postToTokenEndpoint(client, form) {
|
|
|
162
175
|
});
|
|
163
176
|
const body = await response.json();
|
|
164
177
|
if (!response.ok) {
|
|
165
|
-
throw new
|
|
178
|
+
throw new sign_in_error_1.SignInError('SSO_TOKEN_REQUEST_FAILED', 'Cognito rejected the token request.', {
|
|
179
|
+
status: response.status,
|
|
180
|
+
oauthError: body.error,
|
|
181
|
+
});
|
|
166
182
|
}
|
|
167
183
|
return body;
|
|
168
184
|
}
|
package/dist/auth/sso.spec.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const node_crypto_1 = require("node:crypto");
|
|
4
|
+
const node_net_1 = require("node:net");
|
|
4
5
|
const sso_1 = require("./sso");
|
|
5
6
|
const ssoClient = {
|
|
6
7
|
domain: 'https://dev-vibeiq.auth.us-east-1.amazoncognito.com',
|
|
7
8
|
clientId: 'cli-client',
|
|
8
9
|
};
|
|
9
|
-
describe('
|
|
10
|
+
describe('createSignInAttempt', () => {
|
|
10
11
|
it('should derive the challenge as the base64url SHA-256 of the verifier', () => {
|
|
11
|
-
const
|
|
12
|
-
expect(
|
|
12
|
+
const signInAttempt = (0, sso_1.createSignInAttempt)();
|
|
13
|
+
expect(signInAttempt.challenge).toBe((0, node_crypto_1.createHash)('sha256').update(signInAttempt.verifier).digest('base64url'));
|
|
14
|
+
});
|
|
15
|
+
it('should make a verifier of at least the 43 characters PKCE requires', () => {
|
|
16
|
+
expect((0, sso_1.createSignInAttempt)().verifier.length).toBeGreaterThanOrEqual(43);
|
|
13
17
|
});
|
|
14
18
|
});
|
|
15
19
|
describe('buildAuthorizeUrl', () => {
|
|
@@ -37,10 +41,10 @@ describe('parsePastedSignInCode', () => {
|
|
|
37
41
|
expect((0, sso_1.parsePastedSignInCode)(' the-code#the-state \n', 'the-state')).toBe('the-code');
|
|
38
42
|
});
|
|
39
43
|
it('should reject a code from another attempt', () => {
|
|
40
|
-
expect(() => (0, sso_1.parsePastedSignInCode)('the-code#other-state', 'the-state')).toThrow(
|
|
44
|
+
expect(() => (0, sso_1.parsePastedSignInCode)('the-code#other-state', 'the-state')).toThrow(expect.objectContaining({ code: 'SSO_SIGN_IN_CODE_MISMATCH' }));
|
|
41
45
|
});
|
|
42
46
|
it('should reject a code pasted without its state', () => {
|
|
43
|
-
expect(() => (0, sso_1.parsePastedSignInCode)('the-code', 'the-state')).toThrow(
|
|
47
|
+
expect(() => (0, sso_1.parsePastedSignInCode)('the-code', 'the-state')).toThrow(expect.objectContaining({ code: 'SSO_SIGN_IN_CODE_MISMATCH' }));
|
|
44
48
|
});
|
|
45
49
|
});
|
|
46
50
|
describe('canOpenBrowser', () => {
|
|
@@ -87,7 +91,10 @@ describe('fetchSsoDomainCheck', () => {
|
|
|
87
91
|
});
|
|
88
92
|
it('should fail when the lookup fails', async () => {
|
|
89
93
|
stubDomainCheckFetch('{}', 502);
|
|
90
|
-
await expect((0, sso_1.fetchSsoDomainCheck)('dev@example.com', 'https://api')).rejects.
|
|
94
|
+
await expect((0, sso_1.fetchSsoDomainCheck)('dev@example.com', 'https://api')).rejects.toMatchObject({
|
|
95
|
+
code: 'SSO_DOMAIN_CHECK_FAILED',
|
|
96
|
+
details: { domain: 'example.com', status: 502 },
|
|
97
|
+
});
|
|
91
98
|
});
|
|
92
99
|
});
|
|
93
100
|
describe('listenForLoopbackCode', () => {
|
|
@@ -106,23 +113,66 @@ describe('listenForLoopbackCode', () => {
|
|
|
106
113
|
});
|
|
107
114
|
it('should reject a redirect for this attempt that carries no code', async () => {
|
|
108
115
|
const listener = await (0, sso_1.listenForLoopbackCode)('the-state');
|
|
109
|
-
const rejection = expect(listener.code).rejects.
|
|
116
|
+
const rejection = expect(listener.code).rejects.toMatchObject({
|
|
117
|
+
code: 'SSO_UNEXPECTED_CALLBACK',
|
|
118
|
+
});
|
|
110
119
|
const response = await fetch(`${sso_1.LOOPBACK_CALLBACK_URL}?state=the-state`);
|
|
111
120
|
expect(response.status).toBe(400);
|
|
112
121
|
await rejection;
|
|
113
122
|
});
|
|
114
123
|
it('should reject when the identity provider reports an error', async () => {
|
|
115
124
|
const listener = await (0, sso_1.listenForLoopbackCode)('the-state');
|
|
116
|
-
const rejection = expect(listener.code).rejects.
|
|
125
|
+
const rejection = expect(listener.code).rejects.toMatchObject({
|
|
126
|
+
code: 'SSO_SIGN_IN_REJECTED',
|
|
127
|
+
details: { oauthError: 'User cancelled' },
|
|
128
|
+
});
|
|
117
129
|
await fetch(`${sso_1.LOOPBACK_CALLBACK_URL}?error=access_denied&error_description=User%20cancelled&state=the-state`);
|
|
118
130
|
await rejection;
|
|
119
131
|
});
|
|
132
|
+
it('should close idle browser connections once the code arrives', async () => {
|
|
133
|
+
const listener = await (0, sso_1.listenForLoopbackCode)('the-state');
|
|
134
|
+
const idleConnection = (0, node_net_1.connect)(sso_1.LOOPBACK_PORT, 'localhost');
|
|
135
|
+
await new Promise((resolve) => idleConnection.once('connect', resolve));
|
|
136
|
+
const idleConnectionClosed = new Promise((resolve) => idleConnection.once('close', resolve));
|
|
137
|
+
await fetch(`${sso_1.LOOPBACK_CALLBACK_URL}?code=the-code&state=the-state`);
|
|
138
|
+
await expect(listener.code).resolves.toBe('the-code');
|
|
139
|
+
await expect(idleConnectionClosed).resolves.toBe(false);
|
|
140
|
+
});
|
|
120
141
|
it('should tell the user to paste a code instead when the port is taken', async () => {
|
|
121
142
|
const listener = await (0, sso_1.listenForLoopbackCode)('the-state');
|
|
122
|
-
await expect((0, sso_1.listenForLoopbackCode)('another-state')).rejects.
|
|
143
|
+
await expect((0, sso_1.listenForLoopbackCode)('another-state')).rejects.toMatchObject({
|
|
144
|
+
code: 'SSO_LOOPBACK_PORT_IN_USE',
|
|
145
|
+
details: { port: sso_1.LOOPBACK_PORT },
|
|
146
|
+
});
|
|
123
147
|
await fetch(`${sso_1.LOOPBACK_CALLBACK_URL}?code=the-code&state=the-state`);
|
|
124
148
|
await listener.code;
|
|
125
149
|
});
|
|
150
|
+
it('should free the port when stopped', async () => {
|
|
151
|
+
const listener = await (0, sso_1.listenForLoopbackCode)('the-state');
|
|
152
|
+
listener.stop();
|
|
153
|
+
const nextListener = await (0, sso_1.listenForLoopbackCode)('next-state');
|
|
154
|
+
nextListener.stop();
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
describe('buildOpenBrowserCommand', () => {
|
|
158
|
+
it('should use open on a Mac', () => {
|
|
159
|
+
expect((0, sso_1.buildOpenBrowserCommand)('https://sign.in', 'darwin')).toEqual([
|
|
160
|
+
'open',
|
|
161
|
+
['https://sign.in'],
|
|
162
|
+
]);
|
|
163
|
+
});
|
|
164
|
+
it('should pass the URL through rundll32 on Windows so the shell cannot split it', () => {
|
|
165
|
+
expect((0, sso_1.buildOpenBrowserCommand)('https://sign.in?a=1&b=2', 'win32')).toEqual([
|
|
166
|
+
'rundll32',
|
|
167
|
+
['url.dll,FileProtocolHandler', 'https://sign.in?a=1&b=2'],
|
|
168
|
+
]);
|
|
169
|
+
});
|
|
170
|
+
it('should use xdg-open on Linux', () => {
|
|
171
|
+
expect((0, sso_1.buildOpenBrowserCommand)('https://sign.in', 'linux')).toEqual([
|
|
172
|
+
'xdg-open',
|
|
173
|
+
['https://sign.in'],
|
|
174
|
+
]);
|
|
175
|
+
});
|
|
126
176
|
});
|
|
127
177
|
describe('exchangeCodeForTokens', () => {
|
|
128
178
|
const originalFetch = global.fetch;
|
|
@@ -133,6 +183,9 @@ describe('exchangeCodeForTokens', () => {
|
|
|
133
183
|
global.fetch = jest
|
|
134
184
|
.fn()
|
|
135
185
|
.mockResolvedValue(new Response(JSON.stringify({ error: 'invalid_grant' }), { status: 400 }));
|
|
136
|
-
await expect((0, sso_1.exchangeCodeForTokens)(ssoClient, 'the-code', sso_1.LOOPBACK_CALLBACK_URL, 'verifier')).rejects.
|
|
186
|
+
await expect((0, sso_1.exchangeCodeForTokens)(ssoClient, 'the-code', sso_1.LOOPBACK_CALLBACK_URL, 'verifier')).rejects.toMatchObject({
|
|
187
|
+
code: 'SSO_TOKEN_REQUEST_FAILED',
|
|
188
|
+
details: { status: 400, oauthError: 'invalid_grant' },
|
|
189
|
+
});
|
|
137
190
|
});
|
|
138
191
|
});
|
package/dist/basecommand.d.ts
CHANGED
|
@@ -11,5 +11,8 @@ export declare abstract class BaseCommand extends Command {
|
|
|
11
11
|
protected args: any;
|
|
12
12
|
init(): Promise<void>;
|
|
13
13
|
setLogLevel(logLevel: string, config?: any): void;
|
|
14
|
+
protected catch(error: Error & {
|
|
15
|
+
exitCode?: number;
|
|
16
|
+
}): Promise<unknown>;
|
|
14
17
|
private confirmEnv;
|
|
15
18
|
}
|
package/dist/basecommand.js
CHANGED
|
@@ -3,11 +3,12 @@ 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");
|
|
6
7
|
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");
|
|
11
|
+
const sign_in_error_1 = require("./auth/sign-in-error");
|
|
11
12
|
const baseFlags_1 = require("./baseFlags");
|
|
12
13
|
class BaseCommand extends core_1.Command {
|
|
13
14
|
static description = 'Global Flags';
|
|
@@ -48,11 +49,17 @@ class BaseCommand extends core_1.Command {
|
|
|
48
49
|
logger_1.default.level = config.logLevel;
|
|
49
50
|
}
|
|
50
51
|
}
|
|
52
|
+
async catch(error) {
|
|
53
|
+
if (error instanceof sign_in_error_1.SignInError) {
|
|
54
|
+
this.error((0, sign_in_error_1.formatErrorForTerminal)(error), { exit: 1 });
|
|
55
|
+
}
|
|
56
|
+
return super.catch(error);
|
|
57
|
+
}
|
|
51
58
|
async confirmEnv() {
|
|
52
59
|
let config = await (0, config_1.getConfig)();
|
|
53
60
|
if ((0, lodash_1.keys)(config).length === 0) {
|
|
54
61
|
await (0, login_1.authUser)().catch((e) => {
|
|
55
|
-
console.log(`Error: ${e
|
|
62
|
+
console.log(`Error: ${(0, sign_in_error_1.formatErrorForTerminal)(e)}\n\nCheck if you are using the correct environment configuration and credentials.`);
|
|
56
63
|
this.exit(1);
|
|
57
64
|
});
|
|
58
65
|
config = await (0, config_1.getConfig)();
|
|
@@ -73,7 +80,7 @@ class BaseCommand extends core_1.Command {
|
|
|
73
80
|
choices: ['yes', 'no'],
|
|
74
81
|
default: 'no',
|
|
75
82
|
});
|
|
76
|
-
const { confirm } = await
|
|
83
|
+
const { confirm } = await (0, common_1.promptOnStderr)(questions);
|
|
77
84
|
if (confirm === 'no') {
|
|
78
85
|
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
86
|
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
|
+
this.log(`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
|
+
this.log(`App API key: (app:${appFound.apiKey.apiKey})`);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { PropertyLevel } from '@contrail/types';
|
|
2
|
+
import { ColonDelimited, TypeProperty as ExtendedTypeProperty, TypeReferencesCacheByPath } from '../../api/types';
|
|
3
|
+
import { TypeWithProperties } from '../../api/types';
|
|
4
|
+
import { BaseCommand } from '../../basecommand';
|
|
5
|
+
import { Role } from '../../helpers/entities';
|
|
6
|
+
export default class CreateEntity extends BaseCommand {
|
|
7
|
+
static description: string;
|
|
8
|
+
static examples: string[];
|
|
9
|
+
static flags: {
|
|
10
|
+
count: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
11
|
+
dryRun: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
inputFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
13
|
+
outputFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
14
|
+
generateValues: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
15
|
+
readableIds: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
skipHydrateRelationships: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
17
|
+
suffix: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
18
|
+
apiVersion: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
19
|
+
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
20
|
+
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
21
|
+
};
|
|
22
|
+
static args: {
|
|
23
|
+
typePath: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
24
|
+
};
|
|
25
|
+
static strict: boolean;
|
|
26
|
+
init(): Promise<void>;
|
|
27
|
+
run(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export type CreateSummary = {
|
|
30
|
+
created: any[];
|
|
31
|
+
failed: {
|
|
32
|
+
input: any;
|
|
33
|
+
error: string;
|
|
34
|
+
}[];
|
|
35
|
+
};
|
|
36
|
+
export declare function summarizeSettledCreates(inputs: any[], settled: PromiseSettledResult<any>[]): CreateSummary;
|
|
37
|
+
export declare function pickRandomPropertyValues(type: TypeWithProperties, objectReferencesCache: ObjectReferenceCachesByTypePath, typeReferencesCache: TypeReferencesCacheByPath, roles?: Role[], suppliedSlugs?: Set<string>): any;
|
|
38
|
+
export type WithId = {
|
|
39
|
+
id: string;
|
|
40
|
+
[key: string]: any;
|
|
41
|
+
};
|
|
42
|
+
export type ObjectReferenceCache = Map<string, WithId>;
|
|
43
|
+
type ObjectReferenceCachesByTypePath = Map<string, ObjectReferenceCache>;
|
|
44
|
+
export declare function pickRandomValueForProperty(property: ExtendedTypeProperty, objectReferencesCache: ObjectReferenceCachesByTypePath, typeReferencesCache: TypeReferencesCacheByPath): number | string | string[] | boolean | null;
|
|
45
|
+
export declare function getReferencedObjectPaths(type: TypeWithProperties): ColonDelimited[];
|
|
46
|
+
export declare function buildObjectReferenceCache(entities: any[]): ObjectReferenceCache;
|
|
47
|
+
export declare function selectRandomObject(cache: ObjectReferenceCache): WithId;
|
|
48
|
+
export declare function doesPropertyLevelMatchRole(propertyLevel: PropertyLevel, role: Role): boolean;
|
|
49
|
+
export {};
|