cloudron 5.11.4 → 5.11.5

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.
@@ -14,8 +14,8 @@ function collectArgs(value, collected) {
14
14
 
15
15
  // global options
16
16
  program.option('--server <server>', 'Cloudron domain')
17
- .option('--build-service-token <token>', 'Build service token')
18
- .option('--build-service, --set-build-service [buildservice url]', 'Set build service app URL. This build service is automatically used for future calls from this project');
17
+ .option('--token, --build-service-token <token>', 'Build service token')
18
+ .option('--url, --set-build-service [buildservice url]', 'Set build service URL. This build service is automatically used for future calls from this project');
19
19
 
20
20
  program.command('build', { isDefault: true })
21
21
  .description('Build an app. This is the default subcommand')
@@ -31,8 +31,7 @@ program.command('build', { isDefault: true })
31
31
 
32
32
  program.command('login')
33
33
  .description('Login to the build service')
34
- .option('-u, --username <username>', 'Username')
35
- .option('-p, --password <password>', 'Password (unsafe)')
34
+ .option('-t, --token <token>', 'Build service token')
36
35
  .action(buildActions.login);
37
36
 
38
37
  program.command('logs')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudron",
3
- "version": "5.11.4",
3
+ "version": "5.11.5",
4
4
  "license": "MIT",
5
5
  "description": "Cloudron Commandline Tool",
6
6
  "main": "main.js",
@@ -33,25 +33,50 @@ function requestError(response) {
33
33
  return `${response.statusCode} message: ${response.body?.message || null}`;
34
34
  }
35
35
 
36
+ // analyzes options and merges with any existing build service config
37
+ function getBuildServiceConfig(options) {
38
+ const buildService = config.getBuildServiceConfig();
39
+ if (!buildService.type) buildService.type = 'local'; // default
40
+
41
+ if (options.local) {
42
+ buildService.type = 'local';
43
+ } else if (options.setBuildService) { // stash for future use
44
+ buildService.token = null;
45
+ buildService.url = null;
46
+ buildService.type = 'remote';
47
+
48
+ let url;
49
+ if (typeof options.setBuildService === 'string') {
50
+ url = options.setBuildService;
51
+ } else {
52
+ url = readlineSync.question('Enter build service URL: ', { });
53
+ }
54
+
55
+ if (url.indexOf('://') === -1) url = `https://${url}`;
56
+ buildService.url = url;
57
+ }
58
+
59
+ if (options.buildServiceToken) buildService.token = options.buildServiceToken;
60
+
61
+ config.setBuildServiceConfig(buildService);
62
+
63
+ return buildService;
64
+ }
65
+
36
66
  async function login(options) {
37
67
  assert.strictEqual(typeof options, 'object');
38
68
 
39
- const buildServiceConfig = config.getBuildServiceConfig();
40
-
41
- if (!options.hideBanner) console.log('Build Service login' + ` (${buildServiceConfig.url}):`);
69
+ const buildServiceConfig = getBuildServiceConfig(options);
42
70
 
43
- const username = options.username || readlineSync.question('Username: ', {});
44
- const password = options.password || readlineSync.question('Password: ', { noEchoBack: true });
71
+ console.log('Build Service login' + ` (${buildServiceConfig.url}):`);
45
72
 
46
- // reset token
47
- buildServiceConfig.token = null;
48
- config.setBuildServiceConfig(buildServiceConfig);
73
+ const token = options.buildServiceToken || readlineSync.question('Token: ', {});
49
74
 
50
- const response = await superagent.post(`${buildServiceConfig.url}/api/v1/login`).send({ username: username, password: password }).ok(() => true);
51
- if (response.statusCode === 401 || response.statusCode === 403) return exit(`Authentication error: ${requestError(response)}}`);
52
- if (response.statusCode !== 200 && response.statusCode !== 201) return exit(`Unexpected response: ${requestError(response)}`);
75
+ const response = await superagent.get(`${buildServiceConfig.url}/api/v1/profile`).query({ accessToken: token }).ok(() => true);
76
+ if (response.statusCode === 401 || response.statusCode === 403) return exit(`Authentication error: ${requestError(response)}`);
77
+ if (response.statusCode !== 200) return exit(`Unexpected response: ${requestError(response)}`);
53
78
 
54
- buildServiceConfig.token = response.body.accessToken;
79
+ buildServiceConfig.token = token;
55
80
  config.setBuildServiceConfig(buildServiceConfig);
56
81
 
57
82
  console.log('Login successful.');
@@ -276,7 +301,9 @@ async function buildRemote(manifest, sourceDir, appConfig, options) {
276
301
  exit();
277
302
  }
278
303
 
279
- async function build(options) {
304
+ async function build(localOptions, cmd) {
305
+ const options = cmd.optsWithGlobals();
306
+
280
307
  // try to find the manifest of this project
281
308
  const manifestFilePath = helper.locateManifest();
282
309
  if (!manifestFilePath) return exit('No CloudronManifest.json found');
@@ -288,31 +315,7 @@ async function build(options) {
288
315
  const sourceDir = path.dirname(manifestFilePath);
289
316
 
290
317
  const appConfig = config.getAppConfig(sourceDir);
291
-
292
- const buildService = config.getBuildServiceConfig();
293
- if (!buildService.type) buildService.type = 'local'; // default
294
-
295
- if (options.local) {
296
- buildService.type = 'local';
297
- } else if (options.setBuildService) {
298
- buildService.token = null;
299
- buildService.url = null;
300
- buildService.type = 'remote';
301
-
302
- let url;
303
- if (typeof options.setBuildService === 'string') {
304
- url = options.setBuildService;
305
- } else {
306
- url = readlineSync.question('Enter build service URL: ', { });
307
- }
308
-
309
- if (url.indexOf('://') === -1) url = `https://${url}`;
310
- buildService.url = url;
311
- }
312
-
313
- if (options.buildServiceToken) buildService.token = options.buildServiceToken;
314
-
315
- config.setBuildServiceConfig(buildService);
318
+ const buildServiceConfig = getBuildServiceConfig(options);
316
319
 
317
320
  let repository = appConfig.repository;
318
321
  if (!repository || options.setRepository) {
@@ -328,23 +331,27 @@ async function build(options) {
328
331
  config.setAppConfig(sourceDir, appConfig);
329
332
  }
330
333
 
331
- if (buildService.type === 'local') {
334
+ if (buildServiceConfig.type === 'local') {
332
335
  await buildLocal(manifest, sourceDir, appConfig, options);
333
- } else if (buildService.type === 'remote' && buildService.url) {
336
+ } else if (buildServiceConfig.type === 'remote' && buildServiceConfig.url) {
334
337
  await buildRemote(manifest, sourceDir, appConfig, options);
335
338
  } else {
336
339
  exit('Unknown build service type or missing build service url. Rerun with --reset-build-service');
337
340
  }
338
341
  }
339
342
 
340
- async function logs(options) {
343
+ async function logs(localOptions, cmd) {
344
+ const options = cmd.optsWithGlobals();
345
+
341
346
  if (!options.id) return exit('buildId is required');
342
347
 
343
348
  const [logsError] = await safe(followBuildLog(options.id, !!options.raw));
344
349
  if (logsError) console.log(`Failed to get logs: ${logsError.message}`);
345
350
  }
346
351
 
347
- async function status(options) {
352
+ async function status(localOptions, cmd) {
353
+ const options = cmd.optsWithGlobals();
354
+
348
355
  if (!options.id) return exit('buildId is required');
349
356
 
350
357
  const [statusError, status] = await safe(getStatus(options.id));
@@ -352,12 +359,14 @@ async function status(options) {
352
359
  console.log(status);
353
360
  }
354
361
 
355
- async function push(options) {
362
+ async function push(localOptions, cmd) {
363
+ const options = cmd.optsWithGlobals();
364
+
356
365
  if (!options.id) return exit('buildId is required');
357
366
  if (!options.repository) return exit('repository is required');
358
367
  if (!options.tag) return exit('tag is required');
359
368
 
360
- const buildServiceConfig = config.getBuildServiceConfig();
369
+ const buildServiceConfig = getBuildServiceConfig(options);
361
370
 
362
371
  const response = await superagent.post(`${buildServiceConfig.url}/api/v1/builds/${options.id}/push`)
363
372
  .query({ accessToken: buildServiceConfig.token })