@contentstack/cli-auth 1.0.0 → 1.0.1
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 +7 -7
- package/lib/commands/auth/tokens/add.js +9 -19
- package/lib/utils/tokens-validation.js +36 -9
- package/messages/index.json +47 -0
- package/oclif.manifest.json +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
|
|
|
18
18
|
$ csdx COMMAND
|
|
19
19
|
running command...
|
|
20
20
|
$ csdx (-v|--version|version)
|
|
21
|
-
@contentstack/cli-auth/1.0.
|
|
21
|
+
@contentstack/cli-auth/1.0.1 darwin-arm64 node-v16.17.0
|
|
22
22
|
$ csdx --help [COMMAND]
|
|
23
23
|
USAGE
|
|
24
24
|
$ csdx COMMAND
|
|
@@ -59,7 +59,7 @@ EXAMPLES
|
|
|
59
59
|
$ csdx auth:login --username <username> --password <password>
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
_See code: [src/commands/auth/login.ts](https://github.com/contentstack/cli/blob/v1.0.
|
|
62
|
+
_See code: [src/commands/auth/login.ts](https://github.com/contentstack/cli/blob/v1.0.1/src/commands/auth/login.ts)_
|
|
63
63
|
|
|
64
64
|
## `csdx auth:logout`
|
|
65
65
|
|
|
@@ -81,7 +81,7 @@ EXAMPLES
|
|
|
81
81
|
$ csdx auth:logout --yes
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
_See code: [src/commands/auth/logout.ts](https://github.com/contentstack/cli/blob/v1.0.
|
|
84
|
+
_See code: [src/commands/auth/logout.ts](https://github.com/contentstack/cli/blob/v1.0.1/src/commands/auth/logout.ts)_
|
|
85
85
|
|
|
86
86
|
## `csdx auth:tokens`
|
|
87
87
|
|
|
@@ -108,7 +108,7 @@ EXAMPLE
|
|
|
108
108
|
$ csdx auth:tokens
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
_See code: [src/commands/auth/tokens/index.ts](https://github.com/contentstack/cli/blob/v1.0.
|
|
111
|
+
_See code: [src/commands/auth/tokens/index.ts](https://github.com/contentstack/cli/blob/v1.0.1/src/commands/auth/tokens/index.ts)_
|
|
112
112
|
|
|
113
113
|
## `csdx auth:tokens:add [-a <value>] [--delivery] [--management] [-e <value>] [-k <value>] [-y] [--token <value>]`
|
|
114
114
|
|
|
@@ -142,7 +142,7 @@ EXAMPLES
|
|
|
142
142
|
token>
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
-
_See code: [src/commands/auth/tokens/add.ts](https://github.com/contentstack/cli/blob/v1.0.
|
|
145
|
+
_See code: [src/commands/auth/tokens/add.ts](https://github.com/contentstack/cli/blob/v1.0.1/src/commands/auth/tokens/add.ts)_
|
|
146
146
|
|
|
147
147
|
## `csdx auth:tokens:remove`
|
|
148
148
|
|
|
@@ -161,7 +161,7 @@ EXAMPLES
|
|
|
161
161
|
$ csdx auth:tokens:remove -a <alias>
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
-
_See code: [src/commands/auth/tokens/remove.ts](https://github.com/contentstack/cli/blob/v1.0.
|
|
164
|
+
_See code: [src/commands/auth/tokens/remove.ts](https://github.com/contentstack/cli/blob/v1.0.1/src/commands/auth/tokens/remove.ts)_
|
|
165
165
|
|
|
166
166
|
## `csdx auth:whoami`
|
|
167
167
|
|
|
@@ -178,5 +178,5 @@ EXAMPLE
|
|
|
178
178
|
$ csdx auth:whoami
|
|
179
179
|
```
|
|
180
180
|
|
|
181
|
-
_See code: [src/commands/auth/whoami.ts](https://github.com/contentstack/cli/blob/v1.0.
|
|
181
|
+
_See code: [src/commands/auth/whoami.ts](https://github.com/contentstack/cli/blob/v1.0.1/src/commands/auth/whoami.ts)_
|
|
182
182
|
<!-- commandsstop -->
|
|
@@ -6,7 +6,6 @@ const interactive_1 = require("../../../utils/interactive");
|
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
7
|
class TokensAddCommand extends cli_command_1.Command {
|
|
8
8
|
async run() {
|
|
9
|
-
this.managementAPIClient = { host: this.cmaHost, authtoken: this.authToken };
|
|
10
9
|
const { flags: addTokenFlags } = this.parse(TokensAddCommand);
|
|
11
10
|
let isAliasExist = false;
|
|
12
11
|
const skipAliasReplaceConfirmation = addTokenFlags.force || addTokenFlags.yes;
|
|
@@ -44,36 +43,27 @@ class TokensAddCommand extends cli_command_1.Command {
|
|
|
44
43
|
if (!apiKey) {
|
|
45
44
|
apiKey = await cli_utilities_1.cliux.inquire({ type: 'input', message: 'CLI_AUTH_TOKENS_ADD_ENTER_API_KEY', name: 'apiKey' });
|
|
46
45
|
}
|
|
47
|
-
const apiKeyValidationResult = await utils_1.tokenValidation.validateAPIKey(this.managementAPIClient, apiKey);
|
|
48
|
-
if (!apiKeyValidationResult.valid) {
|
|
49
|
-
throw new cli_utilities_1.CLIError({ message: apiKeyValidationResult.message });
|
|
50
|
-
}
|
|
51
46
|
if (!token) {
|
|
52
47
|
token = await cli_utilities_1.cliux.inquire({ type: 'input', message: 'CLI_AUTH_TOKENS_ADD_ENTER_TOKEN', name: 'token' });
|
|
53
48
|
}
|
|
49
|
+
if (isDelivery && !environment) {
|
|
50
|
+
environment = await cli_utilities_1.cliux.inquire({
|
|
51
|
+
type: 'input',
|
|
52
|
+
message: 'CLI_AUTH_TOKENS_ADD_ENTER_ENVIRONMENT',
|
|
53
|
+
name: 'env',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
54
56
|
let tokenValidationResult;
|
|
55
57
|
if (type === 'delivery') {
|
|
56
|
-
tokenValidationResult = await utils_1.tokenValidation.validateDeliveryToken(this.
|
|
58
|
+
tokenValidationResult = await utils_1.tokenValidation.validateDeliveryToken(this.deliveryAPIClient, apiKey, token, environment, this.region.name, this.cdaHost);
|
|
57
59
|
}
|
|
58
60
|
else if (type === 'management') {
|
|
61
|
+
this.managementAPIClient = { host: this.cmaHost, authorization: token, api_key: apiKey };
|
|
59
62
|
tokenValidationResult = await utils_1.tokenValidation.validateManagementToken(this.managementAPIClient, apiKey, token);
|
|
60
63
|
}
|
|
61
64
|
if (!tokenValidationResult.valid) {
|
|
62
65
|
throw new cli_utilities_1.CLIError(tokenValidationResult.message);
|
|
63
66
|
}
|
|
64
|
-
if (isDelivery && !environment) {
|
|
65
|
-
environment = await cli_utilities_1.cliux.inquire({
|
|
66
|
-
type: 'input',
|
|
67
|
-
message: 'CLI_AUTH_TOKENS_ADD_ENTER_ENVIRONMENT',
|
|
68
|
-
name: 'env',
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
if (environment) {
|
|
72
|
-
const envValidationResult = await utils_1.tokenValidation.validateEnvironment(this.managementAPIClient, apiKey, environment);
|
|
73
|
-
if (!envValidationResult.valid) {
|
|
74
|
-
throw new cli_utilities_1.CLIError(envValidationResult.message);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
67
|
if (isManagement) {
|
|
78
68
|
cli_utilities_1.configHandler.set(`${configKeyTokens}.${alias}`, { token, apiKey, type });
|
|
79
69
|
}
|
|
@@ -7,18 +7,32 @@ const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
|
7
7
|
* @param contentStackClient
|
|
8
8
|
* @param apiKey
|
|
9
9
|
* @param deliveryToken
|
|
10
|
+
* @param environment
|
|
11
|
+
* @param region
|
|
10
12
|
* @returns
|
|
11
13
|
*/
|
|
12
|
-
const validateDeliveryToken = async (contentStackClient, apiKey, deliveryToken) => {
|
|
14
|
+
const validateDeliveryToken = async (contentStackClient, apiKey, deliveryToken, environment, region, host) => {
|
|
15
|
+
var _a;
|
|
13
16
|
let result;
|
|
14
17
|
try {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const regionMap = {
|
|
19
|
+
EU: 'eu',
|
|
20
|
+
NA: 'us',
|
|
21
|
+
AZURE_NA: 'azure-na',
|
|
22
|
+
};
|
|
23
|
+
const stack = contentStackClient
|
|
24
|
+
.Stack({
|
|
25
|
+
api_key: apiKey,
|
|
26
|
+
delivery_token: deliveryToken,
|
|
27
|
+
environment,
|
|
28
|
+
region: regionMap[region],
|
|
29
|
+
host,
|
|
30
|
+
});
|
|
31
|
+
const parsedHost = host.replace(/^https?:\/\//, '');
|
|
32
|
+
stack.setHost(parsedHost);
|
|
33
|
+
const deliveryTokenResult = await stack.getContentTypes({ limit: 1 });
|
|
20
34
|
cli_utilities_1.logger.debug('delivery token validation result', deliveryTokenResult);
|
|
21
|
-
if (
|
|
35
|
+
if ((_a = deliveryTokenResult === null || deliveryTokenResult === void 0 ? void 0 : deliveryTokenResult.content_types) === null || _a === void 0 ? void 0 : _a.length) {
|
|
22
36
|
result = { valid: true, message: deliveryTokenResult };
|
|
23
37
|
}
|
|
24
38
|
else {
|
|
@@ -27,7 +41,15 @@ const validateDeliveryToken = async (contentStackClient, apiKey, deliveryToken)
|
|
|
27
41
|
}
|
|
28
42
|
catch (error) {
|
|
29
43
|
cli_utilities_1.logger.debug('validate delivery token error', error);
|
|
30
|
-
|
|
44
|
+
if (error.error_code === 109) {
|
|
45
|
+
result = { valid: false, message: cli_utilities_1.messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY') };
|
|
46
|
+
}
|
|
47
|
+
else if (error.error_code === 141) {
|
|
48
|
+
result = { valid: false, message: cli_utilities_1.messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_ENVIRONMENT_NAME') };
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
result = { valid: false, message: cli_utilities_1.messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_DELIVERY_TOKEN') };
|
|
52
|
+
}
|
|
31
53
|
}
|
|
32
54
|
return result;
|
|
33
55
|
};
|
|
@@ -82,7 +104,12 @@ const validateManagementToken = async (contentStackClient, apiKey, managementTok
|
|
|
82
104
|
}
|
|
83
105
|
catch (error) {
|
|
84
106
|
cli_utilities_1.logger.error('Failed to validate management token', error);
|
|
85
|
-
|
|
107
|
+
if (error.response && error.response.status === 401) {
|
|
108
|
+
result = { valid: false, message: cli_utilities_1.messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_MANAGEMENT_TOKEN') };
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
result = { valid: false, message: cli_utilities_1.messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY') };
|
|
112
|
+
}
|
|
86
113
|
}
|
|
87
114
|
return result;
|
|
88
115
|
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"CLI_AUTH_LOGIN_ENTER_EMAIL_ADDRESS": "Enter your email address",
|
|
3
|
+
"CLI_AUTH_LOGIN_ENTER_PASSWORD": "Enter your password",
|
|
4
|
+
"CLI_AUTH_LOGIN_SUCCESS": "Successfully logged in!!",
|
|
5
|
+
"CLI_AUTH_LOGIN_FAILED": "Login Error",
|
|
6
|
+
"CLI_AUTH_LOGIN_DESCRIPTION": "User session login",
|
|
7
|
+
"CLI_AUTH_LOGIN_FLAG_USERNAME": "User name",
|
|
8
|
+
"CLI_AUTH_LOGIN_FLAG_PASSWORD": "Password",
|
|
9
|
+
"CLI_AUTH_LOGIN_SECURITY_CODE_SEND_SUCCESS": "Security code sent to your mobile",
|
|
10
|
+
"CLI_AUTH_LOGIN_ASK_CHANNEL_FOR_SECURITY_CODE": "Two factor authentication enabled, please select a way to get the security code",
|
|
11
|
+
"CLI_AUTH_LOGIN_ENTER_SECURITY_CODE": "Please provide the security code",
|
|
12
|
+
"CLI_AUTH_LOGOUT_CONFIRM": "Are you sure you want to log out?",
|
|
13
|
+
"CLI_AUTH_LOGOUT_LOADER_START": "Logging out....",
|
|
14
|
+
"CLI_AUTH_LOGOUT_SUCCESS": "Successfully logged out",
|
|
15
|
+
"CLI_AUTH_LOGOUT_FAILED": "Error in logout, please login again",
|
|
16
|
+
"CLI_AUTH_LOGOUT_DESCRIPTION": "User session logout",
|
|
17
|
+
"CLI_AUTH_LOGOUT_FLAG_FORCE": "Force logging out for skipping the confirmation",
|
|
18
|
+
"CLI_AUTH_WHOAMI_LOGGED_IN_AS": "You are currently logged in with email",
|
|
19
|
+
"CLI_AUTH_WHOAMI_FAILED": "Failed to get the current user details",
|
|
20
|
+
"CLI_AUTH_WHOAMI_DESCRIPTION": "Display current users email address",
|
|
21
|
+
"CLI_AUTH_TOKENS_ADD_ASK_TOKEN_ALIAS": "Provide alias to store token",
|
|
22
|
+
"CLI_AUTH_TOKENS_ADD_CONFIRM_ALIAS_REPLACE": "Alias is already exists, do you want to replace?",
|
|
23
|
+
"CLI_AUTH_TOKENS_ADD_ENTER_API_KEY": "Enter the api key",
|
|
24
|
+
"CLI_AUTH_TOKENS_ADD_ENTER_TOKEN": "Enter the token",
|
|
25
|
+
"CLI_AUTH_TOKENS_ADD_ENTER_ENVIRONMENT": "Enter the environment name",
|
|
26
|
+
"CLI_AUTH_TOKENS_ADD_REPLACE_SUCCESS": "Successfully replaced the token",
|
|
27
|
+
"CLI_AUTH_TOKENS_ADD_SUCCESS": "Successfully added the token",
|
|
28
|
+
"CLI_AUTH_TOKENS_ADD_FAILED": "Failed to add the token",
|
|
29
|
+
"CLI_AUTH_TOKENS_ADD_DESCRIPTION": "Adds management/delivery tokens to your session to use it with further CLI command by default it adds management token if either of management or delivery flags are not set",
|
|
30
|
+
"CLI_AUTH_TOKENS_ADD_FLAG_DELIVERY_TOKEN": "Set this while saving delivery token",
|
|
31
|
+
"CLI_AUTH_TOKENS_ADD_FLAG_MANAGEMENT_TOKEN": "Set this while saving management token",
|
|
32
|
+
"CLI_AUTH_TOKENS_ADD_FLAG_ENVIRONMENT_NAME": "Environment name for delivery token",
|
|
33
|
+
"CLI_AUTH_TOKENS_REMOVE_SUCCESS": "Token removed successfully !!",
|
|
34
|
+
"CLI_AUTH_TOKENS_REMOVE_FAILED": "Failed to remove the selected token",
|
|
35
|
+
"CLI_AUTH_TOKENS_NOT_FOUND": "No tokens are added yet!",
|
|
36
|
+
"CLI_AUTH_TOKENS_REMOVE_SELECT_TOKEN": "Select tokens to remove",
|
|
37
|
+
"CLI_AUTH_TOKENS_REMOVE_DESCRIPTION": "Removes selected tokens",
|
|
38
|
+
"CLI_AUTH_TOKENS_LIST_NO_TOKENS": "No tokens are added. Use auth:tokens:add command to add tokens.",
|
|
39
|
+
"CLI_AUTH_TOKENS_LIST_FAILED": "Failed to list the tokens",
|
|
40
|
+
"CLI_AUTH_TOKENS_LIST_DESCRIPTION": "Lists all existing tokens added to the session",
|
|
41
|
+
"CLI_AUTH_TOKENS_VALIDATION_INVALID_DELIVERY_TOKEN": "Invalid delivery token",
|
|
42
|
+
"CLI_AUTH_TOKENS_VALIDATION_INVALID_ENVIRONMENT_NAME": "Invalid environment name",
|
|
43
|
+
"CLI_AUTH_TOKENS_VALIDATION_INVALID_MANAGEMENT_TOKEN": "Invalid management token",
|
|
44
|
+
"CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY": "Invalid api key",
|
|
45
|
+
"CLI_AUTH_EXIT_PROCESS": "Exiting the process...",
|
|
46
|
+
"CLI_SELECT_TOKEN_TYPE": "Select the type of token to add"
|
|
47
|
+
}
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.0.
|
|
1
|
+
{"version":"1.0.1","commands":{"auth:login":{"id":"auth:login","description":"User sessions login","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["login"],"examples":["$ csdx auth:login","$ csdx auth:login -u <username>","$ csdx auth:login -u <username> -p <password>","$ csdx auth:login --username <username>","$ csdx auth:login --username <username> --password <password>"],"flags":{"username":{"name":"username","type":"option","char":"u","description":"User name","required":false},"password":{"name":"password","type":"option","char":"p","description":"Password","required":false}},"args":[]},"auth:logout":{"id":"auth:logout","description":"User session logout","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["logout"],"examples":["$ csdx auth:logout","$ csdx auth:logout -y","$ csdx auth:logout --yes"],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Force log out by skipping the confirmation","required":false,"allowNo":false},"force":{"name":"force","type":"boolean","char":"f","description":"Force log out by skipping the confirmation","hidden":true,"required":false,"allowNo":false}},"args":[]},"auth:whoami":{"id":"auth:whoami","description":"Display current users email address","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["whoami"],"examples":["$ csdx auth:whoami"],"flags":{},"args":[]},"auth:tokens:add":{"id":"auth:tokens:add","description":"Adds management/delivery tokens to your session to use it with other CLI commands","usage":"auth:tokens:add [-a <value>] [--delivery] [--management] [-e <value>] [-k <value>] [-y] [--token <value>]","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":[],"examples":["$ csdx auth:tokens:add","$ csdx auth:tokens:add -a <alias>","$ csdx auth:tokens:add -k <stack api key>","$ csdx auth:tokens:add --delivery","$ csdx auth:tokens:add --management","$ csdx auth:tokens:add -e <environment>","$ csdx auth:tokens:add --token <token>","$ csdx auth:tokens:add -a <alias> -k <stack api key> --management --token <management token>","$ csdx auth:tokens:add -a <alias> -k <stack api key> --delivery -e <environment> --token <delivery token>","$ csdx auth:tokens:add --alias <alias> --stack-api-key <stack api key> --management --token <management token>","$ csdx auth:tokens:add --alias <alias> --stack-api-key <stack api key> --delivery -e <environment> --token <delivery token>"],"flags":{"alias":{"name":"alias","type":"option","char":"a","description":"Name of the token alias"},"delivery":{"name":"delivery","type":"boolean","char":"d","description":"Set this flag to save delivery token","allowNo":false},"management":{"name":"management","type":"boolean","char":"m","description":"Set this flag to save management token","allowNo":false},"environment":{"name":"environment","type":"option","char":"e","description":"Environment name for delivery token"},"stack-api-key":{"name":"stack-api-key","type":"option","char":"k","description":"Stack API Key"},"yes":{"name":"yes","type":"boolean","char":"y","description":"Use this flag to skip confirmation","allowNo":false},"token":{"name":"token","type":"option","char":"t","description":"Add the token name"},"api-key":{"name":"api-key","type":"option","description":"API Key","hidden":true},"force":{"name":"force","type":"boolean","char":"f","description":"Force adding","hidden":true,"allowNo":false}},"args":[]},"auth:tokens":{"id":"auth:tokens","description":"Lists all existing tokens added to the session","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":["tokens"],"examples":["$ csdx auth:tokens"],"flags":{"columns":{"name":"columns","type":"option","description":"only show provided columns (comma-separated)"},"sort":{"name":"sort","type":"option","description":"property to sort by (prepend '-' for descending)"},"filter":{"name":"filter","type":"option","description":"filter property by partial string matching, ex: name=foo"},"csv":{"name":"csv","type":"boolean","description":"output is csv format [alias: --output=csv]","allowNo":false},"output":{"name":"output","type":"option","description":"output in a more machine friendly format","options":["csv","json","yaml"]},"extended":{"name":"extended","type":"boolean","char":"x","description":"show extra columns","allowNo":false},"no-truncate":{"name":"no-truncate","type":"boolean","description":"do not truncate output to fit screen","allowNo":false},"no-header":{"name":"no-header","type":"boolean","description":"hide table header from output","allowNo":false}},"args":[]},"auth:tokens:remove":{"id":"auth:tokens:remove","description":"Removes selected tokens","pluginName":"@contentstack/cli-auth","pluginType":"core","aliases":[],"examples":["$ csdx auth:tokens:remove","$ csdx auth:tokens:remove -a <alias>"],"flags":{"alias":{"name":"alias","type":"option","char":"a","description":"Token alias"},"ignore":{"name":"ignore","type":"boolean","char":"i","description":"Ignore","allowNo":false}},"args":[]}}}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-auth",
|
|
3
3
|
"description": "Contentstack CLI plugin for authentication activities",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"scripts": {
|
|
@@ -59,7 +59,8 @@
|
|
|
59
59
|
"files": [
|
|
60
60
|
"/lib",
|
|
61
61
|
"/npm-shrinkwrap.json",
|
|
62
|
-
"/oclif.manifest.json"
|
|
62
|
+
"/oclif.manifest.json",
|
|
63
|
+
"/messages"
|
|
63
64
|
],
|
|
64
65
|
"homepage": "https://github.com/contentstack/cli",
|
|
65
66
|
"keywords": [
|