@gheima/cli 0.9.3 → 0.9.4
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/CHANGELOG.md +6 -0
- package/dist/cli.js +65 -1
- package/dist/pack.js +3 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @gheima/cli
|
|
2
2
|
|
|
3
|
+
## 0.9.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0b37d69: `gheima login --resume` finishes on a credential that appeared since `login --no-wait` (saved with `login --with-key`, or `GHEIMA_API_KEY`) instead of waiting on a device code nobody will approve. A credential that was already there when the sign-in started does not count, so signing in again as another account still waits for the code.
|
|
8
|
+
|
|
3
9
|
## 0.9.3
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import { readFileSync, createReadStream, createWriteStream, existsSync, statSync
|
|
|
4
4
|
import { Readable } from 'node:stream';
|
|
5
5
|
import { pipeline } from 'node:stream/promises';
|
|
6
6
|
import { basename } from 'node:path';
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
7
8
|
import { Command } from 'commander';
|
|
8
9
|
import { GheimaError, GheimaClient, DEFAULT_API_URL } from '@gheima/sdk';
|
|
9
10
|
import { makeClient, transportOptions, VERSION } from './client.js';
|
|
@@ -182,7 +183,15 @@ program
|
|
|
182
183
|
async function startLoginOnly(baseUrl, profileName, urlOverride) {
|
|
183
184
|
const started = await startDeviceLogin(baseUrl, defaultClientName());
|
|
184
185
|
const expiresAt = Date.now() + started.expires_in * 1000;
|
|
185
|
-
|
|
186
|
+
const prior = resolveAuth({ profile: profileName, url: urlOverride });
|
|
187
|
+
savePendingLogin({
|
|
188
|
+
start: started,
|
|
189
|
+
expiresAt,
|
|
190
|
+
baseUrl,
|
|
191
|
+
profileName,
|
|
192
|
+
urlOverride,
|
|
193
|
+
priorKeyHash: prior ? keyHash(prior.apiKey) : undefined,
|
|
194
|
+
});
|
|
186
195
|
const result = {
|
|
187
196
|
status: 'pending',
|
|
188
197
|
userCode: started.user_code,
|
|
@@ -198,6 +207,10 @@ async function startLoginOnly(baseUrl, profileName, urlOverride) {
|
|
|
198
207
|
info(`Open ${color.bold(started.verification_uri_complete)} and approve it.`);
|
|
199
208
|
info('Then run `gheima login --resume` to finish signing in.');
|
|
200
209
|
}
|
|
210
|
+
/** A short fingerprint of an API key, so a pending sign-in can tell keys apart without storing one. */
|
|
211
|
+
function keyHash(apiKey) {
|
|
212
|
+
return createHash('sha256').update(apiKey).digest('hex').slice(0, 16);
|
|
213
|
+
}
|
|
201
214
|
/** `gheima login --resume`: finish the pending sign-in, or say it is still pending. */
|
|
202
215
|
async function resumeLogin(timeout) {
|
|
203
216
|
const seconds = timeout === undefined ? undefined : Number(timeout);
|
|
@@ -208,6 +221,31 @@ async function resumeLogin(timeout) {
|
|
|
208
221
|
if (!pending) {
|
|
209
222
|
throw new UsageError('No sign-in is waiting (none was started, or it expired). Run `gheima login --no-wait` first.');
|
|
210
223
|
}
|
|
224
|
+
// Signed in another way meanwhile (`login --with-key`, GHEIMA_API_KEY): no approval is coming
|
|
225
|
+
// for this code, so finish on the credential that works instead of polling until it expires.
|
|
226
|
+
// Only a credential that appeared SINCE `--no-wait`: one already there is what a deliberate
|
|
227
|
+
// re-login (another account, a key about to be revoked) is replacing.
|
|
228
|
+
const resolved = resolveAuth({ profile: pending.profileName, url: pending.urlOverride });
|
|
229
|
+
const existing = resolved && keyHash(resolved.apiKey) !== pending.priorKeyHash ? resolved : null;
|
|
230
|
+
const account = existing
|
|
231
|
+
? await new GheimaClient(transportOptions({ apiKey: existing.apiKey, url: existing.url })).account
|
|
232
|
+
.get()
|
|
233
|
+
.catch(() => null)
|
|
234
|
+
: null;
|
|
235
|
+
if (existing && account) {
|
|
236
|
+
clearPendingLogin();
|
|
237
|
+
const profile = existing.profile ?? pending.profileName;
|
|
238
|
+
if (isJsonMode()) {
|
|
239
|
+
return printJson({
|
|
240
|
+
status: 'signed_in',
|
|
241
|
+
account: { id: account.id, name: account.name, slug: account.slug },
|
|
242
|
+
profile,
|
|
243
|
+
source: existing.source,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
success(`Already signed in as ${color.bold(account.name)} (${account.slug}), via ${existing.source}`);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
211
249
|
const spin = spinner('Waiting for approval…');
|
|
212
250
|
let result;
|
|
213
251
|
try {
|
|
@@ -365,6 +403,32 @@ services
|
|
|
365
403
|
fail(err);
|
|
366
404
|
}
|
|
367
405
|
});
|
|
406
|
+
services
|
|
407
|
+
.command('set-registry-auth <service>')
|
|
408
|
+
.description('Save the credential to pull an image service’s private image (token on stdin)')
|
|
409
|
+
.requiredOption('--username <name>', 'registry username')
|
|
410
|
+
.requiredOption('--password-stdin', 'read the token or password from stdin, e.g. `echo $GHCR_TOKEN | gheima services set-registry-auth web --username me --password-stdin`')
|
|
411
|
+
.action(async (ref, opts, cmd) => {
|
|
412
|
+
const g = globals(cmd);
|
|
413
|
+
const client = makeClient(g);
|
|
414
|
+
// Only from stdin: a token on argv lands in shell history and in `ps` for every user.
|
|
415
|
+
const password = (await readStdin()).replace(/\r?\n$/, '');
|
|
416
|
+
if (!password)
|
|
417
|
+
fail('No token on stdin. Pipe it in: echo $TOKEN | gheima services set-registry-auth …');
|
|
418
|
+
try {
|
|
419
|
+
const id = await resolveServiceId(client, ref);
|
|
420
|
+
const saved = await client.services.setRegistryAuth(id, {
|
|
421
|
+
username: opts.username,
|
|
422
|
+
password,
|
|
423
|
+
});
|
|
424
|
+
if (g.json)
|
|
425
|
+
return printJson(saved);
|
|
426
|
+
success(`Saved the credential for ${saved.host} as ${saved.username}. It applies from the next deploy.`);
|
|
427
|
+
}
|
|
428
|
+
catch (err) {
|
|
429
|
+
fail(err);
|
|
430
|
+
}
|
|
431
|
+
});
|
|
368
432
|
services
|
|
369
433
|
.command('get <service>')
|
|
370
434
|
.description('Show service detail')
|
package/dist/pack.js
CHANGED
|
@@ -15,6 +15,9 @@ import { gzipSync } from 'node:zlib';
|
|
|
15
15
|
const WALK_SKIP = new Set(['.git', 'node_modules', '.gheima']);
|
|
16
16
|
const SECRET_DIRS = new Set(['.ssh', '.aws', '.gnupg', '.kube', '.docker']);
|
|
17
17
|
const SECRET_NAMES = new Set([
|
|
18
|
+
// direnv's per-folder environment: a shell script of `export KEY=value`, i.e. a `.env` by
|
|
19
|
+
// another name, and nothing a build reads.
|
|
20
|
+
'.envrc',
|
|
18
21
|
'.npmrc',
|
|
19
22
|
'.netrc',
|
|
20
23
|
'.pgpass',
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// GENERATED by scripts/write-version.mjs from package.json. Do not edit.
|
|
2
|
-
export const VERSION = '0.9.
|
|
2
|
+
export const VERSION = '0.9.4';
|