@automattic/vip 2.1.0 → 2.2.0
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/CONTRIBUTING.md +24 -0
- package/README.md +34 -0
- package/assets/{dev-environment.lando.template.yml.ejs → dev-env.lando.template.yml.ejs} +24 -21
- package/assets/dev-env.nginx.template.conf.ejs +13 -0
- package/dist/bin/vip-config-envvar-delete.js +93 -0
- package/dist/bin/vip-config-envvar-get-all.js +94 -0
- package/dist/bin/vip-config-envvar-get.js +79 -0
- package/dist/bin/vip-config-envvar-list.js +91 -0
- package/dist/bin/vip-config-envvar-set.js +112 -0
- package/dist/bin/vip-config-envvar.js +23 -0
- package/dist/bin/vip-config.js +20 -0
- package/dist/bin/vip-dev-env-create.js +3 -2
- package/dist/bin/vip-dev-env-destroy.js +1 -1
- package/dist/bin/vip-dev-env-import-sql.js +8 -3
- package/dist/bin/vip-import-media.js +2 -2
- package/dist/bin/vip.js +2 -2
- package/dist/lib/cli/apiConfig.js +3 -17
- package/dist/lib/cli/command.js +14 -1
- package/dist/lib/cli/format.js +1 -0
- package/dist/lib/dev-environment/dev-environment-cli.js +36 -20
- package/dist/lib/dev-environment/dev-environment-core.js +40 -5
- package/dist/lib/dev-environment/dev-environment-lando.js +88 -14
- package/dist/lib/envvar/api-delete.js +56 -0
- package/dist/lib/envvar/api-get-all.js +59 -0
- package/dist/lib/envvar/api-get.js +24 -0
- package/dist/lib/envvar/api-list.js +60 -0
- package/dist/lib/envvar/api-set.js +58 -0
- package/dist/lib/envvar/api.js +104 -0
- package/dist/lib/envvar/input.js +55 -0
- package/dist/lib/envvar/logging.js +33 -0
- package/dist/lib/envvar/read-file.js +43 -0
- package/dist/lib/media-import/status.js +8 -3
- package/dist/lib/site-import/status.js +4 -1
- package/jest.setupMocks.js +1 -0
- package/package.json +31 -24
package/CONTRIBUTING.md
CHANGED
|
@@ -34,6 +34,30 @@ VIP_PROXY="" API_HOST=http://localhost:4000 node ./dist/bin/vip -- wp option get
|
|
|
34
34
|
|
|
35
35
|
New libraries should generally support both CLI and web contexts, though some cases that won't make sense (e.g. formatting for CLI output). Ensuring the libraries are useful everywhere will allow us to offer consistent experiences regardless of the interface.
|
|
36
36
|
|
|
37
|
+
## Release & Deployment Process
|
|
38
|
+
|
|
39
|
+
Our release flow for VIP CLI follows this pattern:
|
|
40
|
+
|
|
41
|
+
**_feature branch -> develop branch -> master branch -> NPM release_**
|
|
42
|
+
|
|
43
|
+
- For feature branches, please follow A8C branch naming conventions (e.g.- `add/data-sync-command`, `fix/subsite-launch-command`, etc.)
|
|
44
|
+
- Include a Changelog for all npm version releases, including any minor or major versions
|
|
45
|
+
- This is a public repository. Please do not include any internal links in PRs, changelogs, testing instructions, etc.
|
|
46
|
+
- Merge changes from your feature branch to the `develop` branch
|
|
47
|
+
- Please do not merge any changes into the `master` branch yet. All features/changes that are not ready to be public should stay in the `develop` branch to avoid conflicts when releasing urgent fixes.
|
|
48
|
+
- Changes from the `develop` branch are merged to `master` and released on NPM following our release schedule
|
|
49
|
+
- Any team member that is part of our NPM organization can release new minor or major versions, but please have a Customer Experience (Pâtisserie) team member look over the changes first.
|
|
50
|
+
|
|
51
|
+
### Changelogs
|
|
52
|
+
Changelogs allow customers to keep up with all the changes happening across our VIP Platform. Changelogs for VIP CLI are posted to the V[VIP Cloud Changelog P2](https://wpvipchangelog.wordpress.com/), along with the repository’s `README.md`.
|
|
53
|
+
|
|
54
|
+
### Release Schedule
|
|
55
|
+
We deploy changes from our `develop` branch to the `master` branch on Tuesdays from 4AM to 5PM Pacific Time.
|
|
56
|
+
|
|
57
|
+
Changes that are not ready to be publicly released should stay in the `develop` branch to avoid conflicts with any urgent fixes we may need to roll out. Fixes for urgent or breaking bugs may be merged straight to the `master` branch and released publicly via npm at any time outside of our release schedule.
|
|
58
|
+
|
|
59
|
+
All other changes should follow the schedule so that we can monitor the newly released changes.
|
|
60
|
+
|
|
37
61
|
## Releasing / Publishing
|
|
38
62
|
|
|
39
63
|
### Pre-publish Checks
|
package/README.md
CHANGED
|
@@ -27,6 +27,40 @@ By default, we record information about the usage of this tool using an in-house
|
|
|
27
27
|
|
|
28
28
|
## Changelog
|
|
29
29
|
|
|
30
|
+
### 2.2.0 (27 October 2021)
|
|
31
|
+
|
|
32
|
+
New: Environment variables command
|
|
33
|
+
- #896 Open config envvar command for all customers
|
|
34
|
+
- #876 Update envvar list command to only show names
|
|
35
|
+
- #879 Add config envvar get and get-all commands
|
|
36
|
+
- #875 Temporarily gate access to new config command to VIP staff
|
|
37
|
+
- #858 Environment variable CLI commands (list, set, delete)
|
|
38
|
+
|
|
39
|
+
Fixes:
|
|
40
|
+
- #901 Don't mark import as failed until restore has completed
|
|
41
|
+
- #899 Proxy fix + healthchecks
|
|
42
|
+
- #894 support windows db import
|
|
43
|
+
- #889 Proxy config change
|
|
44
|
+
- #888 mount wordpress code
|
|
45
|
+
- #872 Auto flush cache after import and add vipgo user
|
|
46
|
+
- #869 Media redirect to production site.
|
|
47
|
+
- #885 Make search data persistent between restarts
|
|
48
|
+
- #844 Expose DB and expose extra services in info table
|
|
49
|
+
- #865 spawn WP-CLI as root to allow for FS operations
|
|
50
|
+
- #895 Fix rmdir deprecation warning
|
|
51
|
+
- #870 Add the VIP CLI release process and release schedule
|
|
52
|
+
|
|
53
|
+
Dependencies updates:
|
|
54
|
+
- #778 Update dependency ini to v2
|
|
55
|
+
- #786 Update dependency keytar to v7
|
|
56
|
+
- #884 Update dependency cli-columns to v4
|
|
57
|
+
- #887 Update dependency lando to v3.4.3
|
|
58
|
+
- #874 Update dependency lando to v3.4.0
|
|
59
|
+
- #750 Bump hosted-git-info from 2.8.8 to 2.8.9
|
|
60
|
+
- #877 Bump tmpl from 1.0.4 to 1.0.5
|
|
61
|
+
|
|
62
|
+
https://github.com/Automattic/vip/releases/tag/v2.2.0
|
|
63
|
+
|
|
30
64
|
### 2.1.0 (16 September 2021)
|
|
31
65
|
|
|
32
66
|
- #857 Remove select DB checks
|
|
@@ -12,7 +12,7 @@ services:
|
|
|
12
12
|
devtools:
|
|
13
13
|
type: compose
|
|
14
14
|
services:
|
|
15
|
-
image: ghcr.io/automattic/vip-container-images/dev-tools:0.
|
|
15
|
+
image: ghcr.io/automattic/vip-container-images/dev-tools:0.7
|
|
16
16
|
command: sleep infinity
|
|
17
17
|
volumes:
|
|
18
18
|
- devtools:/dev-tools
|
|
@@ -27,6 +27,7 @@ services:
|
|
|
27
27
|
image: ghcr.io/automattic/vip-container-images/nginx:1.21.3
|
|
28
28
|
command: nginx -g "daemon off;"
|
|
29
29
|
volumes:
|
|
30
|
+
- ./nginx/extra.conf:/etc/nginx/conf.extra/extra.conf
|
|
30
31
|
<% wpVolumes() %>
|
|
31
32
|
|
|
32
33
|
php:
|
|
@@ -46,15 +47,21 @@ services:
|
|
|
46
47
|
volume:
|
|
47
48
|
nocopy: true
|
|
48
49
|
<% wpVolumes() %>
|
|
49
|
-
|
|
50
|
-
run_as_root:
|
|
50
|
+
run:
|
|
51
51
|
- sh /dev-tools/setup.sh database root "http://<%= siteSlug %>.vipdev.lndo.site/" "<%= wpTitle %>" <% if ( multisite ) { %> <%= siteSlug %>.vipdev.lndo.site <% } %>
|
|
52
|
+
run_as_root:
|
|
53
|
+
- echo "Copying dev-env-plugin.php to mu-plugins"
|
|
54
|
+
- cp /dev-tools/dev-env-plugin.php /wp/wp-content/mu-plugins/
|
|
52
55
|
|
|
53
56
|
database:
|
|
54
57
|
type: compose
|
|
55
58
|
services:
|
|
56
59
|
image: mariadb:<%= mariadb %>
|
|
57
60
|
command: docker-entrypoint.sh mysqld
|
|
61
|
+
ports:
|
|
62
|
+
- ":3306"
|
|
63
|
+
healthcheck:
|
|
64
|
+
test: 'mysql -uroot --silent --execute "SHOW DATABASES;"'
|
|
58
65
|
environment:
|
|
59
66
|
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 'true'
|
|
60
67
|
volumes:
|
|
@@ -79,9 +86,8 @@ services:
|
|
|
79
86
|
<% } %>
|
|
80
87
|
|
|
81
88
|
vip-search:
|
|
82
|
-
type:
|
|
83
|
-
|
|
84
|
-
overrides:
|
|
89
|
+
type: compose
|
|
90
|
+
services:
|
|
85
91
|
image: elasticsearch:<%= elasticsearch %>
|
|
86
92
|
command: /usr/local/bin/docker-entrypoint.sh
|
|
87
93
|
environment:
|
|
@@ -90,6 +96,14 @@ services:
|
|
|
90
96
|
ELASTICSEARCH_NODE_NAME: 'lando'
|
|
91
97
|
ELASTICSEARCH_PORT_NUMBER: 9200
|
|
92
98
|
discovery.type: 'single-node'
|
|
99
|
+
ports:
|
|
100
|
+
- ":9200"
|
|
101
|
+
healthcheck:
|
|
102
|
+
test: "curl --noproxy '*' -XGET localhost:9200"
|
|
103
|
+
volumes:
|
|
104
|
+
- search_data:/usr/share/elasticsearch/data
|
|
105
|
+
volumes:
|
|
106
|
+
search_data:
|
|
93
107
|
|
|
94
108
|
<% if ( statsd ) { %>
|
|
95
109
|
statsd:
|
|
@@ -99,17 +113,13 @@ services:
|
|
|
99
113
|
command: node stats.js /config/statsd-config.js
|
|
100
114
|
<% } %>
|
|
101
115
|
|
|
102
|
-
<% if ( wordpress.mode == 'image' ) { %>
|
|
103
116
|
wordpress:
|
|
104
117
|
type: compose
|
|
105
118
|
services:
|
|
106
119
|
image: <%= wordpress.image %>:<%= wordpress.tag %>
|
|
107
120
|
command: sh -c "rsync -a /wp/ /shared/; sleep infinity"
|
|
108
121
|
volumes:
|
|
109
|
-
- wordpress:/shared
|
|
110
|
-
volumes:
|
|
111
|
-
wordpress: {}
|
|
112
|
-
<% } %>
|
|
122
|
+
- ./wordpress:/shared
|
|
113
123
|
|
|
114
124
|
<% if ( muPlugins.mode == 'image' ) { %>
|
|
115
125
|
mu-plugins:
|
|
@@ -151,8 +161,9 @@ tooling:
|
|
|
151
161
|
wp:
|
|
152
162
|
service: php
|
|
153
163
|
description: "Run WP-CLI command"
|
|
164
|
+
user: root
|
|
154
165
|
cmd:
|
|
155
|
-
- wp
|
|
166
|
+
- wp --allow-root
|
|
156
167
|
|
|
157
168
|
add-site:
|
|
158
169
|
service: php
|
|
@@ -170,15 +181,7 @@ tooling:
|
|
|
170
181
|
- ./config:/wp/config
|
|
171
182
|
- ./log:/wp/log
|
|
172
183
|
- ./uploads:/wp/wp-content/uploads
|
|
173
|
-
|
|
174
|
-
- type: volume
|
|
175
|
-
source: wordpress
|
|
176
|
-
target: /wp
|
|
177
|
-
volume:
|
|
178
|
-
nocopy: true
|
|
179
|
-
<% } else { %>
|
|
180
|
-
- <%= wordpress.dir %>:/wp
|
|
181
|
-
<% } %>
|
|
184
|
+
- ./wordpress:/wp
|
|
182
185
|
<% if ( muPlugins.mode == 'image' ) { %>
|
|
183
186
|
- type: volume
|
|
184
187
|
source: mu-plugins
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
|
|
87
|
+
(0, _command.default)({
|
|
88
|
+
appContext: true,
|
|
89
|
+
appQuery: _api.appQuery,
|
|
90
|
+
envContext: true,
|
|
91
|
+
requiredArgs: 1,
|
|
92
|
+
usage: `${baseUsage} <VARIABLE_NAME>`
|
|
93
|
+
}).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,112 @@
|
|
|
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'; // Command examples
|
|
40
|
+
|
|
41
|
+
const examples = [{
|
|
42
|
+
usage: `${baseUsage} MY_VARIABLE`,
|
|
43
|
+
description: 'Sets the environment variable "MY_VARIABLE" and prompts for its value'
|
|
44
|
+
}];
|
|
45
|
+
|
|
46
|
+
async function setEnvVarCommand(arg, opt) {
|
|
47
|
+
// Help the user by uppercasing input.
|
|
48
|
+
const name = arg[0].trim().toUpperCase();
|
|
49
|
+
const trackingParams = {
|
|
50
|
+
app_id: opt.app.id,
|
|
51
|
+
command: `${baseUsage} ${name}`,
|
|
52
|
+
env_id: opt.env.id,
|
|
53
|
+
from_file: !!opt.fromFile,
|
|
54
|
+
org_id: opt.app.organization.id,
|
|
55
|
+
skip_confirm: !!opt.skipConfirmation,
|
|
56
|
+
variable_name: name
|
|
57
|
+
};
|
|
58
|
+
(0, _logging.debug)(`Request: Set environment variable ${JSON.stringify(name)} for ${(0, _logging.getEnvContext)(opt.app, opt.env)}`);
|
|
59
|
+
await (0, _tracker.trackEvent)('envvar_set_command_execute', trackingParams);
|
|
60
|
+
|
|
61
|
+
if (!(0, _api.validateNameWithMessage)(name)) {
|
|
62
|
+
await (0, _tracker.trackEvent)('envvar_set_invalid_name', trackingParams);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let value;
|
|
67
|
+
|
|
68
|
+
if (opt.fromFile) {
|
|
69
|
+
value = await (0, _readFile.readVariableFromFile)(opt.fromFile);
|
|
70
|
+
} else {
|
|
71
|
+
console.log(`For multiline input, use the ${_chalk.default.bold('--from-file')} option.`);
|
|
72
|
+
console.log();
|
|
73
|
+
value = await (0, _input.promptForValue)(`Enter the value for ${name}:`).catch(async () => {
|
|
74
|
+
await (0, _tracker.trackEvent)('envvar_set_user_cancelled_input', trackingParams);
|
|
75
|
+
(0, _input.cancel)();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!opt.skipConfirmation) {
|
|
80
|
+
// Print input if it was loaded from file.
|
|
81
|
+
if (opt.fromFile) {
|
|
82
|
+
console.log('===== Received value printed below =====');
|
|
83
|
+
console.log(value);
|
|
84
|
+
console.log('===== Received value printed above =====');
|
|
85
|
+
console.log();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!(await (0, _input.confirm)(`Please ${_chalk.default.bold('confirm')} the input value above (y/N)`))) {
|
|
89
|
+
await (0, _tracker.trackEvent)('envvar_set_user_cancelled_confirmation', trackingParams);
|
|
90
|
+
(0, _input.cancel)();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
await (0, _api.setEnvVar)(opt.app.id, opt.env.id, name, value).catch(async err => {
|
|
95
|
+
_rollbar.rollbar.error(err);
|
|
96
|
+
|
|
97
|
+
await (0, _tracker.trackEvent)('envvar_set_mutation_error', { ...trackingParams,
|
|
98
|
+
error: err.message
|
|
99
|
+
});
|
|
100
|
+
throw err;
|
|
101
|
+
});
|
|
102
|
+
await (0, _tracker.trackEvent)('envvar_set_command_success', trackingParams);
|
|
103
|
+
console.log(_chalk.default.green(`Successfully set environment variable ${JSON.stringify(name)}`));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
(0, _command.default)({
|
|
107
|
+
appContext: true,
|
|
108
|
+
appQuery: _api.appQuery,
|
|
109
|
+
envContext: true,
|
|
110
|
+
requiredArgs: 1,
|
|
111
|
+
usage: `${baseUsage} <VARIABLE_NAME>`
|
|
112
|
+
}).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);
|