@coffre/ui 0.2.0 → 0.4.0
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/chunks/audit-sentence-BhHmvQX_.js +660 -0
- package/dist/chunks/audit-sentence-BhHmvQX_.js.map +1 -0
- package/dist/chunks/delete-place-CRX7ntE8.js +206 -0
- package/dist/chunks/delete-place-CRX7ntE8.js.map +1 -0
- package/dist/chunks/{directory-CSjWWUQ1.js → directory-zr3ek7Mc.js} +175 -60
- package/dist/chunks/directory-zr3ek7Mc.js.map +1 -0
- package/dist/chunks/folders-DoBmCwOi.js +207 -0
- package/dist/chunks/folders-DoBmCwOi.js.map +1 -0
- package/dist/chunks/grants-Cw1FyGID.js +669 -0
- package/dist/chunks/grants-Cw1FyGID.js.map +1 -0
- package/dist/chunks/offboarding-CE6d7um1.js +305 -0
- package/dist/chunks/offboarding-CE6d7um1.js.map +1 -0
- package/dist/chunks/one-time-DXEl9hbg.js +35 -0
- package/dist/chunks/one-time-DXEl9hbg.js.map +1 -0
- package/dist/chunks/page-DvsgZ2Hd.js +391 -0
- package/dist/chunks/page-DvsgZ2Hd.js.map +1 -0
- package/dist/chunks/principal-BIN-xwZw.js +42 -0
- package/dist/chunks/principal-BIN-xwZw.js.map +1 -0
- package/dist/chunks/{principal-page-D_91OA0l.js → principal-page-DhjO76GH.js} +245 -251
- package/dist/chunks/principal-page-DhjO76GH.js.map +1 -0
- package/dist/chunks/project-page-SRCtRe2g.js +17 -0
- package/dist/chunks/project-page-SRCtRe2g.js.map +1 -0
- package/dist/chunks/{queries-CQ81o4so.js → queries-DVR_i3rA.js} +132 -30
- package/dist/chunks/queries-DVR_i3rA.js.map +1 -0
- package/dist/chunks/references-B6pLT1uQ.js +343 -0
- package/dist/chunks/references-B6pLT1uQ.js.map +1 -0
- package/dist/chunks/{row-state-0PsrEzOL.js → row-state-DOPUsjQK.js} +3 -3
- package/dist/chunks/{row-state-0PsrEzOL.js.map → row-state-DOPUsjQK.js.map} +1 -1
- package/dist/chunks/signin-errors--ykMFuqN.js +57 -0
- package/dist/chunks/signin-errors--ykMFuqN.js.map +1 -0
- package/dist/chunks/tabs-BmwKfUeK.js +22 -0
- package/dist/chunks/tabs-BmwKfUeK.js.map +1 -0
- package/dist/chunks/{theme-B2vQolVR.js → theme-DJuz-xLM.js} +3 -3
- package/dist/chunks/{theme-B2vQolVR.js.map → theme-DJuz-xLM.js.map} +1 -1
- package/dist/chunks/{ui-DixXLQvQ.js → ui-DJje3gST.js} +6 -3
- package/dist/chunks/ui-DJje3gST.js.map +1 -0
- package/dist/chunks/{use-change-c6CeLRin.js → use-change-DUiGO19U.js} +52 -21
- package/dist/chunks/use-change-DUiGO19U.js.map +1 -0
- package/dist/chunks/{use-shell-jxd7Tzd-.js → use-shell-rNKfGjdj.js} +3 -3
- package/dist/chunks/{use-shell-jxd7Tzd-.js.map → use-shell-rNKfGjdj.js.map} +1 -1
- package/dist/chunks/validation-D312_NLf.js +87 -0
- package/dist/chunks/validation-D312_NLf.js.map +1 -0
- package/dist/index.d.ts +361 -27
- package/dist/index.js +188 -98
- package/dist/index.js.map +1 -1
- package/dist/pages/account.d.ts +2 -2
- package/dist/pages/account.js +297 -135
- package/dist/pages/account.js.map +1 -1
- package/dist/pages/approval.d.ts +9 -0
- package/dist/pages/approval.js +207 -0
- package/dist/pages/approval.js.map +1 -0
- package/dist/pages/audit.js +17 -542
- package/dist/pages/audit.js.map +1 -1
- package/dist/pages/device-login.js +2 -3
- package/dist/pages/device-login.js.map +1 -1
- package/dist/pages/environment.js +647 -257
- package/dist/pages/environment.js.map +1 -1
- package/dist/pages/login.js +18 -7
- package/dist/pages/login.js.map +1 -1
- package/dist/pages/oauth-authorize.d.ts +10 -0
- package/dist/pages/oauth-authorize.js +249 -0
- package/dist/pages/oauth-authorize.js.map +1 -0
- package/dist/pages/project-access.d.ts +6 -0
- package/dist/pages/project-access.js +370 -0
- package/dist/pages/project-access.js.map +1 -0
- package/dist/pages/project-environments.d.ts +4 -0
- package/dist/pages/project-environments.js +593 -0
- package/dist/pages/project-environments.js.map +1 -0
- package/dist/pages/project-settings.d.ts +4 -0
- package/dist/pages/project-settings.js +242 -0
- package/dist/pages/project-settings.js.map +1 -0
- package/dist/pages/project.d.ts +10 -2
- package/dist/pages/project.js +57 -934
- package/dist/pages/project.js.map +1 -1
- package/dist/pages/projects.js +53 -21
- package/dist/pages/projects.js.map +1 -1
- package/dist/pages/service-account.d.ts +10 -0
- package/dist/pages/{token.js → service-account.js} +115 -56
- package/dist/pages/service-account.js.map +1 -0
- package/dist/pages/service-accounts.d.ts +3 -0
- package/dist/pages/service-accounts.js +38 -0
- package/dist/pages/service-accounts.js.map +1 -0
- package/dist/pages/settings.d.ts +1 -0
- package/dist/pages/settings.js +104 -42
- package/dist/pages/settings.js.map +1 -1
- package/dist/pages/unregistered.js +2 -3
- package/dist/pages/unregistered.js.map +1 -1
- package/dist/pages/user.d.ts +6 -1
- package/dist/pages/user.js +18 -6
- package/dist/pages/user.js.map +1 -1
- package/dist/pages/users.js +6 -10
- package/dist/pages/users.js.map +1 -1
- package/package.json +3 -3
- package/src/components/actions-log.tsx +117 -0
- package/src/components/audit-sentence.tsx +55 -0
- package/src/components/command-palette.tsx +4 -4
- package/src/components/delete-place.tsx +180 -0
- package/src/components/directory.tsx +259 -110
- package/src/components/every-project.tsx +287 -0
- package/src/components/expiry-field.tsx +42 -0
- package/src/components/folders.tsx +219 -0
- package/src/components/grants.tsx +11 -4
- package/src/components/icons.tsx +2 -0
- package/src/components/missing.tsx +110 -0
- package/src/components/offboarding.tsx +61 -33
- package/src/components/page.tsx +4 -1
- package/src/components/principal-page.tsx +136 -106
- package/src/components/principal-picker.tsx +5 -5
- package/src/components/principal.tsx +4 -4
- package/src/components/references.tsx +323 -0
- package/src/components/service-tokens.tsx +115 -95
- package/src/components/shell.tsx +11 -32
- package/src/components/tabs.tsx +18 -0
- package/src/components/trusted-workloads.tsx +97 -79
- package/src/components/ui.tsx +8 -1
- package/src/index.ts +13 -2
- package/src/layout.tsx +2 -2
- package/src/lib/access-plan.ts +2 -2
- package/src/lib/audit-sentences.ts +161 -77
- package/src/lib/changes.ts +56 -5
- package/src/lib/coffre.ts +3 -2
- package/src/lib/one-time.ts +32 -0
- package/src/lib/project-access.ts +11 -23
- package/src/lib/project-page.ts +14 -0
- package/src/lib/queries.ts +126 -32
- package/src/lib/search.ts +25 -0
- package/src/lib/signin-errors.ts +45 -1
- package/src/lib/validation.ts +14 -0
- package/src/options.ts +187 -35
- package/src/pages/account.tsx +274 -129
- package/src/pages/approval.tsx +197 -0
- package/src/pages/audit.tsx +9 -61
- package/src/pages/environment.tsx +585 -286
- package/src/pages/login.tsx +8 -2
- package/src/pages/oauth-authorize.tsx +233 -0
- package/src/pages/project-access.tsx +219 -0
- package/src/pages/project-environments.tsx +582 -0
- package/src/pages/project-settings.tsx +259 -0
- package/src/pages/project.tsx +52 -879
- package/src/pages/projects.tsx +55 -18
- package/src/pages/service-account.tsx +50 -0
- package/src/pages/{tokens.tsx → service-accounts.tsx} +9 -6
- package/src/pages/settings.tsx +62 -8
- package/src/pages/user.tsx +16 -4
- package/src/pages/users.tsx +2 -2
- package/src/parity.ts +160 -0
- package/src/register.ts +58 -9
- package/src/router.tsx +4 -0
- package/src/shared/models.ts +6 -2
- package/src/styles/globals.css +536 -31
- package/dist/chunks/directory-CSjWWUQ1.js.map +0 -1
- package/dist/chunks/grants-saMQagmG.js +0 -160
- package/dist/chunks/grants-saMQagmG.js.map +0 -1
- package/dist/chunks/icons-D-PfAfnH.js +0 -203
- package/dist/chunks/icons-D-PfAfnH.js.map +0 -1
- package/dist/chunks/offboarding-C6l30DZR.js +0 -263
- package/dist/chunks/offboarding-C6l30DZR.js.map +0 -1
- package/dist/chunks/page-C5HcNqf2.js +0 -190
- package/dist/chunks/page-C5HcNqf2.js.map +0 -1
- package/dist/chunks/principal-page-D_91OA0l.js.map +0 -1
- package/dist/chunks/queries-CQ81o4so.js.map +0 -1
- package/dist/chunks/signin-errors-BEFlVDbQ.js +0 -30
- package/dist/chunks/signin-errors-BEFlVDbQ.js.map +0 -1
- package/dist/chunks/ui-DixXLQvQ.js.map +0 -1
- package/dist/chunks/use-action-CWsg_YWU.js +0 -49
- package/dist/chunks/use-action-CWsg_YWU.js.map +0 -1
- package/dist/chunks/use-change-c6CeLRin.js.map +0 -1
- package/dist/chunks/validation-BQtqPe2V.js +0 -29
- package/dist/chunks/validation-BQtqPe2V.js.map +0 -1
- package/dist/pages/token.d.ts +0 -3
- package/dist/pages/token.js.map +0 -1
- package/dist/pages/tokens.d.ts +0 -3
- package/dist/pages/tokens.js +0 -39
- package/dist/pages/tokens.js.map +0 -1
- package/dist/project-BqIy8gYR.d.ts +0 -5
- package/src/lib/instance.ts +0 -13
- package/src/pages/token.tsx +0 -34
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { CoffreError, planImport, type CoffreClient } from '@coffre/client';
|
|
1
|
+
import { byFolder, CoffreError, foldersOf, planImport, type CoffreClient, type ListedReference } from '@coffre/client';
|
|
2
2
|
import { parseDotenv } from '@coffre/core/dotenv';
|
|
3
3
|
import {
|
|
4
4
|
useEffect,
|
|
5
5
|
useRef,
|
|
6
6
|
useState,
|
|
7
7
|
type InputHTMLAttributes,
|
|
8
|
+
type TextareaHTMLAttributes,
|
|
8
9
|
} from 'react';
|
|
9
|
-
import { useSuspenseQuery } from '@tanstack/react-query';
|
|
10
|
+
import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
|
|
10
11
|
import { Link } from '@tanstack/react-router';
|
|
11
12
|
import { useShell } from '../lib/use-shell';
|
|
12
13
|
import { Menu } from '@base-ui/react/menu';
|
|
13
14
|
import { toast } from 'sonner';
|
|
14
15
|
import { failureMessage, useCoffre } from '../lib/coffre';
|
|
15
|
-
import { archiveSecret, restoreSecret, saveSecrets, UnsavedEdits } from '../lib/changes';
|
|
16
|
+
import { archiveSecret, moveSecret, restoreSecret, saveSecrets, UnsavedEdits } from '../lib/changes';
|
|
16
17
|
import type { ItemStatus } from '../lib/optimistic';
|
|
17
18
|
import { affects, keys as queryKeys, queries } from '../lib/queries';
|
|
18
19
|
import { useChange, useChangeStatus } from '../lib/use-change';
|
|
@@ -37,6 +38,7 @@ import { secretKeyProblem } from '../lib/validation';
|
|
|
37
38
|
import {
|
|
38
39
|
breakAfterUnderscores,
|
|
39
40
|
ConfirmButton,
|
|
41
|
+
ConfirmDialog,
|
|
40
42
|
CopyButton,
|
|
41
43
|
EmptyState,
|
|
42
44
|
ErrorLine,
|
|
@@ -49,12 +51,19 @@ import {
|
|
|
49
51
|
} from '../components/ui';
|
|
50
52
|
import { Card, ClosedDoor, PageHeader } from '../components/page';
|
|
51
53
|
import { SecretReadOnly } from '../components/affordances';
|
|
54
|
+
import { FolderMenu, FolderRow, MoveToFolder } from '../components/folders';
|
|
55
|
+
import { MissingKeys } from '../components/missing';
|
|
56
|
+
import { ArchiveBlocked, archiveBlockers, LentReferences, MakeReference, ReferenceValue } from '../components/references';
|
|
57
|
+
import { isActiveAccessibleEnvironment } from '../lib/project-environments';
|
|
52
58
|
import {
|
|
53
59
|
AlertCircle,
|
|
54
60
|
Archive,
|
|
61
|
+
Check,
|
|
55
62
|
Clock,
|
|
56
63
|
Eye,
|
|
64
|
+
ArrowRight,
|
|
57
65
|
EyeOff,
|
|
66
|
+
Folder,
|
|
58
67
|
Hash,
|
|
59
68
|
History,
|
|
60
69
|
Key,
|
|
@@ -64,6 +73,7 @@ import {
|
|
|
64
73
|
Plus,
|
|
65
74
|
RotateBack,
|
|
66
75
|
Search,
|
|
76
|
+
SlashCircle,
|
|
67
77
|
Terminal,
|
|
68
78
|
Upload,
|
|
69
79
|
X,
|
|
@@ -139,6 +149,18 @@ function EnvironmentLedger({
|
|
|
139
149
|
const save = useChange(saveSecrets(coffre, { project, environment }, principal?.id ?? null));
|
|
140
150
|
const restore = useChange(restoreSecret(coffre, { project, environment }));
|
|
141
151
|
const archive = useChange(archiveSecret(coffre, { project, environment }));
|
|
152
|
+
const move = useChange(moveSecret(coffre, { project, environment }));
|
|
153
|
+
// The references that read this environment's secrets from elsewhere, and the environments you read.
|
|
154
|
+
const { data: references } = useQuery(queries.references(coffre, `${project}/${environment}`));
|
|
155
|
+
const lentBy = new Map<string, ListedReference[]>();
|
|
156
|
+
for (const reference of references?.ok === true ? references.references : []) {
|
|
157
|
+
const [sourceProject, sourceEnvironment, key] = reference.source.split('/') as [string, string, string];
|
|
158
|
+
if (sourceProject !== project || sourceEnvironment !== environment) continue;
|
|
159
|
+
lentBy.set(key, [...(lentBy.get(key) ?? []), reference]);
|
|
160
|
+
}
|
|
161
|
+
const readable = useShell().projects.flatMap((each) => each.environments
|
|
162
|
+
.filter(isActiveAccessibleEnvironment)
|
|
163
|
+
.map((one) => `${each.slug}/${one.slug}`));
|
|
142
164
|
const { status, dismiss } = useChangeStatus(queryKeys.secrets({ project, environment }));
|
|
143
165
|
const [drafts, setDrafts] = useState<SecretDraft[]>([]);
|
|
144
166
|
const [changes, setChanges] = useState<Record<string, SecretChange>>({});
|
|
@@ -153,7 +175,31 @@ function EnvironmentLedger({
|
|
|
153
175
|
const canArchive = permissions.includes('secret.archive');
|
|
154
176
|
const canReveal = canRevealSecrets(permissions);
|
|
155
177
|
|
|
156
|
-
|
|
178
|
+
// Listed by folder: those in none first, then each folder by name.
|
|
179
|
+
const active = byFolder(keys.filter((entry) => !entry.archived)).flatMap(([, entries]) => entries);
|
|
180
|
+
const folders = foldersOf(active);
|
|
181
|
+
// Renaming or removing a folder: everything in it at once, the keys staying where they are.
|
|
182
|
+
const refile = useAction();
|
|
183
|
+
const place = `${project}/${environment}`;
|
|
184
|
+
const folderMenu = (folder: string, count: number) =>
|
|
185
|
+
canWrite && (
|
|
186
|
+
<FolderMenu
|
|
187
|
+
folder={folder}
|
|
188
|
+
count={count}
|
|
189
|
+
what="key"
|
|
190
|
+
folders={folders}
|
|
191
|
+
onRename={(name) =>
|
|
192
|
+
void refile.run(() => coffre.folders.renameKeys(place, folder, name), {
|
|
193
|
+
affects: affects.secrets({ project, environment }),
|
|
194
|
+
onSuccess: () => toast.success(`${folder}/ is ${name}/ now`),
|
|
195
|
+
})}
|
|
196
|
+
onRemove={() =>
|
|
197
|
+
void refile.run(() => coffre.folders.removeKeys(place, folder), {
|
|
198
|
+
affects: affects.secrets({ project, environment }),
|
|
199
|
+
onSuccess: () => toast.success(`${folder}/ removed: its keys are in no folder`),
|
|
200
|
+
})}
|
|
201
|
+
/>
|
|
202
|
+
);
|
|
157
203
|
const archived = keys.filter((entry) => entry.archived);
|
|
158
204
|
const existing = new Set(keys.map((entry) => entry.key));
|
|
159
205
|
|
|
@@ -192,6 +238,48 @@ function EnvironmentLedger({
|
|
|
192
238
|
});
|
|
193
239
|
}
|
|
194
240
|
|
|
241
|
+
/**
|
|
242
|
+
* One row's own Save: its change alone goes, and any other row's stays
|
|
243
|
+
* pending. A row opened and left as it was just closes.
|
|
244
|
+
*/
|
|
245
|
+
function saveRow(key: string) {
|
|
246
|
+
const change = secretChangeFor(changes, key);
|
|
247
|
+
dropChange(key);
|
|
248
|
+
if (change === undefined) return;
|
|
249
|
+
sendAlone({ active, drafts: [], changes: { [key]: change } });
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function saveDraft(draft: SecretDraft) {
|
|
253
|
+
setDrafts((rows) => rows.filter((row) => row.id !== draft.id));
|
|
254
|
+
sendAlone({ active, drafts: [draft], changes: {} });
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Whether one row's change could go alone: named, well named, and clashing with nothing. */
|
|
258
|
+
function readyAlone(drafts: SecretDraft[], changes: Record<string, SecretChange>): boolean {
|
|
259
|
+
const names = [
|
|
260
|
+
...drafts.map((row) => row.key.trim()),
|
|
261
|
+
...Object.values(changes).flatMap((change) => (change.archived ? [] : [change.key.trim()])),
|
|
262
|
+
];
|
|
263
|
+
return (
|
|
264
|
+
(drafts.length > 0 || Object.keys(changes).length > 0) &&
|
|
265
|
+
names.every((name) => name !== '' && secretKeyProblem(name) === null) &&
|
|
266
|
+
!hasSecretEditConflict(active, drafts, changes)
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function sendAlone(batch: { active: SecretKey[]; drafts: SecretDraft[]; changes: Record<string, SecretChange> }) {
|
|
271
|
+
setSaveError(null);
|
|
272
|
+
save(batch, {
|
|
273
|
+
// What did not go comes back as it was, beside the other pending rows.
|
|
274
|
+
onError: (error) => {
|
|
275
|
+
const left = error instanceof UnsavedEdits ? error.outcome : batch;
|
|
276
|
+
setDrafts((rows) => [...rows, ...left.drafts]);
|
|
277
|
+
setChanges((current) => ({ ...current, ...left.changes }));
|
|
278
|
+
setSaveError(failureMessage(error));
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
195
283
|
function dropChange(key: string) {
|
|
196
284
|
setChanges((current) => {
|
|
197
285
|
const { [key]: _, ...rest } = current;
|
|
@@ -205,9 +293,8 @@ function EnvironmentLedger({
|
|
|
205
293
|
}
|
|
206
294
|
|
|
207
295
|
function addDraft() {
|
|
208
|
-
// New rows go
|
|
209
|
-
|
|
210
|
-
setDrafts((rows) => [{ id: nextDraftId.current++, key: '', value: '' }, ...rows]);
|
|
296
|
+
// New rows go last, by the button that made them, in the order they were added.
|
|
297
|
+
setDrafts((rows) => [...rows, { id: nextDraftId.current++, key: '', value: '' }]);
|
|
211
298
|
}
|
|
212
299
|
|
|
213
300
|
function discardAll() {
|
|
@@ -319,17 +406,6 @@ function EnvironmentLedger({
|
|
|
319
406
|
tile={project}
|
|
320
407
|
title={environment}
|
|
321
408
|
aside={<EnvironmentName project={project} environment={environment} />}
|
|
322
|
-
actions={
|
|
323
|
-
<>
|
|
324
|
-
{canWrite && canReveal && <ImportEnv project={project} environment={environment} />}
|
|
325
|
-
{canWrite && (
|
|
326
|
-
<button className="btn btn-primary" onClick={addDraft}>
|
|
327
|
-
<Plus size={14} />
|
|
328
|
-
New secret
|
|
329
|
-
</button>
|
|
330
|
-
)}
|
|
331
|
-
</>
|
|
332
|
-
}
|
|
333
409
|
/>
|
|
334
410
|
|
|
335
411
|
{(active.length > 0 || drafts.length > 0) && (
|
|
@@ -362,22 +438,17 @@ function EnvironmentLedger({
|
|
|
362
438
|
</div>
|
|
363
439
|
)}
|
|
364
440
|
|
|
365
|
-
<
|
|
441
|
+
<MissingKeys
|
|
442
|
+
project={project}
|
|
443
|
+
environment={environment}
|
|
444
|
+
canWrite={canWrite}
|
|
445
|
+
onAdd={(key) => setDrafts((rows) => [...rows, { id: nextDraftId.current++, key, value: '' }])}
|
|
446
|
+
/>
|
|
447
|
+
|
|
448
|
+
{refile.error !== null && <ErrorLine error={refile.error} />}
|
|
449
|
+
<section className="card card-wide" aria-label="Secrets">
|
|
366
450
|
{active.length === 0 && drafts.length === 0 ? (
|
|
367
|
-
<EmptyState
|
|
368
|
-
title="No secrets yet"
|
|
369
|
-
actions={
|
|
370
|
-
canWrite ? (
|
|
371
|
-
<>
|
|
372
|
-
<button className="btn btn-primary" onClick={addDraft}>
|
|
373
|
-
<Plus size={14} />
|
|
374
|
-
New secret
|
|
375
|
-
</button>
|
|
376
|
-
{canReveal && <ImportEnv project={project} environment={environment} />}
|
|
377
|
-
</>
|
|
378
|
-
) : undefined
|
|
379
|
-
}
|
|
380
|
-
>
|
|
451
|
+
<EmptyState title="No secrets yet">
|
|
381
452
|
{canWrite
|
|
382
453
|
? 'Add them one by one, or import an existing .env file. Nothing is written until you save, or until you have seen the import plan.'
|
|
383
454
|
: 'Nothing has been written to this environment, and adding the first secret needs secret.write.'}
|
|
@@ -419,24 +490,9 @@ function EnvironmentLedger({
|
|
|
419
490
|
</tr>
|
|
420
491
|
</thead>
|
|
421
492
|
<tbody>
|
|
422
|
-
{
|
|
423
|
-
<
|
|
424
|
-
|
|
425
|
-
draft={draft}
|
|
426
|
-
existingVersion={
|
|
427
|
-
keys.find((entry) => entry.key === draft.key.trim())?.version ?? null
|
|
428
|
-
}
|
|
429
|
-
disabled={false}
|
|
430
|
-
onChange={(patch) =>
|
|
431
|
-
setDrafts((rows) =>
|
|
432
|
-
rows.map((row) => (row.id === draft.id ? { ...row, ...patch } : row)),
|
|
433
|
-
)
|
|
434
|
-
}
|
|
435
|
-
onRemove={() => setDrafts((rows) => rows.filter((row) => row.id !== draft.id))}
|
|
436
|
-
/>
|
|
437
|
-
))}
|
|
438
|
-
|
|
439
|
-
{listed.map((entry) => {
|
|
493
|
+
{byFolder(listed).flatMap(([folder, entries]) => [
|
|
494
|
+
...(folder === null ? [] : [<FolderRow key={`folder:${folder}`} folder={folder} count={entries.length} columns={columns} actions={folderMenu(folder, entries.length)} />]),
|
|
495
|
+
...entries.map((entry) => {
|
|
440
496
|
const change = secretChangeFor(changes, entry.key);
|
|
441
497
|
const state = status(entry.key);
|
|
442
498
|
return (
|
|
@@ -454,6 +510,10 @@ function EnvironmentLedger({
|
|
|
454
510
|
canWrite={canWrite}
|
|
455
511
|
canArchive={canArchive}
|
|
456
512
|
canReveal={canReveal}
|
|
513
|
+
folders={folders}
|
|
514
|
+
onMove={(folder) => move({ key: entry.key, folder })}
|
|
515
|
+
lent={lentBy.get(entry.key) ?? []}
|
|
516
|
+
environments={readable}
|
|
457
517
|
status={state}
|
|
458
518
|
// Not while its save is on its way.
|
|
459
519
|
disabled={state.state === 'pending'}
|
|
@@ -461,6 +521,10 @@ function EnvironmentLedger({
|
|
|
461
521
|
onEdit={() => setEditing((current) => new Set(current).add(entry.key))}
|
|
462
522
|
onPatch={(patch) => patchChange(entry, patch)}
|
|
463
523
|
onUndo={() => dropChange(entry.key)}
|
|
524
|
+
onSave={() => saveRow(entry.key)}
|
|
525
|
+
saveReady={
|
|
526
|
+
change === undefined || readyAlone([], { [entry.key]: change })
|
|
527
|
+
}
|
|
464
528
|
onMarkArchive={() => {
|
|
465
529
|
setEditing((current) => {
|
|
466
530
|
const next = new Set(current);
|
|
@@ -474,7 +538,8 @@ function EnvironmentLedger({
|
|
|
474
538
|
}}
|
|
475
539
|
/>
|
|
476
540
|
);
|
|
477
|
-
|
|
541
|
+
}),
|
|
542
|
+
])}
|
|
478
543
|
|
|
479
544
|
{listed.length === 0 && active.length > 0 && (
|
|
480
545
|
<tr>
|
|
@@ -483,22 +548,47 @@ function EnvironmentLedger({
|
|
|
483
548
|
</td>
|
|
484
549
|
</tr>
|
|
485
550
|
)}
|
|
551
|
+
|
|
552
|
+
{drafts.map((draft) => (
|
|
553
|
+
<DraftRow
|
|
554
|
+
key={draft.id}
|
|
555
|
+
draft={draft}
|
|
556
|
+
existingVersion={
|
|
557
|
+
keys.find((entry) => entry.key === draft.key.trim())?.version ?? null
|
|
558
|
+
}
|
|
559
|
+
disabled={false}
|
|
560
|
+
onChange={(patch) =>
|
|
561
|
+
setDrafts((rows) =>
|
|
562
|
+
rows.map((row) => (row.id === draft.id ? { ...row, ...patch } : row)),
|
|
563
|
+
)
|
|
564
|
+
}
|
|
565
|
+
onRemove={() => setDrafts((rows) => rows.filter((row) => row.id !== draft.id))}
|
|
566
|
+
onSave={() => saveDraft(draft)}
|
|
567
|
+
saveReady={readyAlone([draft], {})}
|
|
568
|
+
/>
|
|
569
|
+
))}
|
|
486
570
|
</tbody>
|
|
487
571
|
</table>
|
|
488
572
|
</div>
|
|
489
573
|
)}
|
|
490
574
|
</section>
|
|
491
575
|
|
|
576
|
+
{canWrite && (
|
|
577
|
+
<div className="table-actions">
|
|
578
|
+
<button className="btn btn-primary" onClick={addDraft}>
|
|
579
|
+
<Plus size={14} />
|
|
580
|
+
New secret
|
|
581
|
+
</button>
|
|
582
|
+
{canReveal && <ImportEnv project={project} environment={environment} />}
|
|
583
|
+
</div>
|
|
584
|
+
)}
|
|
585
|
+
|
|
492
586
|
{archived.length > 0 && (
|
|
493
587
|
<Card
|
|
588
|
+
wide
|
|
494
589
|
labelledBy="archived-secrets"
|
|
495
590
|
title="Archived"
|
|
496
|
-
description=
|
|
497
|
-
<>
|
|
498
|
-
Retired, so no longer served or injected by <code>coffre run</code>. Their history
|
|
499
|
-
and audit trail are intact, and restoring is immediate.
|
|
500
|
-
</>
|
|
501
|
-
}
|
|
591
|
+
description="No longer served; restoring one brings it back with its history."
|
|
502
592
|
>
|
|
503
593
|
<div className="dt-wrap">
|
|
504
594
|
<table className="dt secrets secrets-archived stacks">
|
|
@@ -617,16 +707,44 @@ function MaskedInput({
|
|
|
617
707
|
className = '',
|
|
618
708
|
...props
|
|
619
709
|
}: Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> & { masked: boolean }) {
|
|
710
|
+
const cssMask = useCssMask();
|
|
711
|
+
return (
|
|
712
|
+
<input
|
|
713
|
+
{...props}
|
|
714
|
+
type={masked && !cssMask ? 'password' : 'text'}
|
|
715
|
+
className={`${className}${masked && cssMask ? ' is-masked' : ''}`}
|
|
716
|
+
autoComplete="off"
|
|
717
|
+
spellCheck={false}
|
|
718
|
+
data-1p-ignore
|
|
719
|
+
data-lpignore="true"
|
|
720
|
+
data-bwignore
|
|
721
|
+
/>
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
function useCssMask(): boolean {
|
|
620
726
|
const [cssMask, setCssMask] = useState(false);
|
|
621
727
|
useEffect(() => {
|
|
622
728
|
setCssMask(typeof CSS !== 'undefined' && CSS.supports('-webkit-text-security', 'disc'));
|
|
623
729
|
}, []);
|
|
730
|
+
return cssMask;
|
|
731
|
+
}
|
|
624
732
|
|
|
733
|
+
/**
|
|
734
|
+
* MaskedInput for a value with line breaks, which a text input would drop.
|
|
735
|
+
* Without the CSS mask there is no password textarea, so masked text is
|
|
736
|
+
* drawn transparent instead.
|
|
737
|
+
*/
|
|
738
|
+
function MaskedTextarea({
|
|
739
|
+
masked,
|
|
740
|
+
className = '',
|
|
741
|
+
...props
|
|
742
|
+
}: TextareaHTMLAttributes<HTMLTextAreaElement> & { masked: boolean }) {
|
|
743
|
+
const cssMask = useCssMask();
|
|
625
744
|
return (
|
|
626
|
-
<
|
|
745
|
+
<textarea
|
|
627
746
|
{...props}
|
|
628
|
-
|
|
629
|
-
className={`${className}${masked && cssMask ? ' is-masked' : ''}`}
|
|
747
|
+
className={`${className}${masked ? (cssMask ? ' is-masked' : ' is-masked-fallback') : ''}`}
|
|
630
748
|
autoComplete="off"
|
|
631
749
|
spellCheck={false}
|
|
632
750
|
data-1p-ignore
|
|
@@ -636,9 +754,12 @@ function MaskedInput({
|
|
|
636
754
|
);
|
|
637
755
|
}
|
|
638
756
|
|
|
757
|
+
const lineCount = (text: string) => text.split('\n').length;
|
|
758
|
+
|
|
639
759
|
function ValueField({
|
|
640
760
|
label,
|
|
641
761
|
value,
|
|
762
|
+
start = '',
|
|
642
763
|
onChange,
|
|
643
764
|
placeholder,
|
|
644
765
|
disabled,
|
|
@@ -647,6 +768,8 @@ function ValueField({
|
|
|
647
768
|
}: {
|
|
648
769
|
label: string;
|
|
649
770
|
value: string;
|
|
771
|
+
/** The value the edit started from. */
|
|
772
|
+
start?: string;
|
|
650
773
|
onChange: (value: string) => void;
|
|
651
774
|
placeholder: string;
|
|
652
775
|
disabled: boolean;
|
|
@@ -654,21 +777,32 @@ function ValueField({
|
|
|
654
777
|
onEscape?: () => void;
|
|
655
778
|
}) {
|
|
656
779
|
const [shown, setShown] = useState(false);
|
|
780
|
+
const field = {
|
|
781
|
+
className: 'input input-mono',
|
|
782
|
+
masked: !shown,
|
|
783
|
+
'aria-label': label,
|
|
784
|
+
placeholder,
|
|
785
|
+
value,
|
|
786
|
+
disabled,
|
|
787
|
+
autoFocus,
|
|
788
|
+
onChange: (event: { target: { value: string } }) => onChange(event.target.value),
|
|
789
|
+
onKeyDown: (event: { key: string }) => {
|
|
790
|
+
if (event.key === 'Escape' && onEscape !== undefined) onEscape();
|
|
791
|
+
},
|
|
792
|
+
};
|
|
657
793
|
return (
|
|
658
794
|
<div className="input-group">
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
}}
|
|
671
|
-
/>
|
|
795
|
+
{/* A value with line breaks opens one line tall, as tall as the row it
|
|
796
|
+
replaces, and grows only by the lines typed into it. */}
|
|
797
|
+
{start.includes('\n') ? (
|
|
798
|
+
<MaskedTextarea
|
|
799
|
+
{...field}
|
|
800
|
+
className="input input-mono value-lines"
|
|
801
|
+
rows={Math.min(8, 1 + Math.max(0, lineCount(value) - lineCount(start)))}
|
|
802
|
+
/>
|
|
803
|
+
) : (
|
|
804
|
+
<MaskedInput {...field} />
|
|
805
|
+
)}
|
|
672
806
|
<button
|
|
673
807
|
type="button"
|
|
674
808
|
className="btn btn-quiet btn-sm btn-icon input-addon"
|
|
@@ -704,12 +838,18 @@ function SecretRow({
|
|
|
704
838
|
canWrite,
|
|
705
839
|
canArchive,
|
|
706
840
|
canReveal,
|
|
841
|
+
folders,
|
|
842
|
+
onMove,
|
|
843
|
+
lent,
|
|
844
|
+
environments,
|
|
707
845
|
status,
|
|
708
846
|
disabled,
|
|
709
847
|
columns,
|
|
710
848
|
onEdit,
|
|
711
849
|
onPatch,
|
|
712
850
|
onUndo,
|
|
851
|
+
onSave,
|
|
852
|
+
saveReady,
|
|
713
853
|
onMarkArchive,
|
|
714
854
|
}: {
|
|
715
855
|
number: number;
|
|
@@ -721,6 +861,13 @@ function SecretRow({
|
|
|
721
861
|
canWrite: boolean;
|
|
722
862
|
canArchive: boolean;
|
|
723
863
|
canReveal: boolean;
|
|
864
|
+
/** The folders in use in this environment, offered when moving it. */
|
|
865
|
+
folders: readonly string[];
|
|
866
|
+
onMove: (folder: string | null) => void;
|
|
867
|
+
/** The references that read this secret from elsewhere. */
|
|
868
|
+
lent: ListedReference[];
|
|
869
|
+
/** The environments you read, offered when making this a reference. */
|
|
870
|
+
environments: readonly string[];
|
|
724
871
|
/** A save of this row on its way, or refused. */
|
|
725
872
|
status: ItemStatus;
|
|
726
873
|
disabled: boolean;
|
|
@@ -728,12 +875,28 @@ function SecretRow({
|
|
|
728
875
|
onEdit: () => void;
|
|
729
876
|
onPatch: (patch: Partial<SecretChange>) => void;
|
|
730
877
|
onUndo: () => void;
|
|
878
|
+
/** This row's change alone, saved now. */
|
|
879
|
+
onSave: () => void;
|
|
880
|
+
saveReady: boolean;
|
|
731
881
|
onMarkArchive: () => void;
|
|
732
882
|
}) {
|
|
733
883
|
const [reveal, setReveal] = useState<Reveal | null>(null);
|
|
734
884
|
const coffre = useCoffre();
|
|
735
885
|
const [revealing, setRevealing] = useState(false);
|
|
736
886
|
const [historyOpen, setHistoryOpen] = useState(false);
|
|
887
|
+
const [moving, setMoving] = useState(false);
|
|
888
|
+
const [referring, setReferring] = useState(false);
|
|
889
|
+
const [breaking, setBreaking] = useState<string | null>(null);
|
|
890
|
+
const [lentOpen, setLentOpen] = useState(false);
|
|
891
|
+
// Archiving a key others read through references waits until they are broken (D41).
|
|
892
|
+
const [archiveBlocked, setArchiveBlocked] = useState(false);
|
|
893
|
+
const blockers = archiveBlockers(`${project}/${environment}/${entry.key}`, lent);
|
|
894
|
+
// Making or breaking a reference: its refusal shows under the row, as a reveal's does.
|
|
895
|
+
const { run: act, error: actError } = useAction();
|
|
896
|
+
const { reference } = entry;
|
|
897
|
+
// What a reveal shows: its own version, or, as a reference, its source's.
|
|
898
|
+
const readVersion = reference === null ? entry.version : reference.version;
|
|
899
|
+
const holderPath = `${project}/${environment}/${entry.key}`;
|
|
737
900
|
const [error, setError] = useState<string | null>(null);
|
|
738
901
|
// The current value, loaded on request as the starting point for an edit.
|
|
739
902
|
// It is not a change until it is edited: saving it untouched would append a
|
|
@@ -744,10 +907,10 @@ function SecretRow({
|
|
|
744
907
|
// different version -- saved here, rolled back, or written by someone else
|
|
745
908
|
// and picked up on refresh -- the old plaintext is not the value any more,
|
|
746
909
|
// and must not stay on screen pretending to be.
|
|
747
|
-
const shown = revealIsCurrent(reveal,
|
|
910
|
+
const shown = revealIsCurrent(reveal, readVersion) ? reveal : null;
|
|
748
911
|
useEffect(() => {
|
|
749
|
-
if (reveal !== null && !revealIsCurrent(reveal,
|
|
750
|
-
}, [reveal,
|
|
912
|
+
if (reveal !== null && !revealIsCurrent(reveal, readVersion)) setReveal(null);
|
|
913
|
+
}, [reveal, readVersion]);
|
|
751
914
|
|
|
752
915
|
useEffect(() => {
|
|
753
916
|
if (reveal === null) return;
|
|
@@ -757,19 +920,19 @@ function SecretRow({
|
|
|
757
920
|
|
|
758
921
|
const secondsLeft = useSecondsLeft(shown);
|
|
759
922
|
|
|
760
|
-
const editBase = editing && revealIsCurrent(base,
|
|
923
|
+
const editBase = editing && revealIsCurrent(base, readVersion) ? base : null;
|
|
761
924
|
useEffect(() => {
|
|
762
925
|
if (!editing) setBase(null);
|
|
763
926
|
}, [editing]);
|
|
764
927
|
|
|
765
|
-
async function readValue(): Promise<string | null> {
|
|
928
|
+
async function readValue({ show = true } = {}): Promise<string | null> {
|
|
766
929
|
if (shown !== null) return shown.value;
|
|
767
930
|
setRevealing(true);
|
|
768
931
|
try {
|
|
769
932
|
const { values } = await coffre.secrets.reveal(`${project}/${environment}/${entry.key}`);
|
|
770
933
|
const value = values[entry.key];
|
|
771
934
|
setError(null);
|
|
772
|
-
setReveal({ value, version:
|
|
935
|
+
if (show) setReveal({ value, version: readVersion, at: Date.now() });
|
|
773
936
|
return value;
|
|
774
937
|
} catch (failure) {
|
|
775
938
|
setError(
|
|
@@ -788,6 +951,24 @@ function SecretRow({
|
|
|
788
951
|
else void readValue();
|
|
789
952
|
}
|
|
790
953
|
|
|
954
|
+
// An edit starts from the current value, read the way Reveal reads it, so
|
|
955
|
+
// the audit log shows who opened it. One that cannot be read starts empty.
|
|
956
|
+
const [opening, setOpening] = useState(false);
|
|
957
|
+
// Rename opens the same editor, its name field focused rather than its value.
|
|
958
|
+
const [focusName, setFocusName] = useState(false);
|
|
959
|
+
async function startEdit({ name = false } = {}) {
|
|
960
|
+
setFocusName(name);
|
|
961
|
+
if (canReveal) {
|
|
962
|
+
setOpening(true);
|
|
963
|
+
const value = await readValue({ show: false });
|
|
964
|
+
setOpening(false);
|
|
965
|
+
if (value === null) return;
|
|
966
|
+
setBase({ value, version: readVersion, at: Date.now() });
|
|
967
|
+
}
|
|
968
|
+
setReveal(null);
|
|
969
|
+
onEdit();
|
|
970
|
+
}
|
|
971
|
+
|
|
791
972
|
const leaving = change.archived;
|
|
792
973
|
const renamed = change.key !== entry.key;
|
|
793
974
|
const valueChanged = change.value !== null;
|
|
@@ -810,6 +991,7 @@ function SecretRow({
|
|
|
810
991
|
<div className="edit-stack">
|
|
811
992
|
<input
|
|
812
993
|
className="input input-mono"
|
|
994
|
+
autoFocus={focusName}
|
|
813
995
|
aria-label={`Name for ${entry.key}`}
|
|
814
996
|
aria-invalid={keyProblem !== null}
|
|
815
997
|
spellCheck={false}
|
|
@@ -834,67 +1016,131 @@ function SecretRow({
|
|
|
834
1016
|
) : (
|
|
835
1017
|
<div className="key-cell">
|
|
836
1018
|
<span>{breakAfterUnderscores(entry.key)}</span>
|
|
837
|
-
{leaving && <span className="tag tag-red">
|
|
1019
|
+
{leaving && <span className="tag tag-red">Will be archived</span>}
|
|
1020
|
+
{lent.length > 0 && (
|
|
1021
|
+
<button
|
|
1022
|
+
type="button"
|
|
1023
|
+
className="tag tag-button tag-violet"
|
|
1024
|
+
aria-expanded={lentOpen}
|
|
1025
|
+
onClick={() => setLentOpen((open) => !open)}
|
|
1026
|
+
>
|
|
1027
|
+
{lent.length} {lent.length === 1 ? 'reference' : 'references'}
|
|
1028
|
+
</button>
|
|
1029
|
+
)}
|
|
838
1030
|
</div>
|
|
839
1031
|
)}
|
|
840
1032
|
</td>
|
|
841
1033
|
|
|
842
1034
|
<td data-label="Value">
|
|
843
|
-
{
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
1035
|
+
{/* What acts on the value sits beside it: reading, Copy, Reveal and Edit;
|
|
1036
|
+
editing or marked for archiving, Save and Cancel, in the same place. */}
|
|
1037
|
+
<div className="value-cell">
|
|
1038
|
+
<div className="value-content">
|
|
1039
|
+
{editing && canWrite ? (
|
|
1040
|
+
<div className="edit-stack">
|
|
1041
|
+
<ValueField
|
|
1042
|
+
label={`New value for ${entry.key}`}
|
|
1043
|
+
value={change.value ?? editBase?.value ?? ''}
|
|
1044
|
+
start={editBase?.value}
|
|
1045
|
+
placeholder={canReveal ? 'Value' : 'New value; the current one is hidden from you'}
|
|
1046
|
+
disabled={disabled}
|
|
1047
|
+
autoFocus={!focusName}
|
|
1048
|
+
onChange={(value) =>
|
|
1049
|
+
onPatch({ value: value === (editBase?.value ?? '') ? null : value })
|
|
1050
|
+
}
|
|
1051
|
+
onEscape={onUndo}
|
|
1052
|
+
/>
|
|
1053
|
+
{reference !== null && reference.state === 'live' && (
|
|
1054
|
+
<span className="edit-note">
|
|
1055
|
+
Saving a value stops following <span className="mono">{reference.source}</span>
|
|
1056
|
+
</span>
|
|
1057
|
+
)}
|
|
1058
|
+
</div>
|
|
1059
|
+
) : shown !== null && !leaving ? (
|
|
1060
|
+
<div
|
|
1061
|
+
className="revealed"
|
|
1062
|
+
style={{ ['--reveal-ttl' as string]: `${REVEAL_TTL_SECONDS}s` }}
|
|
1063
|
+
>
|
|
1064
|
+
<span className="revealed-value">{shown.value === '' ? '(empty)' : shown.value}</span>
|
|
1065
|
+
<span className="revealed-note">
|
|
1066
|
+
Hides in {secondsLeft}s
|
|
1067
|
+
</span>
|
|
1068
|
+
<span className="revealed-meter" aria-hidden />
|
|
1069
|
+
</div>
|
|
1070
|
+
) : reference !== null ? (
|
|
1071
|
+
<ReferenceValue reference={reference} />
|
|
1072
|
+
) : (
|
|
1073
|
+
<span className="mask" aria-label="Hidden">
|
|
1074
|
+
••••••••••••
|
|
863
1075
|
</span>
|
|
864
|
-
|
|
865
|
-
<button
|
|
866
|
-
type="button"
|
|
867
|
-
className="act"
|
|
868
|
-
disabled={revealing}
|
|
869
|
-
onClick={async () => {
|
|
870
|
-
const value = await readValue();
|
|
871
|
-
if (value !== null) {
|
|
872
|
-
setBase({ value, version: entry.version, at: Date.now() });
|
|
873
|
-
}
|
|
874
|
-
}}
|
|
875
|
-
>
|
|
876
|
-
{revealing && <Spinner size={12} />}
|
|
877
|
-
Start from current value
|
|
878
|
-
</button>
|
|
879
|
-
)}
|
|
880
|
-
</span>
|
|
881
|
-
</div>
|
|
882
|
-
) : shown !== null && !leaving ? (
|
|
883
|
-
<div
|
|
884
|
-
className="revealed"
|
|
885
|
-
style={{ ['--reveal-ttl' as string]: `${REVEAL_TTL_SECONDS}s` }}
|
|
886
|
-
>
|
|
887
|
-
<span className="revealed-value">{shown.value === '' ? '(empty)' : shown.value}</span>
|
|
888
|
-
<span className="revealed-note">
|
|
889
|
-
Hides in {secondsLeft}s
|
|
890
|
-
</span>
|
|
891
|
-
<span className="revealed-meter" aria-hidden />
|
|
1076
|
+
)}
|
|
892
1077
|
</div>
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
1078
|
+
{status.state !== 'pending' && (
|
|
1079
|
+
<div className="acts value-acts">
|
|
1080
|
+
{editing || leaving ? (
|
|
1081
|
+
<>
|
|
1082
|
+
<Tip label={leaving ? 'Archive now' : 'Save'}>
|
|
1083
|
+
<button
|
|
1084
|
+
className="act act-icon act-accent"
|
|
1085
|
+
onClick={onSave}
|
|
1086
|
+
disabled={disabled || !saveReady}
|
|
1087
|
+
aria-label={`${leaving ? 'Archive' : 'Save'} ${entry.key} now`}
|
|
1088
|
+
>
|
|
1089
|
+
<Check size={15} />
|
|
1090
|
+
</button>
|
|
1091
|
+
</Tip>
|
|
1092
|
+
<Tip label={leaving ? 'Keep' : 'Cancel'}>
|
|
1093
|
+
<button
|
|
1094
|
+
className="act act-icon act-quiet"
|
|
1095
|
+
onClick={onUndo}
|
|
1096
|
+
disabled={disabled}
|
|
1097
|
+
aria-label={leaving ? `Keep ${entry.key}` : `Cancel editing ${entry.key}`}
|
|
1098
|
+
>
|
|
1099
|
+
<X size={15} />
|
|
1100
|
+
</button>
|
|
1101
|
+
</Tip>
|
|
1102
|
+
</>
|
|
1103
|
+
) : (
|
|
1104
|
+
<>
|
|
1105
|
+
{/* Copy comes in to the left, so Hide stays where Reveal was clicked. */}
|
|
1106
|
+
{shown !== null && (
|
|
1107
|
+
<CopyButton variant="act" value={shown.value} label={`Copy ${entry.key}`} />
|
|
1108
|
+
)}
|
|
1109
|
+
<SecretReadOnly canReveal={canReveal}>
|
|
1110
|
+
<Tip label={shown === null ? 'Reveal' : 'Hide'}>
|
|
1111
|
+
<button
|
|
1112
|
+
className="act act-icon act-accent"
|
|
1113
|
+
onClick={toggleReveal}
|
|
1114
|
+
disabled={revealing}
|
|
1115
|
+
aria-label={`${shown === null ? 'Reveal' : 'Hide'} ${entry.key}`}
|
|
1116
|
+
>
|
|
1117
|
+
{revealing && !opening ? (
|
|
1118
|
+
<Spinner size={13} />
|
|
1119
|
+
) : shown === null ? (
|
|
1120
|
+
<Eye size={15} />
|
|
1121
|
+
) : (
|
|
1122
|
+
<EyeOff size={15} />
|
|
1123
|
+
)}
|
|
1124
|
+
</button>
|
|
1125
|
+
</Tip>
|
|
1126
|
+
</SecretReadOnly>
|
|
1127
|
+
{canWrite && (
|
|
1128
|
+
<Tip label="Edit">
|
|
1129
|
+
<button
|
|
1130
|
+
className="act act-icon"
|
|
1131
|
+
onClick={() => void startEdit()}
|
|
1132
|
+
disabled={disabled || revealing}
|
|
1133
|
+
aria-label={`Edit ${entry.key}`}
|
|
1134
|
+
>
|
|
1135
|
+
{opening ? <Spinner size={13} /> : <Pencil size={14} />}
|
|
1136
|
+
</button>
|
|
1137
|
+
</Tip>
|
|
1138
|
+
)}
|
|
1139
|
+
</>
|
|
1140
|
+
)}
|
|
1141
|
+
</div>
|
|
1142
|
+
)}
|
|
1143
|
+
</div>
|
|
898
1144
|
</td>
|
|
899
1145
|
|
|
900
1146
|
<td className="col-version" data-label="Version">
|
|
@@ -903,129 +1149,152 @@ function SecretRow({
|
|
|
903
1149
|
v{version} → <b>v{version + 1}</b>
|
|
904
1150
|
</span>
|
|
905
1151
|
) : (
|
|
906
|
-
<span className="version-shift"
|
|
1152
|
+
<span className="version-shift" title={reference === null ? undefined : "The source's version"}>
|
|
1153
|
+
{readVersion === null ? '—' : `v${readVersion}`}
|
|
1154
|
+
</span>
|
|
907
1155
|
)}
|
|
908
1156
|
</td>
|
|
909
1157
|
|
|
910
1158
|
<td className="col-written col-hide-narrow" data-label="Last written">
|
|
911
|
-
<Written entry={entry} />
|
|
1159
|
+
<Written entry={reference === null ? entry : { ...entry, updatedBy: reference.createdBy.replace(/^user:/, ''), updatedAt: reference.createdAt }} />
|
|
912
1160
|
</td>
|
|
913
1161
|
|
|
914
1162
|
<td className="col-actions">
|
|
915
1163
|
{status.state === 'pending' ? (
|
|
916
1164
|
<RowPending status={status} />
|
|
917
1165
|
) : (
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
<
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
</button>
|
|
929
|
-
</Tip>
|
|
930
|
-
) : editing ? (
|
|
931
|
-
<Tip label={renamed || valueChanged ? 'Undo changes' : 'Cancel'}>
|
|
932
|
-
<button
|
|
933
|
-
className="act act-icon act-quiet"
|
|
934
|
-
onClick={onUndo}
|
|
935
|
-
disabled={disabled}
|
|
936
|
-
aria-label={`${renamed || valueChanged ? 'Undo changes to' : 'Stop editing'} ${entry.key}`}
|
|
937
|
-
>
|
|
938
|
-
{renamed || valueChanged ? <RotateBack size={14} /> : <X size={15} />}
|
|
939
|
-
</button>
|
|
940
|
-
</Tip>
|
|
941
|
-
) : (
|
|
942
|
-
<>
|
|
943
|
-
{/* Copy comes in to the left, so Hide stays where Reveal was clicked. */}
|
|
944
|
-
{shown !== null && (
|
|
945
|
-
<CopyButton variant="act" value={shown.value} label={`Copy ${entry.key}`} />
|
|
946
|
-
)}
|
|
1166
|
+
(canReveal || (canWrite && !editing && !leaving) || (canArchive && !leaving)) && (
|
|
1167
|
+
<Menu.Root>
|
|
1168
|
+
<Menu.Trigger
|
|
1169
|
+
className="act act-icon act-quiet"
|
|
1170
|
+
aria-label={`More for ${entry.key}`}
|
|
1171
|
+
disabled={disabled}
|
|
1172
|
+
>
|
|
1173
|
+
<MoreHorizontal size={16} />
|
|
1174
|
+
</Menu.Trigger>
|
|
1175
|
+
<MenuPopup align="end">
|
|
947
1176
|
<SecretReadOnly canReveal={canReveal}>
|
|
948
|
-
<
|
|
949
|
-
<
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
disabled={revealing}
|
|
953
|
-
aria-label={`${shown === null ? 'Reveal' : 'Hide'} ${entry.key}`}
|
|
954
|
-
>
|
|
955
|
-
{revealing ? (
|
|
956
|
-
<Spinner size={13} />
|
|
957
|
-
) : shown === null ? (
|
|
958
|
-
<Eye size={15} />
|
|
959
|
-
) : (
|
|
960
|
-
<EyeOff size={15} />
|
|
961
|
-
)}
|
|
962
|
-
</button>
|
|
963
|
-
</Tip>
|
|
1177
|
+
<Menu.Item className="menu-item" onClick={() => setHistoryOpen((open) => !open)}>
|
|
1178
|
+
<History size={14} />
|
|
1179
|
+
{historyOpen ? 'Hide history' : 'Version history'}
|
|
1180
|
+
</Menu.Item>
|
|
964
1181
|
</SecretReadOnly>
|
|
965
|
-
{canWrite && (
|
|
966
|
-
<
|
|
967
|
-
<
|
|
968
|
-
|
|
1182
|
+
{canWrite && !editing && !leaving && (
|
|
1183
|
+
<Menu.Item className="menu-item" onClick={() => void startEdit({ name: true })}>
|
|
1184
|
+
<Pencil size={14} />
|
|
1185
|
+
Rename
|
|
1186
|
+
</Menu.Item>
|
|
1187
|
+
)}
|
|
1188
|
+
{canWrite && !editing && !leaving && (
|
|
1189
|
+
<Menu.Item className="menu-item" onClick={() => setMoving(true)}>
|
|
1190
|
+
<Folder size={14} />
|
|
1191
|
+
Move to folder…
|
|
1192
|
+
</Menu.Item>
|
|
1193
|
+
)}
|
|
1194
|
+
{canWrite && !editing && !leaving && (
|
|
1195
|
+
<Menu.Item className="menu-item" onClick={() => setReferring(true)}>
|
|
1196
|
+
<ArrowRight size={14} />
|
|
1197
|
+
{reference === null ? 'Make a reference…' : 'Point elsewhere…'}
|
|
1198
|
+
</Menu.Item>
|
|
1199
|
+
)}
|
|
1200
|
+
{canWrite && !editing && !leaving && reference !== null && reference.state === 'live' && (
|
|
1201
|
+
<Menu.Item className="menu-item" onClick={() => setBreaking(holderPath)}>
|
|
1202
|
+
<SlashCircle size={14} />
|
|
1203
|
+
Break reference…
|
|
1204
|
+
</Menu.Item>
|
|
1205
|
+
)}
|
|
1206
|
+
{canArchive && !leaving && (
|
|
1207
|
+
<>
|
|
1208
|
+
{(canReveal || canWrite) && <Menu.Separator className="menu-sep" />}
|
|
1209
|
+
<Menu.Item
|
|
1210
|
+
className="menu-item menu-item-danger"
|
|
969
1211
|
onClick={() => {
|
|
970
|
-
// A value already revealed is already on the record, so
|
|
971
|
-
// it becomes the starting point instead of being thrown
|
|
972
|
-
// away and read again.
|
|
973
|
-
if (shown !== null) setBase(shown);
|
|
974
1212
|
setReveal(null);
|
|
975
|
-
|
|
1213
|
+
if (blockers.length > 0) setArchiveBlocked(true);
|
|
1214
|
+
else onMarkArchive();
|
|
976
1215
|
}}
|
|
977
|
-
disabled={disabled}
|
|
978
|
-
aria-label={`Edit ${entry.key}`}
|
|
979
|
-
>
|
|
980
|
-
<Pencil size={14} />
|
|
981
|
-
</button>
|
|
982
|
-
</Tip>
|
|
983
|
-
)}
|
|
984
|
-
{(canReveal || canArchive) && (
|
|
985
|
-
<Menu.Root>
|
|
986
|
-
<Menu.Trigger
|
|
987
|
-
className="act act-icon act-quiet"
|
|
988
|
-
aria-label={`More for ${entry.key}`}
|
|
989
|
-
disabled={disabled}
|
|
990
1216
|
>
|
|
991
|
-
<
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
className="menu-item"
|
|
997
|
-
onClick={() => setHistoryOpen((open) => !open)}
|
|
998
|
-
>
|
|
999
|
-
<History size={14} />
|
|
1000
|
-
{historyOpen ? 'Hide history' : 'Version history'}
|
|
1001
|
-
</Menu.Item>
|
|
1002
|
-
</SecretReadOnly>
|
|
1003
|
-
{canArchive && (
|
|
1004
|
-
<>
|
|
1005
|
-
{canReveal && <Menu.Separator className="menu-sep" />}
|
|
1006
|
-
<Menu.Item
|
|
1007
|
-
className="menu-item menu-item-danger"
|
|
1008
|
-
onClick={() => {
|
|
1009
|
-
setReveal(null);
|
|
1010
|
-
onMarkArchive();
|
|
1011
|
-
}}
|
|
1012
|
-
>
|
|
1013
|
-
<Archive size={14} />
|
|
1014
|
-
Archive
|
|
1015
|
-
<span className="menu-hint">on save</span>
|
|
1016
|
-
</Menu.Item>
|
|
1017
|
-
</>
|
|
1018
|
-
)}
|
|
1019
|
-
</MenuPopup>
|
|
1020
|
-
</Menu.Root>
|
|
1217
|
+
<Archive size={14} />
|
|
1218
|
+
Archive
|
|
1219
|
+
<span className="menu-hint">on save</span>
|
|
1220
|
+
</Menu.Item>
|
|
1221
|
+
</>
|
|
1021
1222
|
)}
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1223
|
+
</MenuPopup>
|
|
1224
|
+
</Menu.Root>
|
|
1225
|
+
)
|
|
1025
1226
|
)}
|
|
1026
1227
|
</td>
|
|
1027
1228
|
</tr>
|
|
1028
1229
|
|
|
1230
|
+
{canWrite && (
|
|
1231
|
+
<MakeReference
|
|
1232
|
+
open={referring}
|
|
1233
|
+
onOpenChange={setReferring}
|
|
1234
|
+
holder={holderPath}
|
|
1235
|
+
environments={environments}
|
|
1236
|
+
onMake={(source) =>
|
|
1237
|
+
act(() => coffre.secrets.set(`${project}/${environment}`, { [entry.key]: { ref: source } }), {
|
|
1238
|
+
affects: affects.secrets({ project, environment }),
|
|
1239
|
+
onSuccess: () => toast.success(`${entry.key} reads ${source}`),
|
|
1240
|
+
})
|
|
1241
|
+
}
|
|
1242
|
+
/>
|
|
1243
|
+
)}
|
|
1244
|
+
|
|
1245
|
+
<ConfirmDialog
|
|
1246
|
+
open={archiveBlocked}
|
|
1247
|
+
onOpenChange={setArchiveBlocked}
|
|
1248
|
+
title={
|
|
1249
|
+
<>
|
|
1250
|
+
Archive <span className="mono">{entry.key}</span>?
|
|
1251
|
+
</>
|
|
1252
|
+
}
|
|
1253
|
+
body={`It is marked to archive when you save: ${project}/${environment} stops serving it, and its versions stay.`}
|
|
1254
|
+
detail={<ArchiveBlocked references={blockers} />}
|
|
1255
|
+
confirmLabel="Archive on save"
|
|
1256
|
+
confirmDisabled={blockers.length > 0}
|
|
1257
|
+
onConfirm={onMarkArchive}
|
|
1258
|
+
/>
|
|
1259
|
+
|
|
1260
|
+
<ConfirmDialog
|
|
1261
|
+
open={breaking !== null}
|
|
1262
|
+
onOpenChange={(open) => !open && setBreaking(null)}
|
|
1263
|
+
title="Break this reference?"
|
|
1264
|
+
body={
|
|
1265
|
+
breaking === holderPath
|
|
1266
|
+
? `Whoever reads ${project}/${environment} stops reading ${reference?.source ?? 'its source'} through ${entry.key}, and a run of ${project}/${environment} refuses until ${entry.key} gets a value.`
|
|
1267
|
+
: `Whoever reads ${breaking ?? ''}'s environment stops reading ${project}/${environment}/${entry.key} through it, and a run there refuses until it gets a value.`
|
|
1268
|
+
}
|
|
1269
|
+
confirmLabel="Break"
|
|
1270
|
+
onConfirm={() => {
|
|
1271
|
+
const path = breaking!;
|
|
1272
|
+
act(() => coffre.references.break(path), {
|
|
1273
|
+
affects: affects.secrets({ project, environment }),
|
|
1274
|
+
onSuccess: () => toast.success(`Broke ${path}`),
|
|
1275
|
+
});
|
|
1276
|
+
}}
|
|
1277
|
+
/>
|
|
1278
|
+
|
|
1279
|
+
{lentOpen && lent.length > 0 && (
|
|
1280
|
+
<tr className="detail-row">
|
|
1281
|
+
<td colSpan={columns}>
|
|
1282
|
+
<LentReferences references={lent} onBreak={(each) => setBreaking(each.holder)} />
|
|
1283
|
+
</td>
|
|
1284
|
+
</tr>
|
|
1285
|
+
)}
|
|
1286
|
+
|
|
1287
|
+
{canWrite && (
|
|
1288
|
+
<MoveToFolder
|
|
1289
|
+
open={moving}
|
|
1290
|
+
onOpenChange={setMoving}
|
|
1291
|
+
what={entry.key}
|
|
1292
|
+
current={entry.folder}
|
|
1293
|
+
folders={folders}
|
|
1294
|
+
onMove={onMove}
|
|
1295
|
+
/>
|
|
1296
|
+
)}
|
|
1297
|
+
|
|
1029
1298
|
{historyOpen && canReveal && (
|
|
1030
1299
|
<tr className="detail-row">
|
|
1031
1300
|
<td colSpan={columns}>
|
|
@@ -1042,10 +1311,10 @@ function SecretRow({
|
|
|
1042
1311
|
</tr>
|
|
1043
1312
|
)}
|
|
1044
1313
|
|
|
1045
|
-
{error !== null && (
|
|
1314
|
+
{(error ?? actError) !== null && (
|
|
1046
1315
|
<tr className="row-error">
|
|
1047
1316
|
<td colSpan={columns}>
|
|
1048
|
-
<ErrorLine error={error} />
|
|
1317
|
+
<ErrorLine error={(error ?? actError)!} />
|
|
1049
1318
|
</td>
|
|
1050
1319
|
</tr>
|
|
1051
1320
|
)}
|
|
@@ -1095,12 +1364,17 @@ function DraftRow({
|
|
|
1095
1364
|
disabled,
|
|
1096
1365
|
onChange,
|
|
1097
1366
|
onRemove,
|
|
1367
|
+
onSave,
|
|
1368
|
+
saveReady,
|
|
1098
1369
|
}: {
|
|
1099
1370
|
draft: SecretDraft;
|
|
1100
1371
|
existingVersion: number | null;
|
|
1101
1372
|
disabled: boolean;
|
|
1102
1373
|
onChange: (patch: Partial<SecretDraft>) => void;
|
|
1103
1374
|
onRemove: () => void;
|
|
1375
|
+
/** This new secret alone, saved now. */
|
|
1376
|
+
onSave: () => void;
|
|
1377
|
+
saveReady: boolean;
|
|
1104
1378
|
}) {
|
|
1105
1379
|
const [touched, setTouched] = useState(false);
|
|
1106
1380
|
const trimmed = draft.key.trim();
|
|
@@ -1141,15 +1415,41 @@ function DraftRow({
|
|
|
1141
1415
|
</div>
|
|
1142
1416
|
</td>
|
|
1143
1417
|
<td data-label="Value">
|
|
1144
|
-
<div className="
|
|
1145
|
-
<
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1418
|
+
<div className="value-cell">
|
|
1419
|
+
<div className="value-content">
|
|
1420
|
+
<div className="edit-stack">
|
|
1421
|
+
<ValueField
|
|
1422
|
+
label={`Value for ${trimmed === '' ? 'the new secret' : trimmed}`}
|
|
1423
|
+
value={draft.value}
|
|
1424
|
+
placeholder="Value"
|
|
1425
|
+
disabled={disabled}
|
|
1426
|
+
onChange={(value) => onChange({ value })}
|
|
1427
|
+
onEscape={onRemove}
|
|
1428
|
+
/>
|
|
1429
|
+
</div>
|
|
1430
|
+
</div>
|
|
1431
|
+
<div className="acts value-acts">
|
|
1432
|
+
<Tip label="Save">
|
|
1433
|
+
<button
|
|
1434
|
+
className="act act-icon act-accent"
|
|
1435
|
+
onClick={onSave}
|
|
1436
|
+
disabled={disabled || !saveReady}
|
|
1437
|
+
aria-label={trimmed === '' ? 'Save this new secret now' : `Save ${trimmed} now`}
|
|
1438
|
+
>
|
|
1439
|
+
<Check size={15} />
|
|
1440
|
+
</button>
|
|
1441
|
+
</Tip>
|
|
1442
|
+
<Tip label="Cancel">
|
|
1443
|
+
<button
|
|
1444
|
+
className="act act-icon act-quiet"
|
|
1445
|
+
onClick={onRemove}
|
|
1446
|
+
disabled={disabled}
|
|
1447
|
+
aria-label={trimmed === '' ? 'Remove this new secret' : `Remove new secret ${trimmed}`}
|
|
1448
|
+
>
|
|
1449
|
+
<X size={15} />
|
|
1450
|
+
</button>
|
|
1451
|
+
</Tip>
|
|
1452
|
+
</div>
|
|
1153
1453
|
</div>
|
|
1154
1454
|
</td>
|
|
1155
1455
|
<td className="col-version" data-label="Version">
|
|
@@ -1166,20 +1466,7 @@ function DraftRow({
|
|
|
1166
1466
|
<td className="col-written col-hide-narrow">
|
|
1167
1467
|
<span className="cell-muted">—</span>
|
|
1168
1468
|
</td>
|
|
1169
|
-
<td className="col-actions"
|
|
1170
|
-
<div className="acts">
|
|
1171
|
-
<Tip label="Remove">
|
|
1172
|
-
<button
|
|
1173
|
-
className="act act-icon act-quiet"
|
|
1174
|
-
onClick={onRemove}
|
|
1175
|
-
disabled={disabled}
|
|
1176
|
-
aria-label={trimmed === '' ? 'Remove this new secret' : `Remove new secret ${trimmed}`}
|
|
1177
|
-
>
|
|
1178
|
-
<X size={15} />
|
|
1179
|
-
</button>
|
|
1180
|
-
</Tip>
|
|
1181
|
-
</div>
|
|
1182
|
-
</td>
|
|
1469
|
+
<td className="col-actions" />
|
|
1183
1470
|
</tr>
|
|
1184
1471
|
);
|
|
1185
1472
|
}
|
|
@@ -1221,30 +1508,42 @@ function ArchivedRow({
|
|
|
1221
1508
|
<Written entry={entry} />
|
|
1222
1509
|
</td>
|
|
1223
1510
|
<td className="col-actions">
|
|
1224
|
-
|
|
1225
|
-
<
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1511
|
+
{state.state === 'pending' ? (
|
|
1512
|
+
<RowPending status={state} />
|
|
1513
|
+
) : (
|
|
1514
|
+
(canReveal || canArchive) && (
|
|
1515
|
+
<div className="acts">
|
|
1516
|
+
<Menu.Root>
|
|
1517
|
+
<Menu.Trigger
|
|
1518
|
+
className="act act-icon act-quiet"
|
|
1519
|
+
aria-label={`More for ${entry.key}`}
|
|
1520
|
+
>
|
|
1521
|
+
<MoreHorizontal size={16} />
|
|
1522
|
+
</Menu.Trigger>
|
|
1523
|
+
<MenuPopup align="end">
|
|
1524
|
+
<SecretReadOnly canReveal={canReveal}>
|
|
1525
|
+
<Menu.Item
|
|
1526
|
+
className="menu-item"
|
|
1527
|
+
onClick={() => setHistoryOpen((open) => !open)}
|
|
1528
|
+
>
|
|
1529
|
+
<History size={14} />
|
|
1530
|
+
{historyOpen ? 'Hide history' : 'Version history'}
|
|
1531
|
+
</Menu.Item>
|
|
1532
|
+
</SecretReadOnly>
|
|
1533
|
+
{canArchive && (
|
|
1534
|
+
<>
|
|
1535
|
+
{canReveal && <Menu.Separator className="menu-sep" />}
|
|
1536
|
+
<Menu.Item className="menu-item" onClick={onRestore}>
|
|
1537
|
+
<RotateBack size={14} />
|
|
1538
|
+
Restore
|
|
1539
|
+
</Menu.Item>
|
|
1540
|
+
</>
|
|
1541
|
+
)}
|
|
1542
|
+
</MenuPopup>
|
|
1543
|
+
</Menu.Root>
|
|
1544
|
+
</div>
|
|
1545
|
+
)
|
|
1546
|
+
)}
|
|
1248
1547
|
</td>
|
|
1249
1548
|
</tr>
|
|
1250
1549
|
{historyOpen && (
|
|
@@ -1360,7 +1659,7 @@ function VersionHistory({
|
|
|
1360
1659
|
<tr key={version.version}>
|
|
1361
1660
|
<td className="cell-mono nowrap">
|
|
1362
1661
|
v{version.version}{' '}
|
|
1363
|
-
{version.current && <span className="tag tag-blue">
|
|
1662
|
+
{version.current && <span className="tag tag-blue">Current</span>}
|
|
1364
1663
|
</td>
|
|
1365
1664
|
<td className="nowrap">
|
|
1366
1665
|
<Timestamp iso={version.createdAt} />
|