Skip to content

Commit 1e9eb3c

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

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
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/mockNotebookServiceData.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,8 @@ export const mockSecretCreate: SecretsSecretCreate = {
179179
type: 'Opaque',
180180
immutable: false,
181181
contents: {
182-
data: {
183-
base64: 'abcd',
184-
},
182+
username: {},
183+
password: {},
185184
},
186185
};
187186

@@ -193,4 +192,7 @@ export const mockSecretsList = [
193192
name: 'secret-2',
194193
canMount: false,
195194
}),
195+
buildMockSecret({
196+
name: 'secret-3',
197+
}),
196198
];

0 commit comments

Comments
 (0)