@automattic/vip 2.11.0 → 2.11.2

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 (99) hide show
  1. package/README.md +8 -0
  2. package/config/config.json +2 -2
  3. package/npm-shrinkwrap.json +1 -1
  4. package/package/dist/bin/vip-app-list.js +73 -0
  5. package/package/dist/bin/vip-app.js +76 -0
  6. package/package/dist/bin/vip-config-envvar-delete.js +97 -0
  7. package/package/dist/bin/vip-config-envvar-get-all.js +94 -0
  8. package/package/dist/bin/vip-config-envvar-get.js +79 -0
  9. package/package/dist/bin/vip-config-envvar-list.js +91 -0
  10. package/package/dist/bin/vip-config-envvar-set.js +123 -0
  11. package/package/dist/bin/vip-config-envvar.js +23 -0
  12. package/package/dist/bin/vip-config.js +20 -0
  13. package/package/dist/bin/vip-dev-env-create.js +105 -0
  14. package/package/dist/bin/vip-dev-env-destroy.js +56 -0
  15. package/package/dist/bin/vip-dev-env-exec.js +67 -0
  16. package/package/dist/bin/vip-dev-env-import-media.js +51 -0
  17. package/package/dist/bin/vip-dev-env-import-sql.js +83 -0
  18. package/package/dist/bin/vip-dev-env-import.js +32 -0
  19. package/package/dist/bin/vip-dev-env-info.js +61 -0
  20. package/package/dist/bin/vip-dev-env-list.js +46 -0
  21. package/package/dist/bin/vip-dev-env-start.js +77 -0
  22. package/package/dist/bin/vip-dev-env-stop.js +52 -0
  23. package/package/dist/bin/vip-dev-env-update.js +89 -0
  24. package/package/dist/bin/vip-dev-env.js +23 -0
  25. package/package/dist/bin/vip-import-media-abort.js +132 -0
  26. package/package/dist/bin/vip-import-media-status.js +84 -0
  27. package/package/dist/bin/vip-import-media.js +168 -0
  28. package/package/dist/bin/vip-import-sql-status.js +83 -0
  29. package/package/dist/bin/vip-import-sql.js +580 -0
  30. package/package/dist/bin/vip-import-validate-files.js +191 -0
  31. package/package/dist/bin/vip-import-validate-sql.js +34 -0
  32. package/package/dist/bin/vip-import.js +20 -0
  33. package/package/dist/bin/vip-logs.js +232 -0
  34. package/package/dist/bin/vip-search-replace.js +71 -0
  35. package/package/dist/bin/vip-sync.js +191 -0
  36. package/package/dist/bin/vip-whoami.js +67 -0
  37. package/package/dist/bin/vip-wp.js +555 -0
  38. package/package/dist/bin/vip.js +149 -0
  39. package/package/dist/lib/analytics/clients/client.js +1 -0
  40. package/package/dist/lib/analytics/clients/pendo.js +92 -0
  41. package/package/dist/lib/analytics/clients/stub.js +19 -0
  42. package/package/dist/lib/analytics/clients/tracks.js +128 -0
  43. package/package/dist/lib/analytics/index.js +45 -0
  44. package/package/dist/lib/api/app.js +70 -0
  45. package/package/dist/lib/api/feature-flags.js +39 -0
  46. package/package/dist/lib/api/user.js +58 -0
  47. package/package/dist/lib/api.js +136 -0
  48. package/package/dist/lib/app-logs/app-logs.js +70 -0
  49. package/package/dist/lib/cli/apiConfig.js +90 -0
  50. package/package/dist/lib/cli/command.js +606 -0
  51. package/package/dist/lib/cli/envAlias.js +60 -0
  52. package/package/dist/lib/cli/exit.js +33 -0
  53. package/package/dist/lib/cli/format.js +213 -0
  54. package/package/dist/lib/cli/pager.js +52 -0
  55. package/package/dist/lib/cli/progress.js +208 -0
  56. package/package/dist/lib/cli/prompt.js +37 -0
  57. package/package/dist/lib/cli/repo.js +77 -0
  58. package/package/dist/lib/client-file-uploader.js +602 -0
  59. package/package/dist/lib/constants/dev-environment.js +42 -0
  60. package/package/dist/lib/constants/file-size.js +14 -0
  61. package/package/dist/lib/dev-environment/dev-environment-cli.js +508 -0
  62. package/package/dist/lib/dev-environment/dev-environment-core.js +620 -0
  63. package/package/dist/lib/dev-environment/dev-environment-lando.js +330 -0
  64. package/package/dist/lib/dev-environment/types.js +1 -0
  65. package/package/dist/lib/env.js +36 -0
  66. package/package/dist/lib/envvar/api-delete.js +56 -0
  67. package/package/dist/lib/envvar/api-get-all.js +59 -0
  68. package/package/dist/lib/envvar/api-get.js +24 -0
  69. package/package/dist/lib/envvar/api-list.js +60 -0
  70. package/package/dist/lib/envvar/api-set.js +58 -0
  71. package/package/dist/lib/envvar/api.js +104 -0
  72. package/package/dist/lib/envvar/input.js +55 -0
  73. package/package/dist/lib/envvar/logging.js +33 -0
  74. package/package/dist/lib/envvar/read-file.js +43 -0
  75. package/package/dist/lib/http/socks-proxy-agent.js +25 -0
  76. package/package/dist/lib/keychain/browser.js +35 -0
  77. package/package/dist/lib/keychain/insecure.js +63 -0
  78. package/package/dist/lib/keychain/keychain.js +1 -0
  79. package/package/dist/lib/keychain/secure.js +36 -0
  80. package/package/dist/lib/keychain.js +36 -0
  81. package/package/dist/lib/media-import/media-file-import.js +34 -0
  82. package/package/dist/lib/media-import/progress.js +86 -0
  83. package/package/dist/lib/media-import/status.js +335 -0
  84. package/package/dist/lib/rollbar.js +35 -0
  85. package/package/dist/lib/search-and-replace.js +203 -0
  86. package/package/dist/lib/site-import/db-file-import.js +46 -0
  87. package/package/dist/lib/site-import/status.js +444 -0
  88. package/package/dist/lib/token.js +132 -0
  89. package/package/dist/lib/tracker.js +96 -0
  90. package/package/dist/lib/validations/is-multi-site-sql-dump.js +59 -0
  91. package/package/dist/lib/validations/is-multi-site.js +99 -0
  92. package/package/dist/lib/validations/line-by-line.js +92 -0
  93. package/package/dist/lib/validations/site-type.js +66 -0
  94. package/package/dist/lib/validations/sql.js +371 -0
  95. package/package/dist/lib/vip-import-validate-files.js +548 -0
  96. package/package/vip.iml +11 -0
  97. package/package.json +1 -1
  98. package/vip.iml +11 -0
  99. package/automattic-vip-2.11.0.tgz +0 -0
