Skip to content

Commit 757b8fa

Browse files
committed
View contents of attached secrets in Workspace Wizard
Signed-off-by: Charles Thao <[email protected]>
1 parent 06e1ca2 commit 757b8fa

File tree

4 files changed

+63
-6
lines changed

4 files changed

+63
-6
lines changed

workspaces/frontend/src/app/pages/Workspaces/Form/properties/WorkspaceFormPropertiesSecrets.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { useNotebookAPI } from '~/app/hooks/useNotebookAPI';
2323
import { useNamespaceContext } from '~/app/context/NamespaceContextProvider';
2424
import { SecretsAttachModal } from './secrets/SecretsAttachModal';
2525
import { SecretsCreateModal } from './secrets/SecretsCreateModal';
26+
import { SecretsViewPopover } from './secrets/SecretsViewPopover';
2627

2728
interface WorkspaceFormPropertiesSecretsProps {
2829
secrets: WorkspacesPodSecretMount[];
@@ -48,7 +49,6 @@ export const WorkspaceFormPropertiesSecrets: React.FC<WorkspaceFormPropertiesSec
4849
const [attachedSecrets, setAttachedSecrets] = useState<WorkspacesPodSecretMount[]>([]);
4950
const [attachedMountPath, setAttachedMountPath] = useState('');
5051
const [attachedDefaultMode, setAttachedDefaultMode] = useState(DEFAULT_MODE_OCTAL);
51-
5252
const { api } = useNotebookAPI();
5353
const { selectedNamespace } = useNamespaceContext();
5454

@@ -157,6 +157,7 @@ export const WorkspaceFormPropertiesSecrets: React.FC<WorkspaceFormPropertiesSec
157157
<Th>Secret Name</Th>
158158
<Th>Mount Path</Th>
159159
<Th>Default Mode</Th>
160+
<Th aria-label="View Secret" />
160161
<Th aria-label="Actions" />
161162
</Tr>
162163
</Thead>
@@ -166,6 +167,9 @@ export const WorkspaceFormPropertiesSecrets: React.FC<WorkspaceFormPropertiesSec
166167
<Td>{secret.secretName}</Td>
167168
<Td>{secret.mountPath}</Td>
168169
<Td>{secret.defaultMode?.toString(8) ?? DEFAULT_MODE_OCTAL}</Td>
170+
<Td isActionCell>
171+
<SecretsViewPopover secretName={secret.secretName} />
172+
</Td>
169173
<Td isActionCell>
170174
<Dropdown
171175
toggle={(toggleRef) => (
@@ -223,6 +227,7 @@ export const WorkspaceFormPropertiesSecrets: React.FC<WorkspaceFormPropertiesSec
223227
onSubmit={handleCreateOrEditSubmit}
224228
editSecret={editingSecret}
225229
/>
230+
226231
<Modal
227232
isOpen={isDeleteModalOpen}
228233
onClose={() => setIsDeleteModalOpen(false)}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React, { useEffect, useState } from 'react';
2+
import { Popover } from '@patternfly/react-core/dist/esm/components/Popover';
3+
import { Button } from '@patternfly/react-core/dist/esm/components/Button';
4+
import { EyeIcon } from '@patternfly/react-icons/dist/esm/icons/eye-icon';
5+
import { useNamespaceContext } from '~/app/context/NamespaceContextProvider';
6+
import { useNotebookAPI } from '~/app/hooks/useNotebookAPI';
7+
import { SecretsSecretUpdate } from '~/generated/data-contracts';
8+
9+
export interface SecretsViewPopoverProps {
10+
secretName: string;
11+
}
12+
export const SecretsViewPopover: React.FC<SecretsViewPopoverProps> = ({ secretName }) => {
13+
const { api } = useNotebookAPI();
14+
const { selectedNamespace } = useNamespaceContext();
15+
const [secret, setSecret] = useState<SecretsSecretUpdate | null>(null);
16+
useEffect(() => {
17+
const fetchSecret = async () => {
18+
const response = await api.secrets.getSecret(selectedNamespace, secretName);
19+
setSecret(response.data);
20+
};
21+
fetchSecret();
22+
}, [secretName, api.secrets, selectedNamespace]);
23+
const secretContentsKeys = secret ? Object.keys(secret.contents) : [];
24+
return (
25+
<Popover
26+
aria-label="Basic popover"
27+
headerContent={<div>{secretName}</div>}
28+
bodyContent={
29+
<div>
30+
{secretContentsKeys.map((key) => (
31+
<div key={key}>{key}: *********</div>
32+
))}
33+
</div>
34+
}
35+
>
36+
<Button variant="plain" icon={<EyeIcon />} />
37+
</Popover>
38+
);
39+
};

workspaces/frontend/src/shared/mock/mockNotebookApis.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
mockedHealthCheckResponse,
66
mockNamespaces,
77
mockSecretCreate,
8+
mockSecretCreate3,
89
mockSecretsList,
910
mockWorkspace1,
1011
mockWorkspaceKind1,
@@ -90,8 +91,8 @@ export const mockNotebookApisImpl = (): NotebookApis => ({
9091
data: mockSecretCreate,
9192
}),
9293
// eslint-disable-next-line @typescript-eslint/no-unused-vars
93-
getSecret: async () => ({
94-
data: mockSecretCreate,
94+
getSecret: async (_, name) => ({
95+
data: name === 'secret-3' ? mockSecretCreate3 : mockSecretCreate,
9596
}),
9697
updateSecret: async () => ({
9798
data: mockSecretCreate,

workspaces/frontend/src/shared/mock/mockNotebookServiceData.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,18 @@ export const mockSecretCreate: SecretsSecretCreate = {
179179
type: 'Opaque',
180180
immutable: false,
181181
contents: {
182-
data: {
183-
base64: 'abcd',
184-
},
182+
username: {},
183+
password: {},
184+
},
185+
};
186+
187+
export const mockSecretCreate3: SecretsSecretCreate = {
188+
name: 'secret-3',
189+
type: 'Opaque',
190+
immutable: false,
191+
contents: {
192+
apiKey: {},
193+
apiSecret: {},
185194
},
186195
};
187196

@@ -193,4 +202,7 @@ export const mockSecretsList = [
193202
name: 'secret-2',
194203
canMount: false,
195204
}),
205+
buildMockSecret({
206+
name: 'secret-3',
207+
}),
196208
];

0 commit comments

Comments
 (0)