clever-tools 3.6.1 → 3.8.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/README.md +1 -7
- package/bin/clever.js +99 -47
- package/package.json +48 -50
- package/src/command-options.js +22 -3
- package/src/commands/accesslogs.js +114 -34
- package/src/commands/activity.js +70 -16
- package/src/commands/addon.js +153 -75
- package/src/commands/applications.js +83 -1
- package/src/commands/cancel-deploy.js +3 -3
- package/src/commands/config.js +6 -7
- package/src/commands/console.js +16 -4
- package/src/commands/curl.js +13 -16
- package/src/commands/delete.js +16 -6
- package/src/commands/deploy.js +9 -6
- package/src/commands/diag.js +68 -28
- package/src/commands/domain.js +13 -13
- package/src/commands/drain.js +42 -27
- package/src/commands/env.js +53 -24
- package/src/commands/logs.js +3 -3
- package/src/commands/notify-email.js +33 -18
- package/src/commands/open.js +3 -3
- package/src/commands/profile.js +29 -9
- package/src/commands/published-config.js +26 -15
- package/src/commands/restart.js +12 -5
- package/src/commands/scale.js +2 -3
- package/src/commands/service.js +42 -15
- package/src/commands/ssh.js +3 -3
- package/src/commands/status.js +72 -46
- package/src/commands/stop.js +3 -3
- package/src/commands/tcp-redirs.js +54 -18
- package/src/commands/webhooks.js +28 -13
- package/src/logger.js +9 -6
- package/src/models/addon.js +21 -12
- package/src/models/app_configuration.js +11 -3
- package/src/models/application.js +106 -7
- package/src/models/exit-strategy-option.js +24 -0
- package/src/models/json-array.js +28 -0
- package/src/models/log-v4.js +9 -29
- package/src/models/log.js +9 -2
- package/src/models/namespaces.js +20 -0
- package/src/models/organisation.js +0 -20
- package/src/models/utils.js +8 -1
- package/src/models/accesslogs.js +0 -54
- package/vendors/README_VENDORS.md +0 -18
- package/vendors/curlconverter-parse.js +0 -3709
package/src/models/log-v4.js
CHANGED
|
@@ -4,6 +4,8 @@ const { Deferred } = require('./utils.js');
|
|
|
4
4
|
const Logger = require('../logger.js');
|
|
5
5
|
const { waitForDeploymentEnd, waitForDeploymentStart } = require('./deployments.js');
|
|
6
6
|
const { ApplicationLogStream } = require('@clevercloud/client/cjs/streams/application-logs.js');
|
|
7
|
+
const { JsonArray } = require('./json-array.js');
|
|
8
|
+
const ExitStrategy = require('../models/exit-strategy-option.js');
|
|
7
9
|
|
|
8
10
|
// 2000 logs per 100ms maximum
|
|
9
11
|
const THROTTLE_ELEMENTS = 2000;
|
|
@@ -90,15 +92,20 @@ async function watchDeploymentAndDisplayLogs (options) {
|
|
|
90
92
|
commitId,
|
|
91
93
|
knownDeployments,
|
|
92
94
|
quiet,
|
|
93
|
-
follow,
|
|
94
95
|
redeployDate,
|
|
96
|
+
exitStrategy,
|
|
95
97
|
} = options;
|
|
96
98
|
|
|
99
|
+
ExitStrategy.plotQuietWarning(exitStrategy, quiet);
|
|
97
100
|
// If in quiet mode, we only log start/finished deployment messages
|
|
98
101
|
!quiet && Logger.println('Waiting for deployment to start…');
|
|
99
102
|
const deployment = await waitForDeploymentStart({ ownerId, appId, deploymentId, commitId, knownDeployments });
|
|
100
103
|
Logger.println(colors.bold.blue(`Deployment started (${deployment.uuid})`));
|
|
101
104
|
|
|
105
|
+
if (exitStrategy === 'deploy-start') {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
102
109
|
const deferred = new Deferred();
|
|
103
110
|
let logsStream;
|
|
104
111
|
|
|
@@ -120,7 +127,7 @@ async function watchDeploymentAndDisplayLogs (options) {
|
|
|
120
127
|
deferred.promise,
|
|
121
128
|
]);
|
|
122
129
|
|
|
123
|
-
if (!quiet &&
|
|
130
|
+
if (!quiet && exitStrategy !== 'never') {
|
|
124
131
|
logsStream.close(quiet ? 'quiet' : 'follow');
|
|
125
132
|
}
|
|
126
133
|
|
|
@@ -166,30 +173,3 @@ function isBuildSucessMessage (log) {
|
|
|
166
173
|
};
|
|
167
174
|
|
|
168
175
|
module.exports = { displayLogs, watchDeploymentAndDisplayLogs };
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Helper to print a real JSON array with starting `[` and ending `]`
|
|
172
|
-
*/
|
|
173
|
-
class JsonArray {
|
|
174
|
-
constructor () {
|
|
175
|
-
this._isFirst = true;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
open () {
|
|
179
|
-
process.stdout.write('[\n');
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
push (log) {
|
|
183
|
-
if (this._isFirst) {
|
|
184
|
-
this._isFirst = false;
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
process.stdout.write(',\n');
|
|
188
|
-
}
|
|
189
|
-
process.stdout.write(` ${JSON.stringify(log)}`);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
close () {
|
|
193
|
-
process.stdout.write('\n]');
|
|
194
|
-
}
|
|
195
|
-
}
|
package/src/models/log.js
CHANGED
|
@@ -9,6 +9,7 @@ const { getOldLogs } = require('@clevercloud/client/cjs/api/v2/log.js');
|
|
|
9
9
|
const { LogsStream } = require('@clevercloud/client/cjs/streams/logs.node.js');
|
|
10
10
|
const { sendToApi, getHostAndTokens } = require('./send-to-api.js');
|
|
11
11
|
const { waitForDeploymentEnd, waitForDeploymentStart } = require('./deployments.js');
|
|
12
|
+
const ExitStrategy = require('../models/exit-strategy-option.js');
|
|
12
13
|
|
|
13
14
|
function isCleverMessage (line) {
|
|
14
15
|
return line._source.syslog_program === '/home/bas/rubydeployer/deployer.rb';
|
|
@@ -100,12 +101,18 @@ async function displayLogs ({ appAddonId, until, since, filter, deploymentId })
|
|
|
100
101
|
return deferred.promise;
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
async function watchDeploymentAndDisplayLogs ({ ownerId, appId, deploymentId, commitId, knownDeployments, quiet,
|
|
104
|
+
async function watchDeploymentAndDisplayLogs ({ ownerId, appId, deploymentId, commitId, knownDeployments, quiet, exitStrategy }) {
|
|
104
105
|
|
|
106
|
+
ExitStrategy.plotQuietWarning(exitStrategy, quiet);
|
|
107
|
+
// If in quiet mode, we only log start/finished deployment messages
|
|
105
108
|
Logger.println('Waiting for deployment to start…');
|
|
106
109
|
const deployment = await waitForDeploymentStart({ ownerId, appId, deploymentId, commitId, knownDeployments });
|
|
107
110
|
Logger.println(colors.bold.blue(`Deployment started (${deployment.uuid})`));
|
|
108
111
|
|
|
112
|
+
if (exitStrategy === 'deploy-start') {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
109
116
|
const deferred = new Deferred();
|
|
110
117
|
let logsStream;
|
|
111
118
|
|
|
@@ -127,7 +134,7 @@ async function watchDeploymentAndDisplayLogs ({ ownerId, appId, deploymentId, co
|
|
|
127
134
|
deferred.promise,
|
|
128
135
|
]);
|
|
129
136
|
|
|
130
|
-
if (!quiet &&
|
|
137
|
+
if (!quiet && exitStrategy !== 'never') {
|
|
131
138
|
logsStream.close();
|
|
132
139
|
}
|
|
133
140
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const Application = require('./application.js');
|
|
2
|
+
const organisation = require('@clevercloud/client/cjs/api/v2/organisation.js');
|
|
3
|
+
const { sendToApi } = require('./send-to-api.js');
|
|
4
|
+
const { autocomplete } = require('cliparse');
|
|
5
|
+
|
|
6
|
+
async function getNamespaces (ownerId) {
|
|
7
|
+
return organisation.getNamespaces({ id: ownerId }).then(sendToApi);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async function completeNamespaces () {
|
|
11
|
+
// Sadly we do not have access to current params in complete as of now
|
|
12
|
+
const { ownerId } = await Application.resolveId(null, null);
|
|
13
|
+
|
|
14
|
+
return getNamespaces(ownerId).then(autocomplete.words);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
getNamespaces,
|
|
19
|
+
completeNamespaces,
|
|
20
|
+
};
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
|
-
const autocomplete = require('cliparse').autocomplete;
|
|
5
4
|
|
|
6
|
-
const AppConfig = require('./app_configuration.js');
|
|
7
|
-
|
|
8
|
-
const organisation = require('@clevercloud/client/cjs/api/v2/organisation.js');
|
|
9
5
|
const { getSummary } = require('@clevercloud/client/cjs/api/v2/user.js');
|
|
10
6
|
const { sendToApi } = require('../models/send-to-api.js');
|
|
11
7
|
|
|
@@ -37,22 +33,6 @@ async function getByName (name) {
|
|
|
37
33
|
return filteredOrgs[0];
|
|
38
34
|
}
|
|
39
35
|
|
|
40
|
-
async function getNamespaces (params) {
|
|
41
|
-
const { alias } = params.options;
|
|
42
|
-
const { ownerId } = await AppConfig.getAppDetails({ alias });
|
|
43
|
-
|
|
44
|
-
return organisation.getNamespaces({ id: ownerId }).then(sendToApi);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function completeNamespaces () {
|
|
48
|
-
// Sadly we do not have access to current params in complete as of now
|
|
49
|
-
const params = { options: {} };
|
|
50
|
-
|
|
51
|
-
return getNamespaces(params).then(autocomplete.words);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
36
|
module.exports = {
|
|
55
37
|
getId,
|
|
56
|
-
getNamespaces,
|
|
57
|
-
completeNamespaces,
|
|
58
38
|
};
|
package/src/models/utils.js
CHANGED
|
@@ -15,4 +15,11 @@ class Deferred {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
function truncateWithEllipsis (length, string) {
|
|
19
|
+
if (string.length > length - 1) {
|
|
20
|
+
return string.substring(0, length - 1) + '…';
|
|
21
|
+
}
|
|
22
|
+
return string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = { Deferred, truncateWithEllipsis };
|
package/src/models/accesslogs.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const clfDate = require('clf-date');
|
|
4
|
-
|
|
5
|
-
function getFormatter (format, isAddon) {
|
|
6
|
-
switch (format.toLowerCase()) {
|
|
7
|
-
// "simple" is the legacy default, "human" is the new one
|
|
8
|
-
case 'human':
|
|
9
|
-
case 'simple':
|
|
10
|
-
return isAddon ? formatSimpleAddon : formatSimple;
|
|
11
|
-
case 'extended':
|
|
12
|
-
return isAddon ? formatExtendedAddon : formatExtended;
|
|
13
|
-
case 'clf':
|
|
14
|
-
return isAddon ? formatCLFAddon : formatCLF;
|
|
15
|
-
case 'json':
|
|
16
|
-
return (l) => JSON.stringify(l);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function formatSource (l) {
|
|
21
|
-
if (l.s != null) {
|
|
22
|
-
const location = l.s.ct ? `${l.s.ct}, ${l.s.co}` : l.s.co;
|
|
23
|
-
return `${l.ipS} - ${location}`;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
return l.ipS;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function formatSimple (l) {
|
|
31
|
-
return `${new Date(l.t).toISOString()} ${l.ipS} ${l.vb} ${l.path}`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function formatExtended (l) {
|
|
35
|
-
return `${new Date(l.t).toISOString()} [ ${formatSource(l)} ] ${l.vb} ${l.h} ${l.path} ${l.sC}`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function formatCLF (l) {
|
|
39
|
-
return `${l.ipS} - - [${clfDate(new Date(l.t))}] "${l.vb} ${l.path} -" ${l.sC} ${l.bOut}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function formatSimpleAddon (l) {
|
|
43
|
-
return `${new Date(l.t).toISOString()} ${l.ipS}`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function formatExtendedAddon (l) {
|
|
47
|
-
return `${new Date(l.t).toISOString()} [ ${formatSource(l)} ] duration(ms): ${l.sDuration}`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function formatCLFAddon (l) {
|
|
51
|
-
return `${l.ipS} - - [${clfDate(new Date(l.t))}] "- - -" - ${l.bOut}`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
module.exports = { getFormatter };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# Why do we have this vendors directory?
|
|
2
|
-
|
|
3
|
-
We depend on the the [`curlconverter`](https://www.npmjs.com/package/curlconverter) package.
|
|
4
|
-
It's only available as ESM.
|
|
5
|
-
This module format is no problem for a recent version of Node.js but it does not work when we build our auto packaged binary version of the CLI with pkg.
|
|
6
|
-
|
|
7
|
-
The next steps for this project are:
|
|
8
|
-
|
|
9
|
-
* find a replacement for pkg to build an auto packaged binary
|
|
10
|
-
* move the whole project to ESM
|
|
11
|
-
* eventually bundle/compile the code to a single file before building the binary
|
|
12
|
-
|
|
13
|
-
Before doing this, we introduced a quick & simple solution, juste for curlconverter:
|
|
14
|
-
|
|
15
|
-
* add `rollup` to dev dependencies
|
|
16
|
-
* bundle the only file we need (`node_modules/curlconverter/dist/src/parse.js`) to a single CJS file with rollup
|
|
17
|
-
* version the bundle in the repo (`vendors/curlconverter-parse.js`)
|
|
18
|
-
* add a npm task to build the bundle again if needed
|