@deepdynamic/cli 0.1.0 → 0.1.1
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/agents/content.js +1 -1
- package/dist/agents/install.js +22 -12
- package/dist/agents/refresh.js +20 -0
- package/dist/agents/setup.js +7 -7
- package/dist/cli.js +8 -8
- package/dist/commands/account.js +19 -19
- package/dist/commands/activity.js +13 -13
- package/dist/commands/blocked.js +16 -16
- package/dist/commands/deploy/index.js +16 -16
- package/dist/commands/deploy/ship.js +8 -8
- package/dist/commands/deployments.js +8 -7
- package/dist/commands/dns.js +228 -242
- package/dist/commands/domains.js +188 -260
- package/dist/commands/emails.js +17 -17
- package/dist/commands/env.js +38 -38
- package/dist/commands/help.js +18 -19
- package/dist/commands/keys.js +83 -89
- package/dist/commands/login/flow.js +11 -11
- package/dist/commands/login/index.js +3 -3
- package/dist/commands/logout.js +11 -11
- package/dist/commands/mail.js +62 -62
- package/dist/commands/notifications.js +30 -29
- package/dist/commands/plan.js +109 -125
- package/dist/commands/projects.js +159 -157
- package/dist/commands/reference.js +109 -102
- package/dist/commands/search.js +29 -18
- package/dist/commands/server.js +99 -112
- package/dist/commands/sessions.js +38 -44
- package/dist/commands/sites.js +16 -16
- package/dist/commands/sms.js +14 -14
- package/dist/commands/status.js +9 -9
- package/dist/commands/support.js +19 -19
- package/dist/commands/update.js +18 -16
- package/dist/commands/usage.js +12 -12
- package/dist/commands/verify.js +16 -16
- package/dist/guide.js +9 -48
- package/dist/http/request.js +3 -3
- package/dist/pretty.js +4 -4
- package/dist/refresh-skills.js +5 -0
- package/dist/registry.js +72 -144
- package/dist/runtime/card-request.js +6 -6
- package/dist/runtime/confirm.js +1 -1
- package/dist/runtime/development.js +1 -1
- package/dist/runtime/dry-run.js +2 -2
- package/dist/runtime/env-file.js +6 -9
- package/dist/runtime/flags.js +11 -13
- package/dist/runtime/login-screen.js +5 -5
- package/dist/runtime/page.js +4 -4
- package/dist/runtime/server-options.js +4 -8
- package/dist/runtime/spinner.js +3 -1
- package/dist/runtime/support.js +2 -3
- package/dist/runtime/text-file.js +5 -5
- package/dist/runtime/timeout.js +2 -2
- package/dist/runtime/update-check.js +48 -14
- package/dist/runtime/update-install.js +34 -4
- package/dist/runtime/usage-error.js +2 -2
- package/dist/setup-agents.js +9 -2
- package/package.json +1 -1
package/dist/commands/keys.js
CHANGED
|
@@ -6,165 +6,159 @@ import { confirmationRequired } from "../runtime/confirm.js";
|
|
|
6
6
|
import { pageRows, pagination, parsePage } from "../runtime/page.js";
|
|
7
7
|
import { plannedChange, plannedRequest, splitDryRun } from "../runtime/dry-run.js";
|
|
8
8
|
import { parseFlags, unknownArgument } from "../runtime/flags.js";
|
|
9
|
-
import {
|
|
9
|
+
import { rehearsed } from "./dns.js";
|
|
10
10
|
export const KEYS_PATH = '/api/v1/keys';
|
|
11
11
|
const KINDS = {
|
|
12
|
-
dns: { name: 'DNS Control API key',
|
|
13
|
-
s3: { name: 'S3 Control API key',
|
|
14
|
-
pay: { name: 'Pay Control API key',
|
|
12
|
+
dns: { name: 'DNS Control API key', prefix: 'dd_dns_' },
|
|
13
|
+
s3: { name: 'S3 Control API key', prefix: 'dd_s3_' },
|
|
14
|
+
pay: { name: 'Pay Control API key', prefix: 'dd_pay_' }
|
|
15
15
|
};
|
|
16
16
|
const EXPIRIES = {
|
|
17
|
-
'10m': { minutes: 10, label: '10
|
|
18
|
-
'1h': { minutes: 60, label: '1
|
|
19
|
-
'6h': { minutes: 360, label: '6
|
|
20
|
-
'1d': { minutes: 1440, label: '1
|
|
17
|
+
'10m': { minutes: 10, label: '10 minutes' },
|
|
18
|
+
'1h': { minutes: 60, label: '1 hour' },
|
|
19
|
+
'6h': { minutes: 360, label: '6 hours' },
|
|
20
|
+
'1d': { minutes: 1440, label: '1 day' }
|
|
21
21
|
};
|
|
22
22
|
const DEFAULT_EXPIRY = '10m';
|
|
23
|
-
const SCOPES = { 'dns:read': 'DNS
|
|
23
|
+
const SCOPES = { 'dns:read': 'DNS read', 'dns:write': 'DNS write', 's3:read': 'Storage read', 's3:write': 'Storage write', 'pay:write': 'Consolidated billing' };
|
|
24
24
|
const CUSTOM_PREFIX = 'dd_key_';
|
|
25
|
-
const KIND_LABELS = { dns: 'DNS Control', s3: 'S3 Control', pay: 'Pay Control', custom: '
|
|
25
|
+
const KIND_LABELS = { dns: 'DNS Control', s3: 'S3 Control', pay: 'Pay Control', custom: 'Custom' };
|
|
26
26
|
const PAY_SCOPE = /^pay(:|$)/i;
|
|
27
27
|
const KEY_VALUE = /^dd_/i;
|
|
28
28
|
const KEY_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
29
29
|
const CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
|
|
30
30
|
const NAME_MAX = 60;
|
|
31
|
-
const ONCE = '
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
display: '내 키 목록에 없는 키 ID 입니다.'
|
|
36
|
-
};
|
|
37
|
-
const KEY_EXISTS = {
|
|
38
|
-
code: 'key_exists',
|
|
39
|
-
message: 'That key is already issued. Revoke it with deepdynamic keys revoke <key-id> --yes before issuing it again.',
|
|
40
|
-
display: '이미 발급된 키입니다. deepdynamic keys revoke <키 ID> --yes 로 취소한 뒤 다시 발급하세요.'
|
|
41
|
-
};
|
|
31
|
+
const ONCE = 'The key value is shown only now. Store it somewhere safe. deepdynamic keys shows only its prefix.';
|
|
32
|
+
const failure = (code, message) => ({ code, message, display: message });
|
|
33
|
+
const KEY_NOT_FOUND = failure('key_not_found', 'No key with that ID is among your keys. Check them with deepdynamic keys.');
|
|
34
|
+
const KEY_EXISTS = failure('key_exists', 'That key is already issued. Revoke it with deepdynamic keys revoke <key-id> --yes before issuing it again.');
|
|
42
35
|
const ISSUE_STEPS = [
|
|
43
|
-
{ stage: 'validate_kind', message: '
|
|
44
|
-
{ stage: 'resolve_prefix', message: '
|
|
45
|
-
{ stage: 'prepare_request', message: '
|
|
36
|
+
{ stage: 'validate_kind', message: 'Checking the key kind.' },
|
|
37
|
+
{ stage: 'resolve_prefix', message: 'Resolving the key prefix.' },
|
|
38
|
+
{ stage: 'prepare_request', message: 'Preparing the issue request.' }
|
|
46
39
|
];
|
|
47
40
|
const PAY_STEPS = [
|
|
48
41
|
...ISSUE_STEPS.slice(0, 2),
|
|
49
|
-
{ stage: 'compute_expiry', message: '
|
|
50
|
-
{ stage: 'check_consent', message: '
|
|
42
|
+
{ stage: 'compute_expiry', message: 'Calculating the expiry.' },
|
|
43
|
+
{ stage: 'check_consent', message: 'Checking consent to consolidated billing.' },
|
|
51
44
|
...ISSUE_STEPS.slice(2)
|
|
52
45
|
];
|
|
53
46
|
const CREATE_STEPS = [
|
|
54
|
-
{ stage: 'validate_name', message: '
|
|
55
|
-
{ stage: 'normalize_scopes', message: '
|
|
56
|
-
{ stage: 'prepare_request', message: '
|
|
47
|
+
{ stage: 'validate_name', message: 'Checking the key name.' },
|
|
48
|
+
{ stage: 'normalize_scopes', message: 'Normalizing the scopes.' },
|
|
49
|
+
{ stage: 'prepare_request', message: 'Preparing the create request.' }
|
|
57
50
|
];
|
|
58
51
|
const REVOKE_STEPS = [
|
|
59
|
-
{ stage: 'validate_id', message: '
|
|
60
|
-
{ stage: 'summarize_impact', message: '
|
|
61
|
-
{ stage: 'prepare_request', message: '
|
|
52
|
+
{ stage: 'validate_id', message: 'Checking the key ID format.' },
|
|
53
|
+
{ stage: 'summarize_impact', message: 'Summarizing the access that revoking blocks.' },
|
|
54
|
+
{ stage: 'prepare_request', message: 'Preparing the revoke request.' }
|
|
62
55
|
];
|
|
63
56
|
const valuesOf = (entries, flag) => entries.filter(([name]) => name === flag).map(([, value]) => value);
|
|
64
57
|
const keyUrl = (siteUrl, suffix = '') => new URL(`${KEYS_PATH}${suffix}`, siteUrl).href;
|
|
65
58
|
const keyOf = (body) => body.key;
|
|
66
59
|
const scopeNames = (scopes) => scopes.map((scope) => SCOPES[scope] ?? scope).join(', ');
|
|
67
60
|
const when = (iso) => iso.replace('T', ' ').replace(/\.\d{3}Z$/, ' UTC');
|
|
68
|
-
|
|
61
|
+
const count = (amount, noun) => `${amount} ${noun}${amount === 1 ? '' : 's'}`;
|
|
62
|
+
function parseIssue(args) {
|
|
69
63
|
const consented = args.includes('--yes');
|
|
70
64
|
const [kind, ...rest] = args.filter((arg) => arg !== '--yes');
|
|
71
65
|
if (kind === undefined || kind.startsWith('-'))
|
|
72
|
-
return
|
|
66
|
+
return { error: 'Specify the key kind: dns, s3 or pay.' };
|
|
73
67
|
if (!Object.hasOwn(KINDS, kind))
|
|
74
|
-
return
|
|
75
|
-
const parsed = parseFlags(rest, ['--expires']
|
|
68
|
+
return { error: `Unknown key kind: ${kind}. Use dns, s3 or pay.` };
|
|
69
|
+
const parsed = parseFlags(rest, ['--expires']);
|
|
76
70
|
if ('error' in parsed)
|
|
77
71
|
return parsed;
|
|
78
72
|
const values = valuesOf(parsed.entries, '--expires');
|
|
79
73
|
if (values.length > 1)
|
|
80
|
-
return
|
|
74
|
+
return { error: '--expires can be given only once.' };
|
|
81
75
|
if (kind !== 'pay' && (values.length || consented)) {
|
|
82
76
|
const flag = values.length ? '--expires' : '--yes';
|
|
83
|
-
return
|
|
77
|
+
return { error: `${flag} is only for pay keys.` };
|
|
84
78
|
}
|
|
85
79
|
const [expires = DEFAULT_EXPIRY] = values;
|
|
86
80
|
if (!Object.hasOwn(EXPIRIES, expires))
|
|
87
|
-
return
|
|
81
|
+
return { error: `--expires must be 10m, 1h, 6h or 1d: ${expires}` };
|
|
88
82
|
return { kind: kind, expiry: kind === 'pay' ? EXPIRIES[expires] : null, consented };
|
|
89
83
|
}
|
|
90
|
-
function parseCreate(args
|
|
91
|
-
const parsed = parseFlags(args, ['--label', '--scope']
|
|
84
|
+
function parseCreate(args) {
|
|
85
|
+
const parsed = parseFlags(args, ['--label', '--scope']);
|
|
92
86
|
if ('error' in parsed)
|
|
93
87
|
return parsed;
|
|
94
88
|
const names = valuesOf(parsed.entries, '--label');
|
|
95
89
|
const given = valuesOf(parsed.entries, '--scope');
|
|
96
90
|
if (names.length === 0)
|
|
97
|
-
return
|
|
91
|
+
return { error: '--label is required.' };
|
|
98
92
|
if (names.length > 1)
|
|
99
|
-
return
|
|
93
|
+
return { error: '--label can be given only once.' };
|
|
100
94
|
const name = names[0].trim();
|
|
101
95
|
if (CONTROL.test(name))
|
|
102
|
-
return
|
|
96
|
+
return { error: 'The key name cannot contain control characters such as line breaks.' };
|
|
103
97
|
if (!name || name.length > NAME_MAX)
|
|
104
|
-
return
|
|
98
|
+
return { error: `--label must be 1-${NAME_MAX} characters.` };
|
|
105
99
|
if (given.length === 0)
|
|
106
|
-
return
|
|
100
|
+
return { error: 'At least one --scope is required.' };
|
|
107
101
|
const pay = given.find((scope) => PAY_SCOPE.test(scope));
|
|
108
102
|
if (pay)
|
|
109
|
-
return
|
|
103
|
+
return { error: `Payment scopes such as ${pay} are issued only with a temporary Pay Control key. Use deepdynamic keys issue pay.` };
|
|
110
104
|
const unknown = given.find((scope) => !Object.hasOwn(SCOPES, scope));
|
|
111
105
|
if (unknown)
|
|
112
|
-
return
|
|
106
|
+
return { error: `Unknown scope: ${unknown}. Use dns:read, dns:write, s3:read or s3:write.` };
|
|
113
107
|
return { name, scopes: Object.keys(SCOPES).filter((scope) => scope !== 'pay:write' && given.includes(scope)) };
|
|
114
108
|
}
|
|
115
|
-
function parseRevoke(args
|
|
109
|
+
function parseRevoke(args) {
|
|
116
110
|
const option = args.find((arg) => arg.startsWith('-'));
|
|
117
111
|
if (option)
|
|
118
|
-
return { error: unknownArgument(option
|
|
112
|
+
return { error: unknownArgument(option) };
|
|
119
113
|
if (args.length !== 1)
|
|
120
|
-
return
|
|
114
|
+
return { error: 'Specify exactly one key ID.' };
|
|
121
115
|
if (KEY_VALUE.test(args[0]))
|
|
122
|
-
return
|
|
116
|
+
return { error: 'Pass the key ID listed by deepdynamic keys, not the key value.' };
|
|
123
117
|
const id = args[0].toLowerCase();
|
|
124
118
|
if (!KEY_ID.test(id))
|
|
125
|
-
return
|
|
119
|
+
return { error: 'Key IDs are UUIDs as listed by deepdynamic keys.' };
|
|
126
120
|
return id;
|
|
127
121
|
}
|
|
128
122
|
function keyRows(key) {
|
|
129
123
|
return [
|
|
130
|
-
['
|
|
131
|
-
['
|
|
132
|
-
...(key.token ? [['
|
|
133
|
-
['
|
|
134
|
-
['
|
|
135
|
-
['
|
|
124
|
+
['Key', `${KIND_LABELS[key.kind] ?? key.kind} · ${key.name}`],
|
|
125
|
+
['Key ID', key.id],
|
|
126
|
+
...(key.token ? [['Key value', key.token], ['Warning', ONCE]] : [['Prefix', `${key.prefix}…`]]),
|
|
127
|
+
['Scopes', scopeNames(key.scopes)],
|
|
128
|
+
['Issued', when(key.createdAt)],
|
|
129
|
+
['Expires', when(key.expiresAt)]
|
|
136
130
|
];
|
|
137
131
|
}
|
|
138
132
|
function issued(command, pretty, depth, message, body, siteUrl) {
|
|
139
133
|
const key = keyOf(body);
|
|
140
134
|
return pretty
|
|
141
|
-
? prettyResult(0, depth, command, message, [['
|
|
135
|
+
? prettyResult(0, depth, command, message, [['Server', siteUrl], ...keyRows(key)])
|
|
142
136
|
: agentResult(0, { command, siteUrl, applied: true, key });
|
|
143
137
|
}
|
|
144
138
|
export async function runKeysList(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
145
139
|
const command = 'keys';
|
|
146
140
|
return rehearsed(command, args, pretty, depth, deps, (rest) => {
|
|
147
|
-
const page = parsePage(rest
|
|
141
|
+
const page = parsePage(rest);
|
|
148
142
|
if (typeof page !== 'number')
|
|
149
143
|
return page;
|
|
150
144
|
const listUrl = (siteUrl) => `${keyUrl(siteUrl)}?page=${page}`;
|
|
151
145
|
return {
|
|
152
|
-
steps: [{ stage: 'prepare_request', message: '
|
|
146
|
+
steps: [{ stage: 'prepare_request', message: 'Preparing the key list request.' }],
|
|
153
147
|
result: (siteUrl) => plannedRequest(command, pretty, depth, siteUrl, listUrl(siteUrl)),
|
|
154
148
|
send: {
|
|
155
149
|
method: 'GET',
|
|
156
150
|
url: listUrl,
|
|
157
|
-
spinner: '
|
|
158
|
-
failed: '
|
|
151
|
+
spinner: 'Loading your API keys.',
|
|
152
|
+
failed: 'Could not load your API keys.',
|
|
159
153
|
notFound: httpFailure(404),
|
|
160
154
|
done: (body, siteUrl) => {
|
|
161
155
|
const { keys, ...paged } = body;
|
|
162
156
|
const paging = pagination(paged, command);
|
|
163
157
|
if (!pretty)
|
|
164
158
|
return agentResult(0, { command, siteUrl, ...paging, keys });
|
|
165
|
-
return prettyResult(0, depth, command, keys.length ?
|
|
166
|
-
['
|
|
167
|
-
...keys.map((key) => [key.id, `${KIND_LABELS[key.kind] ?? key.kind} · ${key.name} · ${key.prefix}… · ${scopeNames(key.scopes)} ·
|
|
159
|
+
return prettyResult(0, depth, command, keys.length ? `Loaded ${count(keys.length, 'key')}.` : 'You have no API keys. Issue one with deepdynamic keys issue or deepdynamic keys create.', [
|
|
160
|
+
['Server', siteUrl],
|
|
161
|
+
...keys.map((key) => [key.id, `${KIND_LABELS[key.kind] ?? key.kind} · ${key.name} · ${key.prefix}… · ${scopeNames(key.scopes)} · Expires ${when(key.expiresAt)}`]),
|
|
168
162
|
...pageRows(paging)
|
|
169
163
|
]);
|
|
170
164
|
}
|
|
@@ -175,41 +169,41 @@ export async function runKeysList(args, pretty, depth, deps = defaultAuthDeps(pr
|
|
|
175
169
|
export async function runKeysIssue(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
176
170
|
const command = 'keys issue';
|
|
177
171
|
const { args: rest, dryRun } = splitDryRun(args);
|
|
178
|
-
const pre = parseIssue(rest
|
|
172
|
+
const pre = parseIssue(rest);
|
|
179
173
|
if (!('error' in pre) && pre.expiry && !pre.consented && !dryRun) {
|
|
180
174
|
return confirmationRequired(command, rest, pretty, depth, {
|
|
181
175
|
message: 'A pay key needs the consent to paid services and consolidated billing, and it can charge the account.',
|
|
182
|
-
display: 'pay
|
|
176
|
+
display: 'Issuing a pay key needs consent to paid services and consolidated billing. Confirm with the user, then run it with --yes.'
|
|
183
177
|
});
|
|
184
178
|
}
|
|
185
179
|
return rehearsed(command, args, pretty, depth, deps, (plain) => {
|
|
186
|
-
const parsed = parseIssue(plain
|
|
180
|
+
const parsed = parseIssue(plain);
|
|
187
181
|
if ('error' in parsed)
|
|
188
182
|
return parsed;
|
|
189
183
|
const { kind, expiry, consented } = parsed;
|
|
190
|
-
const { name,
|
|
184
|
+
const { name, prefix } = KINDS[kind];
|
|
191
185
|
const term = expiry ? { expiresInMinutes: expiry.minutes } : {};
|
|
192
186
|
const consent = expiry ? { consentRequired: true, consented } : {};
|
|
193
187
|
const body = { kind, ...term, ...(expiry && consented ? { consented: true } : {}) };
|
|
194
188
|
const payRows = expiry
|
|
195
189
|
? [
|
|
196
|
-
['
|
|
197
|
-
['
|
|
198
|
-
['
|
|
190
|
+
['Valid for', expiry.label],
|
|
191
|
+
['Consolidated billing', consented ? 'Agreed (--yes)' : 'Required. Add --yes once the user agrees to paid services and consolidated billing.'],
|
|
192
|
+
['Warning', 'This key can charge the account.']
|
|
199
193
|
]
|
|
200
194
|
: [];
|
|
201
195
|
return {
|
|
202
196
|
steps: expiry ? PAY_STEPS : ISSUE_STEPS,
|
|
203
|
-
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: keyUrl(siteUrl), body }, '
|
|
197
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: keyUrl(siteUrl), body }, 'Checked the key issue request. No key was issued.', [['Key', name], ['Prefix', prefix], ...payRows], { kind, name, prefix, ...term, ...consent }),
|
|
204
198
|
send: {
|
|
205
199
|
method: 'POST',
|
|
206
200
|
url: (siteUrl) => keyUrl(siteUrl),
|
|
207
201
|
body,
|
|
208
|
-
spinner: '
|
|
209
|
-
failed: '
|
|
202
|
+
spinner: 'Issuing the key.',
|
|
203
|
+
failed: 'Could not issue the key.',
|
|
210
204
|
notFound: httpFailure(404),
|
|
211
205
|
conflict: KEY_EXISTS,
|
|
212
|
-
done: (result, siteUrl) => issued(command, pretty, depth,
|
|
206
|
+
done: (result, siteUrl) => issued(command, pretty, depth, `Issued the ${name}.`, result, siteUrl)
|
|
213
207
|
}
|
|
214
208
|
};
|
|
215
209
|
});
|
|
@@ -217,23 +211,23 @@ export async function runKeysIssue(args, pretty, depth, deps = defaultAuthDeps(p
|
|
|
217
211
|
export async function runKeysCreate(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
218
212
|
const command = 'keys create';
|
|
219
213
|
return rehearsed(command, args, pretty, depth, deps, (rest) => {
|
|
220
|
-
const parsed = parseCreate(rest
|
|
214
|
+
const parsed = parseCreate(rest);
|
|
221
215
|
if ('error' in parsed)
|
|
222
216
|
return parsed;
|
|
223
217
|
const { name, scopes } = parsed;
|
|
224
218
|
const body = { kind: 'custom', name, scopes };
|
|
225
219
|
return {
|
|
226
220
|
steps: CREATE_STEPS,
|
|
227
|
-
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: keyUrl(siteUrl), body }, '
|
|
221
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: keyUrl(siteUrl), body }, 'Checked the key create request. No key was created.', [['Name', name], ['Prefix', CUSTOM_PREFIX], ['Scopes', scopeNames(scopes)]], { name, prefix: CUSTOM_PREFIX, scopes }),
|
|
228
222
|
send: {
|
|
229
223
|
method: 'POST',
|
|
230
224
|
url: (siteUrl) => keyUrl(siteUrl),
|
|
231
225
|
body,
|
|
232
|
-
spinner: '
|
|
233
|
-
failed: '
|
|
226
|
+
spinner: 'Creating the key.',
|
|
227
|
+
failed: 'Could not create the key.',
|
|
234
228
|
notFound: httpFailure(404),
|
|
235
229
|
conflict: KEY_EXISTS,
|
|
236
|
-
done: (result, siteUrl) => issued(command, pretty, depth,
|
|
230
|
+
done: (result, siteUrl) => issued(command, pretty, depth, `Created the key ${name}.`, result, siteUrl)
|
|
237
231
|
}
|
|
238
232
|
};
|
|
239
233
|
});
|
|
@@ -241,29 +235,29 @@ export async function runKeysCreate(args, pretty, depth, deps = defaultAuthDeps(
|
|
|
241
235
|
export async function runKeysRevoke(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
242
236
|
const command = 'keys revoke';
|
|
243
237
|
return rehearsed(command, args, pretty, depth, deps, (rest) => {
|
|
244
|
-
const id = parseRevoke(rest
|
|
238
|
+
const id = parseRevoke(rest);
|
|
245
239
|
if (typeof id !== 'string')
|
|
246
240
|
return id;
|
|
247
241
|
return {
|
|
248
242
|
steps: REVOKE_STEPS,
|
|
249
|
-
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: keyUrl(siteUrl, `/${encodeURIComponent(id)}/revoke`), body: {} }, '
|
|
243
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: keyUrl(siteUrl, `/${encodeURIComponent(id)}/revoke`), body: {} }, 'Checked the key revoke request. The key was not revoked.', [['Key ID', id], ['Impact', 'Revoking blocks every agent and tool that uses this key at once.']], { keyId: id }),
|
|
250
244
|
send: {
|
|
251
245
|
method: 'POST',
|
|
252
246
|
url: (siteUrl) => keyUrl(siteUrl, `/${encodeURIComponent(id)}/revoke`),
|
|
253
247
|
body: {},
|
|
254
|
-
spinner: '
|
|
255
|
-
failed: '
|
|
248
|
+
spinner: 'Revoking the key.',
|
|
249
|
+
failed: 'Could not revoke the key.',
|
|
256
250
|
notFound: KEY_NOT_FOUND,
|
|
257
251
|
done: (result, siteUrl) => {
|
|
258
252
|
const key = keyOf(result);
|
|
259
253
|
return pretty
|
|
260
|
-
? prettyResult(0, depth, command,
|
|
254
|
+
? prettyResult(0, depth, command, `Revoked the key ${key.name}.`, [['Server', siteUrl], ['Key ID', key.id], ['Key', `${KIND_LABELS[key.kind] ?? key.kind} · ${key.name}`], ['Impact', 'Agents and tools that used this key are now blocked.']])
|
|
261
255
|
: agentResult(0, { command, siteUrl, applied: true, keyId: key.id, key });
|
|
262
256
|
}
|
|
263
257
|
}
|
|
264
258
|
};
|
|
265
259
|
}, {
|
|
266
260
|
message: 'Revoking blocks every agent and tool that uses the key at once.',
|
|
267
|
-
display: '
|
|
261
|
+
display: 'Revoking blocks every agent and tool that uses the key at once. Confirm with the user, then run it with --yes.'
|
|
268
262
|
});
|
|
269
263
|
}
|
|
@@ -8,7 +8,7 @@ import { agentResult } from "../../output.js";
|
|
|
8
8
|
import { prettyResult } from "../../pretty.js";
|
|
9
9
|
import { openBrowser } from "../../runtime/browser.js";
|
|
10
10
|
import { startLoginScreen } from "../../runtime/login-screen.js";
|
|
11
|
-
import {
|
|
11
|
+
import { supportMessage } from "../../runtime/support.js";
|
|
12
12
|
export const CLIENT_ID = 'dd-cli';
|
|
13
13
|
export const LOGIN_TIMEOUT_MS = 10 * 60 * 1000;
|
|
14
14
|
export const defaultLoginDeps = () => ({
|
|
@@ -20,10 +20,10 @@ export const defaultLoginDeps = () => ({
|
|
|
20
20
|
stream: process.stdout.isTTY ? process.stderr : undefined,
|
|
21
21
|
timeoutMs: LOGIN_TIMEOUT_MS
|
|
22
22
|
});
|
|
23
|
-
const failure = (pretty, depth, code, message
|
|
24
|
-
? prettyResult(1, depth, 'login',
|
|
23
|
+
const failure = (pretty, depth, code, message) => pretty
|
|
24
|
+
? prettyResult(1, depth, 'login', message)
|
|
25
25
|
: agentResult(1, { command: 'login', error: { code, message } });
|
|
26
|
-
const supportResult = (pretty, depth, code) => failure(pretty, depth, code, supportMessage(code)
|
|
26
|
+
const supportResult = (pretty, depth, code) => failure(pretty, depth, code, supportMessage(code));
|
|
27
27
|
export const redirectUri = (port) => `http://127.0.0.1:${port}/callback`;
|
|
28
28
|
export function authorizeUrl(siteUrl, port, challenge, state, agent = false) {
|
|
29
29
|
const url = new URL('/login/device', siteUrl);
|
|
@@ -86,9 +86,9 @@ async function finish(deps, code, verifier, port, pretty, depth) {
|
|
|
86
86
|
credentialsPath: path
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
return prettyResult(0, depth, 'login', '
|
|
90
|
-
['
|
|
91
|
-
['
|
|
89
|
+
return prettyResult(0, depth, 'login', 'Logged in.', [
|
|
90
|
+
['Account', me.user.email ?? me.user.name ?? 'Account without email'],
|
|
91
|
+
['Credentials', path]
|
|
92
92
|
]);
|
|
93
93
|
}
|
|
94
94
|
export async function login(deps, pretty = false, depth = 1) {
|
|
@@ -105,7 +105,7 @@ export async function login(deps, pretty = false, depth = 1) {
|
|
|
105
105
|
const code = url.searchParams.get('code');
|
|
106
106
|
const error = url.searchParams.get('error');
|
|
107
107
|
if (done || url.pathname !== '/callback' || url.searchParams.get('state') !== state || (!code && !error)) {
|
|
108
|
-
response.writeHead(400, { 'content-type': 'text/plain; charset=utf-8' }).end('
|
|
108
|
+
response.writeHead(400, { 'content-type': 'text/plain; charset=utf-8' }).end('Invalid request.');
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
111
|
done = true;
|
|
@@ -115,7 +115,7 @@ export async function login(deps, pretty = false, depth = 1) {
|
|
|
115
115
|
const { port } = server.address();
|
|
116
116
|
const timer = setTimeout(() => settle(null), deps.timeoutMs);
|
|
117
117
|
const url = authorizeUrl(deps.siteUrl, port, challenge, state, !pretty);
|
|
118
|
-
const notice =
|
|
118
|
+
const notice = `Finish logging in to DeepDynamic Cloud in your browser.\nIf the browser does not open, open this URL yourself.\n ${url}\n`;
|
|
119
119
|
let stop;
|
|
120
120
|
try {
|
|
121
121
|
stop = pretty ? startLoginScreen(url, deps.stream) : undefined;
|
|
@@ -133,13 +133,13 @@ export async function login(deps, pretty = false, depth = 1) {
|
|
|
133
133
|
const callback = await received;
|
|
134
134
|
clearTimeout(timer);
|
|
135
135
|
if (!callback) {
|
|
136
|
-
return failure(pretty, depth, 'login_timeout', 'Login timed out. Run deepdynamic login to try again.'
|
|
136
|
+
return failure(pretty, depth, 'login_timeout', 'Login timed out. Run deepdynamic login to try again.');
|
|
137
137
|
}
|
|
138
138
|
if ('error' in callback) {
|
|
139
139
|
const cancelled = callback.error === 'access_denied';
|
|
140
140
|
await land(callback.response, deps.siteUrl, cancelled ? 'cancelled' : null);
|
|
141
141
|
return cancelled
|
|
142
|
-
? failure(pretty, depth, 'login_cancelled', 'Login was cancelled.'
|
|
142
|
+
? failure(pretty, depth, 'login_cancelled', 'Login was cancelled.')
|
|
143
143
|
: supportResult(pretty, depth, 'login_failed');
|
|
144
144
|
}
|
|
145
145
|
const result = await finish(deps, callback.code, verifier, port, pretty, depth).catch(() => supportResult(pretty, depth, 'login_failed'));
|
|
@@ -4,10 +4,10 @@ import { spec } from "../../registry.js";
|
|
|
4
4
|
import { plannedRequest, splitDryRun } from "../../runtime/dry-run.js";
|
|
5
5
|
import { parseServerArgs } from "../../runtime/server-options.js";
|
|
6
6
|
import { defaultLoginDeps, login } from "./flow.js";
|
|
7
|
-
const { name: command, usage
|
|
7
|
+
const { name: command, usage } = spec('login');
|
|
8
8
|
export async function runLogin(args, pretty, depth, loginDeps) {
|
|
9
9
|
const { args: rest, dryRun } = splitDryRun(args);
|
|
10
|
-
const options = parseServerArgs(rest
|
|
10
|
+
const options = parseServerArgs(rest);
|
|
11
11
|
if ('error' in options) {
|
|
12
12
|
if (!pretty) {
|
|
13
13
|
return agentResult(2, {
|
|
@@ -16,7 +16,7 @@ export async function runLogin(args, pretty, depth, loginDeps) {
|
|
|
16
16
|
usage
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
return prettyResult(2, depth, command, options.error, [['
|
|
19
|
+
return prettyResult(2, depth, command, options.error, [['Usage', usage]]);
|
|
20
20
|
}
|
|
21
21
|
const deps = loginDeps ?? defaultLoginDeps();
|
|
22
22
|
const siteUrl = options.siteUrl ?? deps.siteUrl;
|
package/dist/commands/logout.js
CHANGED
|
@@ -7,15 +7,15 @@ import { spec } from "../registry.js";
|
|
|
7
7
|
import { splitDryRun } from "../runtime/dry-run.js";
|
|
8
8
|
import { unknownArgument } from "../runtime/flags.js";
|
|
9
9
|
import { CLIENT_ID } from "./login/flow.js";
|
|
10
|
-
const { usage
|
|
10
|
+
const { usage } = spec('logout');
|
|
11
11
|
const LOGOUT_PATH = '/login/revoke';
|
|
12
12
|
const TOKEN_SETTINGS_PATH = '/projects';
|
|
13
13
|
export async function runLogout(args, pretty, depth, deps) {
|
|
14
14
|
const { args: rest, dryRun } = splitDryRun(args);
|
|
15
15
|
if (rest.length > 0) {
|
|
16
|
-
const message = unknownArgument(rest[0]
|
|
16
|
+
const message = unknownArgument(rest[0]);
|
|
17
17
|
return pretty
|
|
18
|
-
? prettyResult(2, depth, 'logout', message, [['
|
|
18
|
+
? prettyResult(2, depth, 'logout', message, [['Usage', usage]])
|
|
19
19
|
: agentResult(2, { command: 'logout', error: { code: 'invalid_arguments', message }, usage });
|
|
20
20
|
}
|
|
21
21
|
const path = credentialsPath();
|
|
@@ -24,7 +24,7 @@ export async function runLogout(args, pretty, depth, deps) {
|
|
|
24
24
|
if (!dryRun)
|
|
25
25
|
await removeCredentials(path);
|
|
26
26
|
return pretty
|
|
27
|
-
? prettyResult(0, depth, 'logout', '
|
|
27
|
+
? prettyResult(0, depth, 'logout', 'Already logged out.')
|
|
28
28
|
: agentResult(0, { command: 'logout', account: null, credentialsPath: path, ...(dryRun ? { dryRun: true } : {}) });
|
|
29
29
|
}
|
|
30
30
|
const email = await readAccountEmail(path);
|
|
@@ -32,14 +32,14 @@ export async function runLogout(args, pretty, depth, deps) {
|
|
|
32
32
|
const url = new URL(LOGOUT_PATH, siteUrl).href;
|
|
33
33
|
if (dryRun) {
|
|
34
34
|
return pretty
|
|
35
|
-
? prettyResult(0, depth, 'logout', '
|
|
35
|
+
? prettyResult(0, depth, 'logout', 'Checked without sending the request.', [['Server', siteUrl], ['Request', `POST ${url}`]])
|
|
36
36
|
: agentResult(0, { command: 'logout', account: { email }, siteUrl, credentialsPath: path, dryRun: true, request: { method: 'POST', url } });
|
|
37
37
|
}
|
|
38
38
|
const result = await request(url, {
|
|
39
39
|
method: 'POST',
|
|
40
40
|
headers: { 'content-type': 'application/json' },
|
|
41
41
|
body: JSON.stringify({ client_id: CLIENT_ID, token })
|
|
42
|
-
}, deps, pretty ? '
|
|
42
|
+
}, deps, pretty ? 'Revoking the access token.' : null);
|
|
43
43
|
await removeCredentials(path);
|
|
44
44
|
const failure = 'failure' in result
|
|
45
45
|
? result.failure
|
|
@@ -47,10 +47,10 @@ export async function runLogout(args, pretty, depth, deps) {
|
|
|
47
47
|
const settings = new URL(TOKEN_SETTINGS_PATH, siteUrl).href;
|
|
48
48
|
if (failure) {
|
|
49
49
|
return pretty
|
|
50
|
-
? prettyResult(1, depth, 'logout', '
|
|
51
|
-
['
|
|
52
|
-
['
|
|
53
|
-
['
|
|
50
|
+
? prettyResult(1, depth, 'logout', 'Deleted the saved login, but could not revoke the access token on the server.', [
|
|
51
|
+
['Server', siteUrl],
|
|
52
|
+
['Reason', failure.display],
|
|
53
|
+
['Revoke at', settings]
|
|
54
54
|
])
|
|
55
55
|
: agentResult(1, {
|
|
56
56
|
command: 'logout',
|
|
@@ -66,6 +66,6 @@ export async function runLogout(args, pretty, depth, deps) {
|
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
return pretty
|
|
69
|
-
? prettyResult(0, depth, 'logout', '
|
|
69
|
+
? prettyResult(0, depth, 'logout', 'Logged out.', [['Account', email ?? 'Account without email'], ['Deleted', path]])
|
|
70
70
|
: agentResult(0, { command: 'logout', account: { email }, siteUrl, credentialsPath: path, revoked: true });
|
|
71
71
|
}
|