@coffre/ui 0.3.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} +112 -54
- 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 +112 -93
- 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
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
|
|
3
|
+
import { Link } from '@tanstack/react-router';
|
|
4
|
+
import { useShell } from '../lib/use-shell';
|
|
5
|
+
import { Menu } from '@base-ui/react/menu';
|
|
6
|
+
import { toast } from 'sonner';
|
|
7
|
+
import { useCoffre } from '../lib/coffre';
|
|
8
|
+
import { archiveEnvironment, createEnvironment, environmentId, renameEnvironment } from '../lib/changes';
|
|
9
|
+
import { keys, queries } from '../lib/queries';
|
|
10
|
+
import { useChange, useChangeStatus } from '../lib/use-change';
|
|
11
|
+
import { ItemFailure, RowPending, rowClass } from '../components/row-state';
|
|
12
|
+
import type { GrantRow, ProjectSummary } from '../shared/models';
|
|
13
|
+
import { ArchiveBlocked, archiveBlockers } from '../components/references';
|
|
14
|
+
import { hasEnvironmentDetails, isActiveAccessibleEnvironment, type ProjectEnvironment } from '../lib/project-environments';
|
|
15
|
+
import { environmentSlugProblem } from '../lib/validation';
|
|
16
|
+
import { ConfirmDialog, EmptyState, MenuPopup, Modal, Timestamp } from '../components/ui';
|
|
17
|
+
import { DeletePlaceDialog } from '../components/delete-place';
|
|
18
|
+
import { PrincipalAvatar } from '../components/principal';
|
|
19
|
+
import { ReachedBy, reaching, useEveryProject } from '../components/every-project';
|
|
20
|
+
import { Archive, ChevronRight, MoreHorizontal, Pencil, Plus, RotateBack, Trash } from '../components/icons';
|
|
21
|
+
import { pageRoute } from '../lib/page-route';
|
|
22
|
+
import { useProject } from '../lib/project-page';
|
|
23
|
+
import type { projectEnvironments } from '../options';
|
|
24
|
+
|
|
25
|
+
const Route = pageRoute<typeof projectEnvironments>();
|
|
26
|
+
|
|
27
|
+
/** A project's first tab: its environments, each opening its secrets. */
|
|
28
|
+
export function ProjectEnvironmentsPage() {
|
|
29
|
+
const { project, managesAccess } = useProject(Route.useParams().project);
|
|
30
|
+
const canManage = project.permissions.includes('environment.manage');
|
|
31
|
+
return managesAccess ? (
|
|
32
|
+
<ManagedEnvironments project={project} canManage={canManage} />
|
|
33
|
+
) : (
|
|
34
|
+
<EnvironmentsPanel project={project} canManage={canManage} grants={[]} />
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The environments of a project whose access you manage, each with who can open it. */
|
|
39
|
+
function ManagedEnvironments({ project, canManage }: { project: ProjectSummary; canManage: boolean }) {
|
|
40
|
+
const { data: result } = useSuspenseQuery(queries.grants(useCoffre(), project.slug));
|
|
41
|
+
return <EnvironmentsPanel project={project} canManage={canManage} grants={result.ok ? result.grants : []} />;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function EnvironmentsPanel({
|
|
45
|
+
project,
|
|
46
|
+
canManage,
|
|
47
|
+
grants,
|
|
48
|
+
}: {
|
|
49
|
+
project: ProjectSummary;
|
|
50
|
+
canManage: boolean;
|
|
51
|
+
/** The project's grants, when you manage its access: who can open each environment. */
|
|
52
|
+
grants: GrantRow[];
|
|
53
|
+
}) {
|
|
54
|
+
const detailed = project.environments.filter(hasEnvironmentDetails);
|
|
55
|
+
const archived = detailed.filter((environment) => environment.details.archivedAt !== null);
|
|
56
|
+
// Environments you may know by name only sit with the active ones: no grant
|
|
57
|
+
// you hold covers their contents, so they are muted and do not open.
|
|
58
|
+
const current = project.environments.filter(
|
|
59
|
+
(environment) => environment.details === null || environment.details.archivedAt === null,
|
|
60
|
+
);
|
|
61
|
+
const { failedAdds, dismiss } = useChangeStatus(keys.projects);
|
|
62
|
+
const refused = failedAdds<{ slug: string; name: string }>(
|
|
63
|
+
project.environments.map((environment) => environmentId(project.slug, environment.slug)),
|
|
64
|
+
).filter(({ ids }) => ids.every((id) => id.startsWith(`${project.slug}/`)));
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<>
|
|
68
|
+
{current.length === 0 && refused.length === 0 ? (
|
|
69
|
+
<div className="card">
|
|
70
|
+
<EmptyState title="No environments yet">
|
|
71
|
+
{canManage
|
|
72
|
+
? 'Add the first with Add environment.'
|
|
73
|
+
: 'Creating environments needs environment.manage on this project.'}
|
|
74
|
+
</EmptyState>
|
|
75
|
+
</div>
|
|
76
|
+
) : (
|
|
77
|
+
<ul className="env-grid" aria-label="Environments">
|
|
78
|
+
{current.map((environment) => (
|
|
79
|
+
<li key={`${project.slug}:${environment.slug}`}>
|
|
80
|
+
<EnvironmentCard
|
|
81
|
+
project={project.slug}
|
|
82
|
+
environment={environment}
|
|
83
|
+
isAdmin={canManage}
|
|
84
|
+
grants={grants}
|
|
85
|
+
/>
|
|
86
|
+
</li>
|
|
87
|
+
))}
|
|
88
|
+
{refused.map(({ mutationId, vars, status }) => (
|
|
89
|
+
<li key={mutationId}>
|
|
90
|
+
<div className="env-card is-muted is-failed">
|
|
91
|
+
<div className="env-card-text">
|
|
92
|
+
<span className="env-card-name">{vars.name}</span>
|
|
93
|
+
<span className="env-card-meta">
|
|
94
|
+
<span className="mono">{vars.slug}</span>
|
|
95
|
+
</span>
|
|
96
|
+
</div>
|
|
97
|
+
<ItemFailure status={status} onDismiss={() => dismiss(mutationId)}>
|
|
98
|
+
Not added.
|
|
99
|
+
</ItemFailure>
|
|
100
|
+
</div>
|
|
101
|
+
</li>
|
|
102
|
+
))}
|
|
103
|
+
</ul>
|
|
104
|
+
)}
|
|
105
|
+
|
|
106
|
+
{canManage && (
|
|
107
|
+
<div className="table-actions">
|
|
108
|
+
<NewEnvironment
|
|
109
|
+
project={project.slug}
|
|
110
|
+
sources={current.filter(isActiveAccessibleEnvironment).map((environment) => environment.slug)}
|
|
111
|
+
/>
|
|
112
|
+
</div>
|
|
113
|
+
)}
|
|
114
|
+
|
|
115
|
+
{archived.length > 0 && (
|
|
116
|
+
<section aria-labelledby="archived-environments">
|
|
117
|
+
<h2 className="section-title" id="archived-environments">
|
|
118
|
+
Archived
|
|
119
|
+
</h2>
|
|
120
|
+
<ul className="env-grid">
|
|
121
|
+
{archived.map((environment) => (
|
|
122
|
+
<li key={environment.slug}>
|
|
123
|
+
<EnvironmentCard
|
|
124
|
+
project={project.slug}
|
|
125
|
+
environment={environment}
|
|
126
|
+
isAdmin={canManage}
|
|
127
|
+
grants={grants}
|
|
128
|
+
/>
|
|
129
|
+
</li>
|
|
130
|
+
))}
|
|
131
|
+
</ul>
|
|
132
|
+
</section>
|
|
133
|
+
)}
|
|
134
|
+
</>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* One environment. The whole card opens it when you can; its menu sits above
|
|
140
|
+
* that link.
|
|
141
|
+
*/
|
|
142
|
+
/** Who can open an environment: a grant on it, or on the whole project. */
|
|
143
|
+
function holdersOf(grants: GrantRow[], environment: string) {
|
|
144
|
+
const seen = new Set<string>();
|
|
145
|
+
return grants.filter((grant) => {
|
|
146
|
+
const id = `${grant.principalType}:${grant.principalId}`;
|
|
147
|
+
if ((grant.environmentSlug !== null && grant.environmentSlug !== environment) || seen.has(id)) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
seen.add(id);
|
|
151
|
+
return true;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** The newest change among an environment's secrets, read when its card shows. */
|
|
156
|
+
function useLastChange(project: string, environment: string, enabled: boolean) {
|
|
157
|
+
const { data } = useQuery({ ...queries.secrets(useCoffre(), { project, environment }), enabled });
|
|
158
|
+
if (data === undefined || !data.ok) return null;
|
|
159
|
+
let last: { at: string; by: string | null } | null = null;
|
|
160
|
+
for (const key of data.keys) {
|
|
161
|
+
if (!key.archived && key.updatedAt !== null && (last === null || key.updatedAt > last.at)) {
|
|
162
|
+
last = { at: key.updatedAt, by: key.updatedBy };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return last;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const SHOWN_HOLDERS = 4;
|
|
169
|
+
|
|
170
|
+
function EnvironmentCard({
|
|
171
|
+
project,
|
|
172
|
+
environment,
|
|
173
|
+
isAdmin,
|
|
174
|
+
grants,
|
|
175
|
+
}: {
|
|
176
|
+
project: string;
|
|
177
|
+
environment: ProjectEnvironment;
|
|
178
|
+
isAdmin: boolean;
|
|
179
|
+
grants: GrantRow[];
|
|
180
|
+
}) {
|
|
181
|
+
const [renaming, setRenaming] = useState(false);
|
|
182
|
+
const [confirming, setConfirming] = useState(false);
|
|
183
|
+
const [deleting, setDeleting] = useState(false);
|
|
184
|
+
const { instanceRole } = useShell();
|
|
185
|
+
const [slug, setSlug] = useState(environment.slug);
|
|
186
|
+
const [name, setName] = useState(environment.name);
|
|
187
|
+
const coffre = useCoffre();
|
|
188
|
+
const rename = useChange(renameEnvironment(coffre, project));
|
|
189
|
+
const archive = useChange(archiveEnvironment(coffre, project));
|
|
190
|
+
// What archiving it would stop, asked once the dialog opens (D41); Archive waits for the answer.
|
|
191
|
+
const place = `${project}/${environment.slug}`;
|
|
192
|
+
const archiving = confirming && environment.details?.archivedAt == null;
|
|
193
|
+
const { data: lent } = useQuery({ ...queries.references(coffre, place), enabled: archiving });
|
|
194
|
+
const blockers = archiving && lent?.ok === true ? archiveBlockers(place, lent.references) : [];
|
|
195
|
+
const asking = archiving && lent === undefined;
|
|
196
|
+
const everyProject = useEveryProject();
|
|
197
|
+
const { status, dismiss } = useChangeStatus(keys.projects);
|
|
198
|
+
const state = status(environmentId(project, environment.slug));
|
|
199
|
+
const pending = state.state === 'pending';
|
|
200
|
+
const details = environment.details;
|
|
201
|
+
const isArchived = details !== null && details.archivedAt !== null;
|
|
202
|
+
const secretCount = details?.secretCount ?? null;
|
|
203
|
+
const opens = details !== null && !isArchived && environment.accessible && !pending;
|
|
204
|
+
const manageable = isAdmin && details !== null;
|
|
205
|
+
// Deleting is for instance owners, and only once the environment is archived.
|
|
206
|
+
const deletable = manageable && isArchived && instanceRole !== 'user';
|
|
207
|
+
const slugError = slug === '' ? null : environmentSlugProblem(slug);
|
|
208
|
+
const lastChange = useLastChange(project, environment.slug, opens);
|
|
209
|
+
const holders = holdersOf(grants, environment.slug);
|
|
210
|
+
// A new slug brings in whoever holds it in every project: said before the rename is saved.
|
|
211
|
+
const gainedBy =
|
|
212
|
+
slug === environment.slug || slugError !== null
|
|
213
|
+
? []
|
|
214
|
+
: reaching(everyProject, slug).filter((grant) => grant.place !== '*');
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<div
|
|
218
|
+
className={`env-card${opens ? ' is-link' : ' is-muted'} ${rowClass(state)}`}
|
|
219
|
+
>
|
|
220
|
+
<div className="env-card-text">
|
|
221
|
+
<span className="env-card-head">
|
|
222
|
+
{opens ? (
|
|
223
|
+
<Link
|
|
224
|
+
className="env-card-name stretch"
|
|
225
|
+
to="/projects/$project/$environment"
|
|
226
|
+
params={{ project, environment: environment.slug }}
|
|
227
|
+
>
|
|
228
|
+
{environment.name}
|
|
229
|
+
</Link>
|
|
230
|
+
) : (
|
|
231
|
+
<span className="env-card-name">{environment.name}</span>
|
|
232
|
+
)}
|
|
233
|
+
<span className="env-card-slug mono">{environment.slug}</span>
|
|
234
|
+
</span>
|
|
235
|
+
|
|
236
|
+
{isArchived ? (
|
|
237
|
+
<span className="env-card-meta">
|
|
238
|
+
<span className="tag tag-red">Archived</span>
|
|
239
|
+
</span>
|
|
240
|
+
) : !environment.accessible && !pending ? (
|
|
241
|
+
<span className="env-card-meta">
|
|
242
|
+
<span className="tag tag-outline">No secret access</span>
|
|
243
|
+
</span>
|
|
244
|
+
) : (
|
|
245
|
+
secretCount !== null && (
|
|
246
|
+
<span className="env-card-facts">
|
|
247
|
+
<span className="env-card-count">
|
|
248
|
+
<strong>{secretCount}</strong> secret{secretCount === 1 ? '' : 's'}
|
|
249
|
+
</span>
|
|
250
|
+
{lastChange !== null && (
|
|
251
|
+
<span className="env-card-change">
|
|
252
|
+
Changed <Timestamp iso={lastChange.at} display="relative" />
|
|
253
|
+
{lastChange.by !== null && <> by {lastChange.by.split('@')[0]}</>}
|
|
254
|
+
</span>
|
|
255
|
+
)}
|
|
256
|
+
</span>
|
|
257
|
+
)
|
|
258
|
+
)}
|
|
259
|
+
|
|
260
|
+
{holders.length > 0 && !isArchived && (
|
|
261
|
+
<span
|
|
262
|
+
className="env-card-holders"
|
|
263
|
+
title={holders.map((grant) => grant.principalId).join(', ')}
|
|
264
|
+
>
|
|
265
|
+
<span className="avatar-stack">
|
|
266
|
+
{holders.slice(0, SHOWN_HOLDERS).map((grant) => (
|
|
267
|
+
<PrincipalAvatar
|
|
268
|
+
key={`${grant.principalType}:${grant.principalId}`}
|
|
269
|
+
type={grant.principalType}
|
|
270
|
+
id={grant.principalId}
|
|
271
|
+
/>
|
|
272
|
+
))}
|
|
273
|
+
</span>
|
|
274
|
+
<span>{holders.length} with access</span>
|
|
275
|
+
</span>
|
|
276
|
+
)}
|
|
277
|
+
</div>
|
|
278
|
+
|
|
279
|
+
{opens && <ChevronRight size={16} className="env-card-go" aria-hidden />}
|
|
280
|
+
|
|
281
|
+
{pending && <RowPending status={state} />}
|
|
282
|
+
|
|
283
|
+
{manageable && !pending && (
|
|
284
|
+
<Menu.Root>
|
|
285
|
+
<Menu.Trigger
|
|
286
|
+
className="act act-quiet env-card-menu"
|
|
287
|
+
aria-label={`Actions for ${environment.slug}`}
|
|
288
|
+
>
|
|
289
|
+
<MoreHorizontal size={16} />
|
|
290
|
+
</Menu.Trigger>
|
|
291
|
+
<MenuPopup align="end">
|
|
292
|
+
<Menu.Item
|
|
293
|
+
className="menu-item"
|
|
294
|
+
onClick={() => {
|
|
295
|
+
setSlug(environment.slug);
|
|
296
|
+
setName(environment.name);
|
|
297
|
+
setRenaming(true);
|
|
298
|
+
}}
|
|
299
|
+
>
|
|
300
|
+
<Pencil size={14} />
|
|
301
|
+
Rename
|
|
302
|
+
</Menu.Item>
|
|
303
|
+
<Menu.Separator className="menu-sep" />
|
|
304
|
+
<Menu.Item
|
|
305
|
+
className={`menu-item${isArchived ? '' : ' menu-item-danger'}`}
|
|
306
|
+
onClick={() => setConfirming(true)}
|
|
307
|
+
>
|
|
308
|
+
{isArchived ? <RotateBack size={14} /> : <Archive size={14} />}
|
|
309
|
+
{isArchived ? 'Restore' : 'Archive…'}
|
|
310
|
+
</Menu.Item>
|
|
311
|
+
{deletable && (
|
|
312
|
+
<Menu.Item className="menu-item menu-item-danger" onClick={() => setDeleting(true)}>
|
|
313
|
+
<Trash size={14} />
|
|
314
|
+
Delete…
|
|
315
|
+
</Menu.Item>
|
|
316
|
+
)}
|
|
317
|
+
</MenuPopup>
|
|
318
|
+
</Menu.Root>
|
|
319
|
+
)}
|
|
320
|
+
|
|
321
|
+
{manageable && (
|
|
322
|
+
<>
|
|
323
|
+
<Modal
|
|
324
|
+
open={renaming}
|
|
325
|
+
onOpenChange={setRenaming}
|
|
326
|
+
title={
|
|
327
|
+
<>
|
|
328
|
+
Rename{' '}
|
|
329
|
+
<span className="mono">
|
|
330
|
+
{project}/{environment.slug}
|
|
331
|
+
</span>
|
|
332
|
+
</>
|
|
333
|
+
}
|
|
334
|
+
>
|
|
335
|
+
<form
|
|
336
|
+
className="form"
|
|
337
|
+
onSubmit={(event) => {
|
|
338
|
+
event.preventDefault();
|
|
339
|
+
// Shown on the card at once; the card says if the server refuses.
|
|
340
|
+
rename({ from: environment.slug, slug, name: name.trim() });
|
|
341
|
+
setRenaming(false);
|
|
342
|
+
}}
|
|
343
|
+
>
|
|
344
|
+
<label className="field">
|
|
345
|
+
<span className="label">Slug</span>
|
|
346
|
+
<input
|
|
347
|
+
className="input input-mono"
|
|
348
|
+
autoFocus
|
|
349
|
+
spellCheck={false}
|
|
350
|
+
value={slug}
|
|
351
|
+
aria-invalid={slugError !== null}
|
|
352
|
+
onChange={(event) => setSlug(event.target.value)}
|
|
353
|
+
/>
|
|
354
|
+
<span className={`hint${slugError !== null ? ' edit-note-error' : ''}`}>
|
|
355
|
+
{slugError ??
|
|
356
|
+
`Anything running coffre run ${project}/${environment.slug} will need the new path.`}
|
|
357
|
+
</span>
|
|
358
|
+
</label>
|
|
359
|
+
<label className="field">
|
|
360
|
+
<span className="label">Display name</span>
|
|
361
|
+
<input
|
|
362
|
+
className="input"
|
|
363
|
+
value={name}
|
|
364
|
+
onChange={(event) => setName(event.target.value)}
|
|
365
|
+
/>
|
|
366
|
+
</label>
|
|
367
|
+
|
|
368
|
+
<ReachedBy grants={gainedBy} lead={`As ${project}/${slug}, it is reached by`} />
|
|
369
|
+
|
|
370
|
+
<div className="dialog-actions">
|
|
371
|
+
<button className="btn" type="button" onClick={() => setRenaming(false)}>
|
|
372
|
+
Cancel
|
|
373
|
+
</button>
|
|
374
|
+
<button
|
|
375
|
+
className="btn btn-primary"
|
|
376
|
+
type="submit"
|
|
377
|
+
disabled={slug === '' || slugError !== null || name.trim() === ''}
|
|
378
|
+
>
|
|
379
|
+
Save
|
|
380
|
+
</button>
|
|
381
|
+
</div>
|
|
382
|
+
</form>
|
|
383
|
+
</Modal>
|
|
384
|
+
|
|
385
|
+
<ConfirmDialog
|
|
386
|
+
open={confirming}
|
|
387
|
+
onOpenChange={setConfirming}
|
|
388
|
+
title={
|
|
389
|
+
<>
|
|
390
|
+
{isArchived ? 'Restore' : 'Archive'}{' '}
|
|
391
|
+
<span className="mono">
|
|
392
|
+
{project}/{environment.slug}
|
|
393
|
+
</span>
|
|
394
|
+
?
|
|
395
|
+
</>
|
|
396
|
+
}
|
|
397
|
+
body={
|
|
398
|
+
secretCount === null ? (
|
|
399
|
+
<>
|
|
400
|
+
This changes whether the environment serves secrets to principals who have
|
|
401
|
+
access. Values and history remain stored.
|
|
402
|
+
</>
|
|
403
|
+
) : isArchived ? (
|
|
404
|
+
<>
|
|
405
|
+
The environment starts serving its {secretCount} secret
|
|
406
|
+
{secretCount === 1 ? '' : 's'} again, to everyone who holds a grant on it.
|
|
407
|
+
</>
|
|
408
|
+
) : (
|
|
409
|
+
<>
|
|
410
|
+
Its {secretCount} secret{secretCount === 1 ? '' : 's'} stop being served, so
|
|
411
|
+
anything running <code>coffre run</code> against{' '}
|
|
412
|
+
<span className="mono">
|
|
413
|
+
{project}/{environment.slug}
|
|
414
|
+
</span>{' '}
|
|
415
|
+
loses them at its next start. Values and history survive, and restoring is
|
|
416
|
+
one click.
|
|
417
|
+
</>
|
|
418
|
+
)
|
|
419
|
+
}
|
|
420
|
+
detail={<ArchiveBlocked references={blockers} />}
|
|
421
|
+
confirmLabel={isArchived ? 'Restore environment' : 'Archive environment'}
|
|
422
|
+
confirmDisabled={asking || blockers.length > 0}
|
|
423
|
+
destructive={!isArchived}
|
|
424
|
+
onConfirm={() => archive({ slug: environment.slug, archived: !isArchived })}
|
|
425
|
+
/>
|
|
426
|
+
</>
|
|
427
|
+
)}
|
|
428
|
+
|
|
429
|
+
{deletable && (
|
|
430
|
+
<DeletePlaceDialog
|
|
431
|
+
path={`${project}/${environment.slug}`}
|
|
432
|
+
open={deleting}
|
|
433
|
+
onOpenChange={setDeleting}
|
|
434
|
+
onDeleted={() => toast.success(`${project}/${environment.slug} deleted, and its name is free`)}
|
|
435
|
+
/>
|
|
436
|
+
)}
|
|
437
|
+
|
|
438
|
+
<ItemFailure
|
|
439
|
+
status={state}
|
|
440
|
+
onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
|
|
441
|
+
/>
|
|
442
|
+
</div>
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* A new environment, empty, or forked from one you can read: each of its
|
|
448
|
+
* keys copied, value and folder, without history. Copying is a read, and
|
|
449
|
+
* logged as one.
|
|
450
|
+
*/
|
|
451
|
+
function NewEnvironment({ project, sources }: { project: string; sources: string[] }) {
|
|
452
|
+
const [open, setOpen] = useState(false);
|
|
453
|
+
const [slug, setSlug] = useState('');
|
|
454
|
+
const [name, setName] = useState('');
|
|
455
|
+
// '' for empty, 'copy:prod' for a copy, 'ref:prod' for references to prod.
|
|
456
|
+
const [start, setStart] = useState('');
|
|
457
|
+
const [how, from] = start === '' ? ['', ''] : (start.split(':') as ['copy' | 'ref', string]);
|
|
458
|
+
const coffre = useCoffre();
|
|
459
|
+
// A fork as references copies the keys whose source you read only through their parent: said before you confirm.
|
|
460
|
+
const { data: parent } = useQuery({ ...queries.secrets(coffre, { project, environment: from }), enabled: how === 'ref' });
|
|
461
|
+
const copied = how === 'ref' && parent?.ok === true
|
|
462
|
+
? parent.keys.filter((key) => !key.archived && key.reference !== null && !key.reference.canOpenSource).map((key) => key.key)
|
|
463
|
+
: [];
|
|
464
|
+
const create = useChange(createEnvironment(coffre, project));
|
|
465
|
+
const slugError = slug === '' ? null : environmentSlugProblem(slug);
|
|
466
|
+
const reachedBy = reaching(useEveryProject(), slugError === null && slug !== '' ? slug : null);
|
|
467
|
+
|
|
468
|
+
function close() {
|
|
469
|
+
setOpen(false);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
return (
|
|
473
|
+
<>
|
|
474
|
+
<button className="btn btn-primary" onClick={() => setOpen(true)}>
|
|
475
|
+
<Plus size={14} />
|
|
476
|
+
Add environment
|
|
477
|
+
</button>
|
|
478
|
+
|
|
479
|
+
<Modal
|
|
480
|
+
open={open}
|
|
481
|
+
onOpenChange={(next) => (next ? setOpen(true) : close())}
|
|
482
|
+
title={
|
|
483
|
+
<>
|
|
484
|
+
New environment in <span className="mono">{project}</span>
|
|
485
|
+
</>
|
|
486
|
+
}
|
|
487
|
+
>
|
|
488
|
+
<form
|
|
489
|
+
className="form"
|
|
490
|
+
onSubmit={(event) => {
|
|
491
|
+
event.preventDefault();
|
|
492
|
+
// Listed at once, as saving; the list says if the server refuses.
|
|
493
|
+
create({ slug, name: name.trim(), ...(from === '' ? {} : { from }), ...(how === 'ref' ? { references: true } : {}) });
|
|
494
|
+
setSlug('');
|
|
495
|
+
setName('');
|
|
496
|
+
setStart('');
|
|
497
|
+
close();
|
|
498
|
+
}}
|
|
499
|
+
>
|
|
500
|
+
<label className="field">
|
|
501
|
+
<span className="label">Slug</span>
|
|
502
|
+
<input
|
|
503
|
+
className="input input-mono"
|
|
504
|
+
autoFocus
|
|
505
|
+
spellCheck={false}
|
|
506
|
+
autoComplete="off"
|
|
507
|
+
placeholder="staging"
|
|
508
|
+
value={slug}
|
|
509
|
+
aria-invalid={slugError !== null}
|
|
510
|
+
onChange={(event) => setSlug(event.target.value)}
|
|
511
|
+
/>
|
|
512
|
+
<span className={`hint${slugError !== null ? ' edit-note-error' : ''}`}>
|
|
513
|
+
{slugError ?? (
|
|
514
|
+
<>
|
|
515
|
+
The CLI will address it as{' '}
|
|
516
|
+
<span className="mono">
|
|
517
|
+
{project}/{slug === '' ? 'staging' : slug}
|
|
518
|
+
</span>
|
|
519
|
+
.
|
|
520
|
+
</>
|
|
521
|
+
)}
|
|
522
|
+
</span>
|
|
523
|
+
</label>
|
|
524
|
+
<label className="field">
|
|
525
|
+
<span className="label">Display name</span>
|
|
526
|
+
<input
|
|
527
|
+
className="input"
|
|
528
|
+
placeholder="Staging"
|
|
529
|
+
value={name}
|
|
530
|
+
onChange={(event) => setName(event.target.value)}
|
|
531
|
+
/>
|
|
532
|
+
</label>
|
|
533
|
+
{sources.length > 0 && (
|
|
534
|
+
<label className="field">
|
|
535
|
+
<span className="label">Start from</span>
|
|
536
|
+
<select className="select" value={start} onChange={(event) => setStart(event.target.value)}>
|
|
537
|
+
<option value="">Empty</option>
|
|
538
|
+
{sources.map((source) => (
|
|
539
|
+
<option key={`copy:${source}`} value={`copy:${source}`}>
|
|
540
|
+
A copy of {source}
|
|
541
|
+
</option>
|
|
542
|
+
))}
|
|
543
|
+
{sources.map((source) => (
|
|
544
|
+
<option key={`ref:${source}`} value={`ref:${source}`}>
|
|
545
|
+
References to {source}
|
|
546
|
+
</option>
|
|
547
|
+
))}
|
|
548
|
+
</select>
|
|
549
|
+
<span className="hint">
|
|
550
|
+
{how === ''
|
|
551
|
+
? 'No secrets yet.'
|
|
552
|
+
: how === 'copy'
|
|
553
|
+
? `Each of ${from}'s keys, with its current value and folder, without history. Copying reads them, in your name.`
|
|
554
|
+
: `Each key follows ${from}'s until it gets a value of its own. Whoever can read ${slug === '' ? 'the new environment' : slug} will read ${from}'s values through them, even without access to ${from}.`}
|
|
555
|
+
</span>
|
|
556
|
+
{copied.length > 0 && (
|
|
557
|
+
<span className="hint">
|
|
558
|
+
Copied instead, since you read their source only through {from}: <span className="mono">{copied.join(', ')}</span>.
|
|
559
|
+
</span>
|
|
560
|
+
)}
|
|
561
|
+
</label>
|
|
562
|
+
)}
|
|
563
|
+
|
|
564
|
+
<ReachedBy grants={reachedBy} lead="As soon as it exists, it is reached by" />
|
|
565
|
+
|
|
566
|
+
<div className="dialog-actions">
|
|
567
|
+
<button className="btn" type="button" onClick={close}>
|
|
568
|
+
Cancel
|
|
569
|
+
</button>
|
|
570
|
+
<button
|
|
571
|
+
className="btn btn-primary"
|
|
572
|
+
type="submit"
|
|
573
|
+
disabled={slug === '' || slugError !== null || name.trim() === ''}
|
|
574
|
+
>
|
|
575
|
+
Add environment
|
|
576
|
+
</button>
|
|
577
|
+
</div>
|
|
578
|
+
</form>
|
|
579
|
+
</Modal>
|
|
580
|
+
</>
|
|
581
|
+
);
|
|
582
|
+
}
|