cloudron 5.14.7 → 5.14.9
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/package.json +1 -1
- package/src/actions.js +15 -8
- package/src/appstore-actions.js +19 -3
- package/src/superagent.js +2 -0
package/package.json
CHANGED
package/src/actions.js
CHANGED
|
@@ -89,7 +89,7 @@ function createRequest(method, apiPath, options) {
|
|
|
89
89
|
function requestError(response) {
|
|
90
90
|
if (response.status === 401) return 'Invalid token. Use cloudron login again.';
|
|
91
91
|
|
|
92
|
-
return `${response.status} message: ${response.body.message || JSON.stringify(response.body)}`; // body is sometimes just a string like in 401
|
|
92
|
+
return `${response.status} message: ${response.body.message || JSON.stringify(String(response.body))}`; // body is sometimes just a string like in 401
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
async function selectDomain(location, options) {
|
|
@@ -132,7 +132,8 @@ async function stopActiveTask(app, options) {
|
|
|
132
132
|
|
|
133
133
|
console.log(`Stopping app's current active task ${app.taskId}`);
|
|
134
134
|
|
|
135
|
-
const
|
|
135
|
+
const request = createRequest('POST', `/api/v1/tasks/${app.taskId}/stop`, options);
|
|
136
|
+
const response = await request.send({});
|
|
136
137
|
if (response.status !== 204) throw `Failed to stop active task: ${requestError(response)}`;
|
|
137
138
|
}
|
|
138
139
|
|
|
@@ -295,7 +296,8 @@ async function stopApp(app, options) {
|
|
|
295
296
|
assert.strictEqual(typeof app, 'object');
|
|
296
297
|
assert.strictEqual(typeof options, 'object');
|
|
297
298
|
|
|
298
|
-
const
|
|
299
|
+
const request = createRequest('POST', `/api/v1/apps/${app.id}/stop`, options);
|
|
300
|
+
const response = await request.send({});
|
|
299
301
|
if (response.status !== 202) throw `Failed to stop app: ${requestError(response)}`;
|
|
300
302
|
|
|
301
303
|
await waitForTask(response.body.taskId, options);
|
|
@@ -305,7 +307,8 @@ async function startApp(app, options) {
|
|
|
305
307
|
assert.strictEqual(typeof app, 'object');
|
|
306
308
|
assert.strictEqual(typeof options, 'object');
|
|
307
309
|
|
|
308
|
-
const
|
|
310
|
+
const request = createRequest('POST', `/api/v1/apps/${app.id}/start`, options);
|
|
311
|
+
const response = await request.send({});
|
|
309
312
|
if (response.status !== 202) throw `Failed to start app: ${requestError(response)}`;
|
|
310
313
|
|
|
311
314
|
await waitForTask(response.body.taskId, options);
|
|
@@ -315,7 +318,8 @@ async function restartApp(app, options) {
|
|
|
315
318
|
assert.strictEqual(typeof app, 'object');
|
|
316
319
|
assert.strictEqual(typeof options, 'object');
|
|
317
320
|
|
|
318
|
-
const
|
|
321
|
+
const request = createRequest('POST', `/api/v1/apps/${app.id}/restart`, options);
|
|
322
|
+
const response = await request.send({});
|
|
319
323
|
if (response.status !== 202) throw `Failed to restart app: ${requestError(response)}`;
|
|
320
324
|
|
|
321
325
|
await waitForTask(response.body.taskId, options);
|
|
@@ -894,7 +898,8 @@ async function uninstall(localOptions, cmd) {
|
|
|
894
898
|
|
|
895
899
|
await stopActiveTask(app, options);
|
|
896
900
|
|
|
897
|
-
const
|
|
901
|
+
const request = createRequest('POST', `/api/v1/apps/${app.id}/uninstall`, options);
|
|
902
|
+
const response = await request.send({});
|
|
898
903
|
if (response.status !== 202) return exit(`Failed to uninstall app: ${requestError(response)}`);
|
|
899
904
|
|
|
900
905
|
process.stdout.write('\n => ' + 'Waiting for app to be uninstalled ');
|
|
@@ -1061,7 +1066,8 @@ async function backupCreate(localOptions, cmd) {
|
|
|
1061
1066
|
const app = await getApp(options);
|
|
1062
1067
|
if (!app) return exit(NO_APP_FOUND_ERROR_STRING);
|
|
1063
1068
|
|
|
1064
|
-
const
|
|
1069
|
+
const request = createRequest('POST', `/api/v1/apps/${app.id}/backup`, options);
|
|
1070
|
+
const response = await request.send({});
|
|
1065
1071
|
if (response.status !== 202) return exit(`Failed to start backup: ${requestError(response)}`);
|
|
1066
1072
|
|
|
1067
1073
|
// FIXME: this should be waitForHealthCheck but the box code incorrectly modifies the installationState
|
|
@@ -1193,7 +1199,8 @@ async function importApp(localOptions, cmd) {
|
|
|
1193
1199
|
if (backupKey) data.backupConfig.key = backupKey;
|
|
1194
1200
|
}
|
|
1195
1201
|
|
|
1196
|
-
const
|
|
1202
|
+
const request = createRequest('POST', `/api/v1/apps/${app.id}/import`, options);
|
|
1203
|
+
const response = await request.send({});
|
|
1197
1204
|
if (response.status !== 202) return exit(`Failed to import app: ${requestError(response)}`);
|
|
1198
1205
|
|
|
1199
1206
|
await waitForFinishInstallation(app.id, response.body.taskId, options);
|
package/src/appstore-actions.js
CHANGED
|
@@ -295,6 +295,23 @@ async function verifyManifest(localOptions, cmd) {
|
|
|
295
295
|
if (error) return exit(error);
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
+
async function checkDockerHub(dockerImage) {
|
|
299
|
+
// const [tagError, tagResponse] = await safe(superagent.get(`https://hub.docker.com/v2/repositories/${repo}/tags/${tag}`).ok(() => true));
|
|
300
|
+
// if (tagError || tagResponse.status !== 200) return exit(`Failed to find docker image in dockerhub. check https://hub.docker.com/r/${repo}/tags : ${tagError || requestError(tagResponse)}`);
|
|
301
|
+
|
|
302
|
+
const [repo, tag] = dockerImage.split(':');
|
|
303
|
+
|
|
304
|
+
const [error, response] = await safe(superagent.get(`https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull`).ok(() => true));
|
|
305
|
+
if (error || response.status !== 200) throw new Error(`Failed to get dockerhub token to validate image: ${error || requestError(response)}`);
|
|
306
|
+
const token = response.body.token;
|
|
307
|
+
|
|
308
|
+
const [error2, response2] = await safe(superagent.head(`https://registry-1.docker.io/v2/${repo}/manifests/${tag}`)
|
|
309
|
+
.set('Accept', 'application/vnd.docker.distribution.manifest.v2+json')
|
|
310
|
+
.set('Authorization', `Bearer ${token}`)
|
|
311
|
+
.ok(() => true));
|
|
312
|
+
if (error2 || response2.status !== 200) throw new Error(`Image not found on docker hub: ${error2 || requestError(response2)}`);
|
|
313
|
+
}
|
|
314
|
+
|
|
298
315
|
async function upload(localOptions, cmd) {
|
|
299
316
|
const options = cmd.optsWithGlobals();
|
|
300
317
|
// try to find the manifest of this project
|
|
@@ -332,9 +349,8 @@ async function upload(localOptions, cmd) {
|
|
|
332
349
|
const error = manifestFormat.checkAppstoreRequirements(manifest);
|
|
333
350
|
if (error) return exit(error);
|
|
334
351
|
|
|
335
|
-
const [
|
|
336
|
-
|
|
337
|
-
if (tagError || tagResponse.status !== 200) return exit(`Failed to find docker image in dockerhub. check https://hub.docker.com/r/${repo}/tags : ${tagError || requestError(tagResponse)}`);
|
|
352
|
+
const [imageError] = await safe(checkDockerHub(manifest.dockerImage));
|
|
353
|
+
if (imageError) return exit(error);
|
|
338
354
|
|
|
339
355
|
// ensure the app is known on the appstore side
|
|
340
356
|
const baseDir = path.dirname(manifestFilePath);
|
package/src/superagent.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
exports = module.exports = {
|
|
4
|
+
head,
|
|
4
5
|
get,
|
|
5
6
|
put,
|
|
6
7
|
post,
|
|
@@ -214,6 +215,7 @@ class Request {
|
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
|
|
218
|
+
function head(url) { return new Request('HEAD', url); }
|
|
217
219
|
function get(url) { return new Request('GET', url); }
|
|
218
220
|
function put(url) { return new Request('PUT', url); }
|
|
219
221
|
function post(url) { return new Request('POST', url); }
|