package/README.md CHANGED
@@ -26,6 +26,14 @@ By default, we record information about the usage of this tool using an in-house
26
26
 
27
27
  ## Changelog
28
28
 
29
+ ### 2.11.2 (12 May 2022)
30
+
31
+ - Hotfix to use correct production config.json in the NPM published package caused by a different NPM version in the build process.
32
+
33
+ ### 2.11.1 (12 May 2022)
34
+
35
+ - Hotfix to use correct production config.json in the NPM published package
36
+
29
37
  ### 2.11.0 (11 May 2022)
30
38
 
31
39
  - #1022 [dev-env] Validate docker installed
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "tracksUserType": "vip:user_id",
3
3
  "tracksAnonUserType": "anon",
4
- "tracksEventPrefix": "vip_cli_dev_",
5
- "environment": "development"
4
+ "tracksEventPrefix": "vip_cli_",
5
+ "environment": "production"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip",
3
- "version": "2.11.0",
3
+ "version": "2.11.2",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ "use strict";
7
+
8
+ var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
9
+
10
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
11
+
12
+ var _api = _interopRequireDefault(require("../lib/api"));
13
+
14
+ var _tracker = require("../lib/tracker");
15
+
16
+ var _rollbar = require("../lib/rollbar");
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ /**
21
+ * Internal dependencies
22
+ */
23
+ (0, _command.default)({
24
+ format: true
25
+ }).argv(process.argv, async () => {
26
+ const api = await (0, _api.default)();
27
+ await (0, _tracker.trackEvent)('app_list_command_execute');
28
+ let response;
29
+
30
+ try {
31
+ response = await api.query({
32
+ // $FlowFixMe: gql template is not supported by flow
33
+ query: (0, _graphqlTag.default)`query Apps( $first: Int, $after: String ) {
34
+ apps( first: $first, after: $after ) {
35
+ total,
36
+ nextCursor
37
+ edges {
38
+ id,
39
+ name,
40
+ repo
41
+ }
42
+ }
43
+ }`,
44
+ variables: {
45
+ first: 100,
46
+ after: null // TODO make dynamic
47
+
48
+ }
49
+ });
50
+ } catch (err) {
51
+ const message = err.toString();
52
+ await (0, _tracker.trackEvent)('app_list_command_fetch_error', {
53
+ error: message
54
+ });
55
+
56
+ _rollbar.rollbar.error(err);
57
+
58
+ console.log('Failed to fetch apps: %s', message);
59
+ return;
60
+ }
61
+
62
+ if (!response || !response.data || !response.data.apps || !response.data.apps.edges || !response.data.apps.edges.length) {
63
+ const message = 'No apps found';
64
+ await (0, _tracker.trackEvent)('app_list_command_fetch_error', {
65
+ error: message
66
+ });
67
+ console.log(message);
68
+ return;
69
+ }
70
+
71
+ await (0, _tracker.trackEvent)('app_list_command_success');
72
+ return response.data.apps.edges;
73
+ });
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ "use strict";
7
+
8
+ var _chalk = _interopRequireDefault(require("chalk"));
9
+
10
+ var _command = _interopRequireWildcard(require("../lib/cli/command"));
11
+
12
+ var _app = _interopRequireDefault(require("../lib/api/app"));
13
+
14
+ var _tracker = require("../lib/tracker");
15
+
16
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
+
18
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ /**
23
+ * Internal dependencies
24
+ */
25
+ (0, _command.default)({
26
+ requiredArgs: 1,
27
+ format: true
28
+ }).example('vip app <app>', 'Pass an app name or ID to get details about that app').example('vip app 123', 'Get details about the app with ID 123').example('vip app vip-test', 'Get details about the app named vip-test').command('list', 'List your VIP applications').argv(process.argv, async arg => {
29
+ await (0, _tracker.trackEvent)('app_command_execute');
30
+ let res;
31
+
32
+ try {
33
+ res = await (0, _app.default)(arg[0], 'id,repo,name,environments{id,appId,name,type,branch,currentCommit,primaryDomain{name},launched}');
34
+ } catch (err) {
35
+ await (0, _tracker.trackEvent)('app_command_fetch_error', {
36
+ error: `App ${arg[0]} does not exist`
37
+ });
38
+ console.log(`App ${_chalk.default.blueBright(arg[0])} does not exist`);
39
+ return;
40
+ }
41
+
42
+ if (!res || !res.environments) {
43
+ await (0, _tracker.trackEvent)('app_command_fetch_error', {
44
+ error: `App ${arg[0]} does not exist`
45
+ });
46
+ console.log(`App ${_chalk.default.blueBright(arg[0])} does not exist`);
47
+ return;
48
+ }
49
+
50
+ await (0, _tracker.trackEvent)('app_command_success'); // Clone the read-only response object so we can modify it
51
+
52
+ const clonedResponse = Object.assign({}, res);
53
+ const header = [{
54
+ key: 'id',
55
+ value: res.id
56
+ }, {
57
+ key: 'name',
58
+ value: res.name
59
+ }, {
60
+ key: 'repo',
61
+ value: res.repo
62
+ }];
63
+ clonedResponse.environments = clonedResponse.environments.map(env => {
64
+ const clonedEnv = Object.assign({}, env);
65
+ clonedEnv.name = (0, _command.getEnvIdentifier)(env); // Use the short version of git commit hash
66
+
67
+ clonedEnv.currentCommit = clonedEnv.currentCommit.substring(0, 7); // Flatten object
68
+
69
+ clonedEnv.primaryDomain = clonedEnv.primaryDomain.name;
70
+ return clonedEnv;
71
+ });
72
+ return {
73
+ header,
74
+ data: clonedResponse.environments
75
+ };
76
+ });
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ *
5
+ * @format
6
+ */
7
+
8
+ /**
9
+ * External dependencies
10
+ */
11
+ "use strict";
12
+
13
+ Object.defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ exports.deleteEnvVarCommand = deleteEnvVarCommand;
17
+
18
+ var _chalk = _interopRequireDefault(require("chalk"));
19
+
20
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
21
+
22
+ var _api = require("../lib/envvar/api");
23
+
24
+ var _input = require("../lib/envvar/input");
25
+
26
+ var _logging = require("../lib/envvar/logging");
27
+
28
+ var _rollbar = require("../lib/rollbar");
29
+
30
+ var _tracker = require("../lib/tracker");
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
+
34
+ /**
35
+ * Internal dependencies
36
+ */
37
+ const baseUsage = 'vip config envvar delete'; // Command examples
38
+
39
+ const examples = [{
40
+ usage: `${baseUsage} MY_VARIABLE`,
41
+ description: 'Permanently deletes the environment variable "MY_VARIABLE"'
42
+ }];
43
+
44
+ async function deleteEnvVarCommand(arg, opt) {
45
+ // Help the user by uppercasing input.
46
+ const name = arg[0].trim().toUpperCase();
47
+ const trackingParams = {
48
+ app_id: opt.app.id,
49
+ command: `${baseUsage} ${name}`,
50
+ env_id: opt.env.id,
51
+ org_id: opt.app.organization.id,
52
+ skip_confirm: !!opt.skipConfirmation,
53
+ variable_name: name
54
+ };
55
+ (0, _logging.debug)(`Request: Delete environment variable ${JSON.stringify(name)} for ${(0, _logging.getEnvContext)(opt.app, opt.env)}`);
56
+ await (0, _tracker.trackEvent)('envvar_delete_command_execute', trackingParams);
57
+
58
+ if (!(0, _api.validateNameWithMessage)(name)) {
59
+ await (0, _tracker.trackEvent)('envvar_delete_invalid_name', trackingParams);
60
+ process.exit(1);
61
+ }
62
+
63
+ if (!opt.skipConfirmation) {
64
+ await (0, _input.promptForValue)(`Type ${name} to confirm deletion:`, name).catch(async () => {
65
+ await (0, _tracker.trackEvent)('envvar_delete_user_cancelled_input', trackingParams);
66
+ (0, _input.cancel)();
67
+ });
68
+
69
+ if (!(await (0, _input.confirm)(`Are you sure? ${_chalk.default.bold.red('Deletion is permanent')} (y/N)`))) {
70
+ await (0, _tracker.trackEvent)('envvar_delete_user_cancelled_confirmation', trackingParams);
71
+ (0, _input.cancel)();
72
+ }
73
+ }
74
+
75
+ await (0, _api.deleteEnvVar)(opt.app.id, opt.env.id, name).catch(async err => {
76
+ _rollbar.rollbar.error(err);
77
+
78
+ await (0, _tracker.trackEvent)('envvar_delete_mutation_error', { ...trackingParams,
79
+ error: err.message
80
+ });
81
+ throw err;
82
+ });
83
+ await (0, _tracker.trackEvent)('envvar_delete_command_success', trackingParams);
84
+ console.log(_chalk.default.green(`Successfully deleted environment variable ${JSON.stringify(name)}`));
85
+
86
+ if (!opt.skipConfirmation) {
87
+ console.log(_chalk.default.bgYellow(_chalk.default.bold('Important:')), 'Updates to environment variables will not be available until the application’s next deploy.');
88
+ }
89
+ }
90
+
91
+ (0, _command.default)({
92
+ appContext: true,
93
+ appQuery: _api.appQuery,
94
+ envContext: true,
95
+ requiredArgs: 1,
96
+ usage: `${baseUsage} <VARIABLE_NAME>`
97
+ }).examples(examples).option('skip-confirmation', 'Skip manual confirmation of input (USE WITH CAUTION)', false).argv(process.argv, deleteEnvVarCommand);
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ *
5
+ * @format
6
+ */
7
+
8
+ /**
9
+ * External dependencies
10
+ */
11
+ "use strict";
12
+
13
+ Object.defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ exports.getAllEnvVarsCommand = getAllEnvVarsCommand;
17
+
18
+ var _chalk = _interopRequireDefault(require("chalk"));
19
+
20
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
21
+
22
+ var _format = require("../lib/cli/format");
23
+
24
+ var _api = require("../lib/envvar/api");
25
+
26
+ var _logging = require("../lib/envvar/logging");
27
+
28
+ var _rollbar = require("../lib/rollbar");
29
+
30
+ var _tracker = require("../lib/tracker");
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
+
34
+ /**
35
+ * Internal dependencies
36
+ */
37
+ const usage = 'vip config envvar get-all'; // Command examples
38
+
39
+ const examples = [{
40
+ usage,
41
+ description: 'Get the values of all environment variables'
42
+ }];
43
+
44
+ async function getAllEnvVarsCommand(arg, opt) {
45
+ const trackingParams = {
46
+ app_id: opt.app.id,
47
+ command: usage,
48
+ env_id: opt.env.id,
49
+ format: opt.format,
50
+ org_id: opt.app.organization.id
51
+ };
52
+ (0, _logging.debug)(`Request: Get all environment variables for ${(0, _logging.getEnvContext)(opt.app, opt.env)}`);
53
+ await (0, _tracker.trackEvent)('envvar_get_all_command_execute', trackingParams);
54
+ const envvars = await (0, _api.getEnvVars)(opt.app.id, opt.env.id).catch(async err => {
55
+ _rollbar.rollbar.error(err);
56
+
57
+ await (0, _tracker.trackEvent)('envvar_get_all_query_error', { ...trackingParams,
58
+ error: err.message
59
+ });
60
+ throw err;
61
+ });
62
+ await (0, _tracker.trackEvent)('envvar_get_all_command_success', trackingParams);
63
+
64
+ if (0 === envvars.length) {
65
+ console.log(_chalk.default.yellow('There are no environment variables'));
66
+ process.exit();
67
+ } // Vary data by expected format.
68
+
69
+
70
+ let key = 'name';
71
+
72
+ if ('keyValue' === opt.format) {
73
+ key = 'key';
74
+ } else if ('ids' === opt.format) {
75
+ key = 'id';
76
+ }
77
+
78
+ const envvarsObject = envvars.map(({
79
+ name: envvarName,
80
+ value
81
+ }) => ({
82
+ [key]: envvarName,
83
+ value
84
+ }));
85
+ console.log((0, _format.formatData)(envvarsObject, opt.format));
86
+ }
87
+
88
+ (0, _command.default)({
89
+ appContext: true,
90
+ appQuery: _api.appQuery,
91
+ envContext: true,
92
+ format: true,
93
+ usage
94
+ }).examples(examples).argv(process.argv, getAllEnvVarsCommand);
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ *
5
+ * @format
6
+ */
7
+
8
+ /**
9
+ * External dependencies
10
+ */
11
+ "use strict";
12
+
13
+ Object.defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ exports.getEnvVarCommand = getEnvVarCommand;
17
+
18
+ var _chalk = _interopRequireDefault(require("chalk"));
19
+
20
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
21
+
22
+ var _api = require("../lib/envvar/api");
23
+
24
+ var _logging = require("../lib/envvar/logging");
25
+
26
+ var _rollbar = require("../lib/rollbar");
27
+
28
+ var _tracker = require("../lib/tracker");
29
+
30
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
+
32
+ /**
33
+ * Internal dependencies
34
+ */
35
+ const baseUsage = 'vip config envvar get'; // Command examples
36
+
37
+ const examples = [{
38
+ usage: `${baseUsage} MY_VARIABLE`,
39
+ description: 'Get the value of the environment variable "MY_VARIABLE"'
40
+ }];
41
+
42
+ async function getEnvVarCommand(arg, opt) {
43
+ // Help the user by uppercasing input.
44
+ const name = arg[0].trim().toUpperCase();
45
+ const trackingParams = {
46
+ app_id: opt.app.id,
47
+ command: `${baseUsage} ${name}`,
48
+ env_id: opt.env.id,
49
+ org_id: opt.app.organization.id,
50
+ variable_name: name
51
+ };
52
+ (0, _logging.debug)(`Request: Get environment variable ${JSON.stringify(name)} for ${(0, _logging.getEnvContext)(opt.app, opt.env)}`);
53
+ await (0, _tracker.trackEvent)('envvar_get_command_execute', trackingParams);
54
+ const envvar = await (0, _api.getEnvVar)(opt.app.id, opt.env.id, name).catch(async err => {
55
+ _rollbar.rollbar.error(err);
56
+
57
+ await (0, _tracker.trackEvent)('envvar_get_query_error', { ...trackingParams,
58
+ error: err.message
59
+ });
60
+ throw err;
61
+ });
62
+ await (0, _tracker.trackEvent)('envvar_get_command_success', trackingParams);
63
+
64
+ if (!envvar) {
65
+ const message = `The environment variable ${JSON.stringify(name)} does not exist`;
66
+ console.log(_chalk.default.yellow(message));
67
+ process.exit();
68
+ }
69
+
70
+ console.log(envvar.value);
71
+ }
72
+
73
+ (0, _command.default)({
74
+ appContext: true,
75
+ appQuery: _api.appQuery,
76
+ envContext: true,
77
+ requiredArgs: 1,
78
+ usage: `${baseUsage} <VARIABLE_NAME>`
79
+ }).examples(examples).argv(process.argv, getEnvVarCommand);
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ *
5
+ * @format
6
+ */
7
+
8
+ /**
9
+ * External dependencies
10
+ */
11
+ "use strict";
12
+
13
+ Object.defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ exports.listEnvVarsCommand = listEnvVarsCommand;
17
+
18
+ var _chalk = _interopRequireDefault(require("chalk"));
19
+
20
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
21
+
22
+ var _format = require("../lib/cli/format");
23
+
24
+ var _api = require("../lib/envvar/api");
25
+
26
+ var _logging = require("../lib/envvar/logging");
27
+
28
+ var _rollbar = require("../lib/rollbar");
29
+
30
+ var _tracker = require("../lib/tracker");
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
+
34
+ /**
35
+ * Internal dependencies
36
+ */
37
+ const usage = 'vip config envvar list'; // Command examples
38
+
39
+ const examples = [{
40
+ usage,
41
+ description: 'Lists all environment variables (names only)'
42
+ }];
43
+
44
+ async function listEnvVarsCommand(arg, opt) {
45
+ const trackingParams = {
46
+ app_id: opt.app.id,
47
+ command: usage,
48
+ env_id: opt.env.id,
49
+ format: opt.format,
50
+ org_id: opt.app.organization.id
51
+ };
52
+ (0, _logging.debug)(`Request: list environment variables for ${(0, _logging.getEnvContext)(opt.app, opt.env)}`);
53
+ await (0, _tracker.trackEvent)('envvar_list_command_execute', trackingParams);
54
+ const envvars = await (0, _api.listEnvVars)(opt.app.id, opt.env.id).catch(async err => {
55
+ _rollbar.rollbar.error(err);
56
+
57
+ await (0, _tracker.trackEvent)('envvar_list_query_error', { ...trackingParams,
58
+ error: err.message
59
+ });
60
+ throw err;
61
+ });
62
+ await (0, _tracker.trackEvent)('envvar_list_command_success', trackingParams);
63
+
64
+ if (0 === envvars.length) {
65
+ console.log(_chalk.default.yellow('There are no environment variables'));
66
+ process.exit();
67
+ } // Vary data by expected format.
68
+
69
+
70
+ let key = 'name';
71
+
72
+ if ('keyValue' === opt.format) {
73
+ key = 'key';
74
+ } else if ('ids' === opt.format) {
75
+ key = 'id';
76
+ } // Format as an object for formatData.
77
+
78
+
79
+ const envvarsObject = envvars.map(name => ({
80
+ [key]: name
81
+ }));
82
+ console.log((0, _format.formatData)(envvarsObject, opt.format));
83
+ }
84
+
85
+ (0, _command.default)({
86
+ appContext: true,
87
+ appQuery: _api.appQuery,
88
+ envContext: true,
89
+ format: true,
90
+ usage
91
+ }).examples(examples).argv(process.argv, listEnvVarsCommand);
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ *
5
+ * @format
6
+ */
7
+
8
+ /**
9
+ * External dependencies
10
+ */
11
+ "use strict";
12
+
13
+ Object.defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ exports.setEnvVarCommand = setEnvVarCommand;
17
+
18
+ var _chalk = _interopRequireDefault(require("chalk"));
19
+
20
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
21
+
22
+ var _api = require("../lib/envvar/api");
23
+
24
+ var _input = require("../lib/envvar/input");
25
+
26
+ var _logging = require("../lib/envvar/logging");
27
+
28
+ var _readFile = require("../lib/envvar/read-file");
29
+
30
+ var _rollbar = require("../lib/rollbar");
31
+
32
+ var _tracker = require("../lib/tracker");
33
+
34
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
+
36
+ /**
37
+ * Internal dependencies
38
+ */
39
+ const baseUsage = 'vip config envvar set';
40
+ const NEW_RELIC_ENVVAR_KEY = 'NEW_RELIC_LICENSE_KEY'; // Command examples
41
+
42
+ const examples = [{
43
+ usage: `${baseUsage} MY_VARIABLE`,
44
+ description: 'Sets the environment variable "MY_VARIABLE" and prompts for its value'
45
+ }];
46
+
47
+ async function setEnvVarCommand(arg, opt) {
48
+ // Help the user by uppercasing input.
49
+ const name = arg[0].trim().toUpperCase();
50
+ const trackingParams = {
51
+ app_id: opt.app.id,
52
+ command: `${baseUsage} ${name}`,
53
+ env_id: opt.env.id,
54
+ from_file: !!opt.fromFile,
55
+ org_id: opt.app.organization.id,
56
+ skip_confirm: !!opt.skipConfirmation,
57
+ variable_name: name
58
+ };
59
+ (0, _logging.debug)(`Request: Set environment variable ${JSON.stringify(name)} for ${(0, _logging.getEnvContext)(opt.app, opt.env)}`);
60
+ await (0, _tracker.trackEvent)('envvar_set_command_execute', trackingParams);
61
+
62
+ if (!(0, _api.validateNameWithMessage)(name)) {
63
+ await (0, _tracker.trackEvent)('envvar_set_invalid_name', trackingParams);
64
+ process.exit(1);
65
+ }
66
+
67
+ if (NEW_RELIC_ENVVAR_KEY === name) {
68
+ await (0, _tracker.trackEvent)('envvar_set_newrelic_key', trackingParams);
69
+ console.log(_chalk.default.bold.red('Setting the New Relic key is not permitted.'), 'If you want to set your own New Relic key, please contact our support team through the usual channels.');
70
+ process.exit(1);
71
+ }
72
+
73
+ let value;
74
+
75
+ if (opt.fromFile) {
76
+ value = await (0, _readFile.readVariableFromFile)(opt.fromFile);
77
+ } else {
78
+ console.log(`For multiline input, use the ${_chalk.default.bold('--from-file')} option.`);
79
+ console.log();
80
+ value = await (0, _input.promptForValue)(`Enter the value for ${name}:`).catch(async () => {
81
+ await (0, _tracker.trackEvent)('envvar_set_user_cancelled_input', trackingParams);
82
+ (0, _input.cancel)();
83
+ });
84
+ }
85
+
86
+ if (!opt.skipConfirmation) {
87
+ // Print input if it was loaded from file.
88
+ if (opt.fromFile) {
89
+ console.log('===== Received value printed below =====');
90
+ console.log(value);
91
+ console.log('===== Received value printed above =====');
92
+ console.log();
93
+ }
94
+
95
+ if (!(await (0, _input.confirm)(`Please ${_chalk.default.bold('confirm')} the input value above (y/N)`))) {
96
+ await (0, _tracker.trackEvent)('envvar_set_user_cancelled_confirmation', trackingParams);
97
+ (0, _input.cancel)();
98
+ }
99
+ }
100
+
101
+ await (0, _api.setEnvVar)(opt.app.id, opt.env.id, name, value).catch(async err => {
102
+ _rollbar.rollbar.error(err);
103
+
104
+ await (0, _tracker.trackEvent)('envvar_set_mutation_error', { ...trackingParams,
105
+ error: err.message
106
+ });
107
+ throw err;
108
+ });
109
+ await (0, _tracker.trackEvent)('envvar_set_command_success', trackingParams);
110
+ console.log(_chalk.default.green(`Successfully set environment variable ${JSON.stringify(name)}`));
111
+
112
+ if (!opt.skipConfirmation) {
113
+ console.log(_chalk.default.bgYellow(_chalk.default.bold('Important:')), 'Updates to environment variables will not be available until the application’s next deploy.');
114
+ }
115
+ }
116
+
117
+ (0, _command.default)({
118
+ appContext: true,
119
+ appQuery: _api.appQuery,
120
+ envContext: true,
121
+ requiredArgs: 1,
122
+ usage: `${baseUsage} <VARIABLE_NAME>`
123
+ }).option('from-file', 'Read environment variable value from file (useful for multiline input)').option('skip-confirmation', 'Skip manual confirmation of input (USE WITH CAUTION)', false).examples(examples).argv(process.argv, setEnvVarCommand);
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ *
5
+ * @format
6
+ */
7
+
8
+ /**
9
+ * External dependencies
10
+ */
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ "use strict";
16
+
17
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
18
+
19
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
+
21
+ (0, _command.default)({
22
+ requiredArgs: 1
23
+ }).command('delete', 'Permanently delete an environment variable').command('get', 'Get the value of an environment variable').command('get-all', 'Get the values of all environment variable').command('list', 'List the names of all environment variables').command('set', 'Add or update an environment variable').argv(process.argv);