Skip to content

Commit

Permalink
Finished secret snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
vmatsiiako committed Jan 5, 2023
1 parent df7340e commit 347b720
Show file tree
Hide file tree
Showing 14 changed files with 485 additions and 73 deletions.
1 change: 1 addition & 0 deletions backend/src/ee/controllers/v1/workspaceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
secretSnapshots = await SecretSnapshot.find({
workspace: workspaceId
})
.sort({ createdAt: -1 })
.skip(offset)
.limit(limit);

Expand Down
4 changes: 3 additions & 1 deletion backend/src/ee/routes/v1/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ router.get(

router.get(
'/:workspaceId/logs',
requireAuth,
requireAuth({
acceptedAuthModes: ['jwt']
}),
requireWorkspaceAuth({
acceptedRoles: [ADMIN, MEMBER]
}),
Expand Down
11 changes: 6 additions & 5 deletions backend/src/helpers/secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,12 @@ const v1PushSecrets = async ({

// (EE) add secret versions for new secrets
EESecretService.addSecretVersions({
secretVersions: newSecrets.map((s) => ({
...s,
secret: s._id,
isDeleted: false
}))
secretVersions: newSecrets.map((secretDocument) => {
return {
...secretDocument.toObject(),
secret: secretDocument._id,
isDeleted: false
}})
});

const addAction = await EELogService.createActionSecret({
Expand Down
10 changes: 4 additions & 6 deletions frontend/components/basic/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default function Layout({ children }: LayoutProps) {
}
});
}
router.push("/dashboard/" + newWorkspaceId + "?Development");
router.push("/dashboard/" + newWorkspaceId);
setIsOpen(false);
setNewWorkspaceName("");
} else {
Expand All @@ -141,8 +141,7 @@ export default function Layout({ children }: LayoutProps) {
{
href:
"/dashboard/" +
workspaceMapping[workspaceSelected as any] +
"?Development",
workspaceMapping[workspaceSelected as any],
title: t("nav:menu.secrets"),
emoji: <FontAwesomeIcon icon={faKey} />,
},
Expand Down Expand Up @@ -199,7 +198,7 @@ export default function Layout({ children }: LayoutProps) {
.map((workspace: { _id: string }) => workspace._id)
.includes(intendedWorkspaceId)
) {
router.push("/dashboard/" + userWorkspaces[0]._id + "?Development");
router.push("/dashboard/" + userWorkspaces[0]._id);
} else {
setWorkspaceList(
userWorkspaces.map((workspace: any) => workspace.name)
Expand Down Expand Up @@ -242,8 +241,7 @@ export default function Layout({ children }: LayoutProps) {
) {
router.push(
"/dashboard/" +
workspaceMapping[workspaceSelected as any] +
"?Development"
workspaceMapping[workspaceSelected as any]
);
localStorage.setItem(
"projectData.id",
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/basic/buttons/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default function Button(props: ButtonProps): JSX.Element {
<FontAwesomeIcon
icon={props.icon}
className={`flex my-auto font-extrabold ${
props.size == "icon-sm" ? "text-sm" : "text-md"
props.size == "icon-sm" ? "text-sm" : "text-sm"
} ${(props.text || props.textDisabled) && "mr-2"}`}
/>
)}
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/context/Notifications/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Notification = ({

return (
<div
className="relative w-full flex items-center justify-between px-4 py-6 rounded-md border border-bunker-500 pointer-events-auto bg-bunker-500"
className="relative w-full flex items-center justify-between px-4 py-4 rounded-md border border-bunker-500 pointer-events-auto bg-bunker-500"
role="alert"
>
{notification.type === 'error' && (
Expand All @@ -56,7 +56,7 @@ const Notification = ({
onClick={() => clearNotification(notification.text)}
>
<FontAwesomeIcon
className="text-white w-4 h-3 hover:text-red"
className="text-white pl-2 w-4 h-3 hover:text-red"
icon={faX}
/>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const NotificationProvider = ({ children }: NotificationProviderProps) => {
const createNotification = ({
text,
type = 'success',
timeoutMs = 5000
timeoutMs = 4000
}: Notification) => {
const doesNotifExist = notifications.some((notif) => notif.text === text);

Expand Down
15 changes: 9 additions & 6 deletions frontend/components/dashboard/KeyPair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface KeyPairProps {
isDuplicate: boolean;
toggleSidebar: (id: string) => void;
sidebarSecretId: string;
isSnapshot: boolean;
}

/**
Expand All @@ -33,6 +34,7 @@ interface KeyPairProps {
* @param {boolean} obj.isDuplicate - list of all the duplicates secret names on the dashboard
* @param {function} obj.toggleSidebar - open/close/switch sidebar
* @param {string} obj.sidebarSecretId - the id of a secret for the side bar is displayed
* @param {boolean} obj.isSnapshot - whether this keyPair is in a snapshot. If so, it won't have some features like sidebar
* @returns
*/
const KeyPair = ({
Expand All @@ -42,10 +44,11 @@ const KeyPair = ({
isBlurred,
isDuplicate,
toggleSidebar,
sidebarSecretId
sidebarSecretId,
isSnapshot
}: KeyPairProps) => {
return (
<div className={`mx-1 flex flex-col items-center ml-1 ${keyPair.id == sidebarSecretId && "bg-mineshaft-500 duration-200"} rounded-md`}>
<div className={`mx-1 flex flex-col items-center ml-1 ${isSnapshot && "pointer-events-none"} ${keyPair.id == sidebarSecretId && "bg-mineshaft-500 duration-200"} rounded-md`}>
<div className="relative flex flex-row justify-between w-full max-w-5xl mr-auto max-h-14 my-1 items-start px-1">
{keyPair.type == "personal" && <div className="group font-normal group absolute top-[1rem] left-[0.2rem] z-40 inline-block text-gray-300 underline hover:text-primary duration-200">
<div className='w-1 h-1 rounded-full bg-primary z-40'></div>
Expand All @@ -65,7 +68,7 @@ const KeyPair = ({
</div>
</div>
<div className="w-full min-w-xl">
<div className="flex min-w-xl items-center pr-1.5 rounded-lg mt-4 md:mt-0 max-h-10">
<div className={`flex min-w-xl items-center ${!isSnapshot && "pr-1.5"} rounded-lg mt-4 md:mt-0 max-h-10`}>
<DashboardInputField
onChangeHandler={modifyValue}
type="value"
Expand All @@ -76,15 +79,15 @@ const KeyPair = ({
/>
</div>
</div>
<div onClick={() => toggleSidebar(keyPair.id)} className="cursor-pointer w-[2.35rem] h-[2.35rem] bg-mineshaft-700 hover:bg-chicago-700 rounded-md flex flex-row justify-center items-center duration-200">
{!isSnapshot && <div onClick={() => toggleSidebar(keyPair.id)} className="cursor-pointer w-[2.35rem] h-[2.35rem] bg-mineshaft-700 hover:bg-chicago-700 rounded-md flex flex-row justify-center items-center duration-200">
<FontAwesomeIcon
className="text-gray-300 px-2.5 text-lg mt-0.5"
icon={faEllipsis}
/>
</div>
</div>}
</div>
</div>
);
};

export default React.memo(KeyPair);
export default KeyPair;
39 changes: 39 additions & 0 deletions frontend/ee/api/secrets/GetProjectSercetShanpshots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import SecurityClient from '~/utilities/SecurityClient';


interface workspaceProps {
workspaceId: string;
offset: number;
limit: number;
}

/**
* This function fetches the secret snapshots for a certain project
* @param {object} obj
* @param {string} obj.workspaceId - project id for which we are trying to get project secret snapshots
* @param {object} obj.offset - teh starting point of snapshots that we want to pull
* @param {object} obj.limit - how many snapshots will we output
* @returns
*/
const getProjectSecretShanpshots = async ({ workspaceId, offset, limit }: workspaceProps) => {
return SecurityClient.fetchCall(
'/api/v1/workspace/' + workspaceId + '/secret-snapshots?' +
new URLSearchParams({
offset: String(offset),
limit: String(limit)
}), {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
}
).then(async (res) => {
if (res && res.status == 200) {
return (await res.json()).secretSnapshots;
} else {
console.log('Failed to get project secret snapshots');
}
});
};

export default getProjectSecretShanpshots;
31 changes: 31 additions & 0 deletions frontend/ee/api/secrets/GetProjectSercetSnapshotsCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import SecurityClient from '~/utilities/SecurityClient';


interface workspaceProps {
workspaceId: string;
}

/**
* This function fetches the count of secret snapshots for a certain project
* @param {object} obj
* @param {string} obj.workspaceId - project id for which we are trying to get project secret snapshots
* @returns
*/
const getProjectSercetSnapshotsCount = async ({ workspaceId }: workspaceProps) => {
return SecurityClient.fetchCall(
'/api/v1/workspace/' + workspaceId + '/secret-snapshots/count', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
}
).then(async (res) => {
if (res && res.status == 200) {
return (await res.json()).count;
} else {
console.log('Failed to get the count of project secret snapshots');
}
});
};

export default getProjectSercetSnapshotsCount;
31 changes: 31 additions & 0 deletions frontend/ee/api/secrets/GetSecretSnapshotData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import SecurityClient from '~/utilities/SecurityClient';


interface SnapshotProps {
secretSnapshotId: string;
}

/**
* This function fetches the secrets for a certain secret snapshot
* @param {object} obj
* @param {string} obj.secretSnapshotId - snapshot id for which we are trying to get secrets
* @returns
*/
const getSecretSnapshotData = async ({ secretSnapshotId }: SnapshotProps) => {
return SecurityClient.fetchCall(
'/api/v1/secret-snapshot/' + secretSnapshotId, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
}
).then(async (res) => {
if (res && res.status == 200) {
return (await res.json()).secretSnapshot;
} else {
console.log('Failed to get the secrets of a certain snapshot');
}
});
};

export default getSecretSnapshotData;
Loading

0 comments on commit 347b720

Please sign in to comment.