runcloud 0.1.103 → 0.1.104
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/dist/commands/token.js +102 -0
- package/dist/index.js +2 -0
- package/dist/run-cloud.js +2 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { acquirePromptIO, select, PromptAbortedError } from '../prompt.js';
|
|
2
|
+
import { fetchProviders } from '../runCloudAuth.js';
|
|
3
|
+
import { authApiUrlFor, commandApiUrls, emailLogin, loginChoices, methodFromFlags, openBrowser, verifyRunCloudCredential, } from './login.js';
|
|
4
|
+
export function tokenReport(isRunCloud, minted) {
|
|
5
|
+
const bin = isRunCloud ? 'runcloud' : 'newly';
|
|
6
|
+
const tokenVar = isRunCloud ? 'RUN_CLOUD_API_TOKEN' : 'NEWLY_API_TOKEN';
|
|
7
|
+
const urlVar = isRunCloud ? 'RUN_CLOUD_API_URL' : 'NEWLY_API_URL';
|
|
8
|
+
const lines = [
|
|
9
|
+
'',
|
|
10
|
+
minted.account ? ` Token minted for ${minted.account}.` : ' Token minted.',
|
|
11
|
+
' This is shown once and was NOT saved on this machine — your existing',
|
|
12
|
+
` \`${bin} login\` credential is untouched. Treat it like a password.`,
|
|
13
|
+
'',
|
|
14
|
+
` ${minted.token}`,
|
|
15
|
+
'',
|
|
16
|
+
' Use it in CI (environment variables):',
|
|
17
|
+
` export ${tokenVar}='${minted.token}'`,
|
|
18
|
+
` export ${urlVar}='${minted.apiUrl}'`,
|
|
19
|
+
'',
|
|
20
|
+
' Or log a machine in with it:',
|
|
21
|
+
` ${bin} login --token '${minted.token}' --api-url '${minted.apiUrl}'`,
|
|
22
|
+
'',
|
|
23
|
+
];
|
|
24
|
+
return lines.join('\n');
|
|
25
|
+
}
|
|
26
|
+
export function registerToken(program) {
|
|
27
|
+
const isRunCloud = program.name() === 'runcloud';
|
|
28
|
+
const defaultAppUrl = isRunCloud
|
|
29
|
+
? process.env.RUN_CLOUD_APP_URL ?? 'https://run.cloud'
|
|
30
|
+
: process.env.NEWLY_APP_URL ?? 'https://newly.app';
|
|
31
|
+
const token = program
|
|
32
|
+
.command('token')
|
|
33
|
+
.description('Mint and manage API tokens for CI and other machines');
|
|
34
|
+
token
|
|
35
|
+
.command('create')
|
|
36
|
+
.description('Sign in and mint a fresh API token — printed once, never saved. ' +
|
|
37
|
+
'Your stored login on this machine is untouched.')
|
|
38
|
+
.option('--app-url <url>', 'product web app URL (for the browser handoff)', defaultAppUrl)
|
|
39
|
+
.option('--api-url <url>', 'control plane URL to mint against (defaults per skin)')
|
|
40
|
+
.option('--email [address]', 'sign in with an emailed code, without a browser')
|
|
41
|
+
.option('--google', 'sign in with Google', false)
|
|
42
|
+
.option('--github', 'sign in with GitHub', false)
|
|
43
|
+
.option('--browser', 'skip the picker and use the browser handoff', false)
|
|
44
|
+
.action(async (opts) => {
|
|
45
|
+
try {
|
|
46
|
+
const authApiUrl = authApiUrlFor(isRunCloud, opts.apiUrl);
|
|
47
|
+
let socialProvider;
|
|
48
|
+
if (!opts.browser) {
|
|
49
|
+
let method = methodFromFlags(opts);
|
|
50
|
+
const terminal = method === 'email' || !method ? acquirePromptIO() : null;
|
|
51
|
+
try {
|
|
52
|
+
let providers = null;
|
|
53
|
+
if (!method && terminal) {
|
|
54
|
+
providers = await fetchProviders(authApiUrl);
|
|
55
|
+
const choices = loginChoices(providers);
|
|
56
|
+
if (choices.length === 0) {
|
|
57
|
+
throw new Error(`${authApiUrl} has no sign-in methods enabled.`);
|
|
58
|
+
}
|
|
59
|
+
method = await select(' How do you want to sign in?', choices, terminal.io);
|
|
60
|
+
}
|
|
61
|
+
if (method === 'email') {
|
|
62
|
+
const preset = typeof opts.email === 'string' ? opts.email : undefined;
|
|
63
|
+
providers ??= await fetchProviders(authApiUrl);
|
|
64
|
+
const { email, token: minted } = await emailLogin(authApiUrl, preset, terminal?.io);
|
|
65
|
+
await verifyRunCloudCredential(authApiUrl, minted);
|
|
66
|
+
const urls = commandApiUrls(providers.cliApiUrl ?? authApiUrl, authApiUrl);
|
|
67
|
+
console.log(tokenReport(isRunCloud, { token: minted, apiUrl: urls.apiUrl, account: email }));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
terminal?.close();
|
|
73
|
+
}
|
|
74
|
+
if (method === 'google' || method === 'github')
|
|
75
|
+
socialProvider = method;
|
|
76
|
+
}
|
|
77
|
+
const { runDeviceLogin } = await import('../deviceLogin.js');
|
|
78
|
+
const payload = await runDeviceLogin({
|
|
79
|
+
apiUrl: authApiUrl,
|
|
80
|
+
appUrl: opts.appUrl,
|
|
81
|
+
provider: socialProvider,
|
|
82
|
+
openBrowser,
|
|
83
|
+
});
|
|
84
|
+
await verifyRunCloudCredential(authApiUrl, payload.token);
|
|
85
|
+
const urls = commandApiUrls(payload.apiUrl, authApiUrl);
|
|
86
|
+
console.log(tokenReport(isRunCloud, {
|
|
87
|
+
token: payload.token,
|
|
88
|
+
apiUrl: urls.apiUrl,
|
|
89
|
+
...(payload.account ? { account: payload.account } : {}),
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
if (e instanceof PromptAbortedError) {
|
|
94
|
+
console.log('Cancelled.');
|
|
95
|
+
process.exitCode = 130;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
99
|
+
process.exitCode = 1;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ import { registerDesktop } from './commands/desktop.js';
|
|
|
20
20
|
import { registerEnvironment } from './commands/environment.js';
|
|
21
21
|
import { registerAppStore } from './commands/appStore.js';
|
|
22
22
|
import { registerUpdate } from './commands/update.js';
|
|
23
|
+
import { registerToken } from './commands/token.js';
|
|
23
24
|
import { CLI_VERSION } from './version.js';
|
|
24
25
|
const program = new Command('newly')
|
|
25
26
|
.description('Develop, provision, and deploy Newly backends')
|
|
@@ -44,4 +45,5 @@ registerDesktop(program);
|
|
|
44
45
|
registerEnvironment(program);
|
|
45
46
|
registerAppStore(program);
|
|
46
47
|
registerUpdate(program);
|
|
48
|
+
registerToken(program);
|
|
47
49
|
await program.parseAsync(process.argv);
|
package/dist/run-cloud.js
CHANGED
|
@@ -5,6 +5,7 @@ import { registerLogin } from './commands/login.js';
|
|
|
5
5
|
import { registerRunCloud } from './commands/run-cloud.js';
|
|
6
6
|
import { registerSandbox } from './commands/sandbox.js';
|
|
7
7
|
import { registerSecrets } from './commands/secrets.js';
|
|
8
|
+
import { registerToken } from './commands/token.js';
|
|
8
9
|
import { CLI_VERSION } from './version.js';
|
|
9
10
|
const program = new Command('runcloud')
|
|
10
11
|
.description('Create and control remote mobile simulators and microVM sandboxes')
|
|
@@ -13,5 +14,6 @@ registerLogin(program);
|
|
|
13
14
|
registerRunCloud(program);
|
|
14
15
|
registerSandbox(program);
|
|
15
16
|
registerSecrets(program);
|
|
17
|
+
registerToken(program);
|
|
16
18
|
registerImage(program);
|
|
17
19
|
await program.parseAsync(process.argv);
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = '0.1.
|
|
1
|
+
export const CLI_VERSION = '0.1.104';
|