{new Date(version.createdAt).toLocaleDateString('en-US', {
year: 'numeric',
month: '2-digit',
diff --git a/frontend/src/hooks/api/secrets/queries.tsx b/frontend/src/hooks/api/secrets/queries.tsx
index 9b9c49df52..031c661d1e 100644
--- a/frontend/src/hooks/api/secrets/queries.tsx
+++ b/frontend/src/hooks/api/secrets/queries.tsx
@@ -19,18 +19,42 @@ import {
export const secretKeys = {
// this is also used in secretSnapshot part
- getProjectSecret: (workspaceId: string, env: string) => [{ workspaceId, env }, 'secrets'],
+ getProjectSecret: (workspaceId: string, env: string | string[]) => [{ workspaceId, env }, 'secrets'],
getSecretVersion: (secretId: string) => [{ secretId }, 'secret-versions']
};
-const fetchProjectEncryptedSecrets = async (workspaceId: string, env: string) => {
- const { data } = await apiRequest.get<{ secrets: EncryptedSecret[] }>('/api/v2/secrets', {
- params: {
- environment: env,
- workspaceId
+const fetchProjectEncryptedSecrets = async (workspaceId: string, env: string | string[]) => {
+ if (typeof env === 'string') {
+ const { data } = await apiRequest.get<{ secrets: EncryptedSecret[] }>('/api/v2/secrets', {
+ params: {
+ environment: env,
+ workspaceId
+ }
+ });
+ return data.secrets;
+ }
+
+ if (typeof env === 'object') {
+ let allEnvData: any = [];
+
+ // eslint-disable-next-line no-restricted-syntax
+ for (const envPoint of env) {
+ // eslint-disable-next-line no-await-in-loop
+ const { data } = await apiRequest.get<{ secrets: EncryptedSecret[] }>('/api/v2/secrets', {
+ params: {
+ environment: envPoint,
+ workspaceId
+ }
+ });
+ allEnvData = allEnvData.concat(data.secrets);
}
- });
- return data.secrets;
+
+ return allEnvData;
+ // eslint-disable-next-line no-else-return
+ } else {
+ return null;
+ }
+
};
export const useGetProjectSecrets = ({
@@ -59,7 +83,7 @@ export const useGetProjectSecrets = ({
// this used for add-only mode in dashboard
// type won't be there thus only one key is shown
const duplicateSecretKey: Record
= {};
- data.forEach((encSecret) => {
+ data.forEach((encSecret: EncryptedSecret) => {
const secretKey = decryptSymmetric({
ciphertext: encSecret.secretKeyCiphertext,
iv: encSecret.secretKeyIV,
@@ -93,12 +117,12 @@ export const useGetProjectSecrets = ({
};
if (encSecret.type === 'personal') {
- personalSecrets[decryptedSecret.key] = { id: encSecret._id, value: secretValue };
+ personalSecrets[`${decryptedSecret.key}-${decryptedSecret.env}`] = { id: encSecret._id, value: secretValue };
} else {
- if (!duplicateSecretKey?.[decryptedSecret.key]) {
+ if (!duplicateSecretKey?.[`${decryptedSecret.key}-${decryptedSecret.env}`]) {
sharedSecrets.push(decryptedSecret);
}
- duplicateSecretKey[decryptedSecret.key] = true;
+ duplicateSecretKey[`${decryptedSecret.key}-${decryptedSecret.env}`] = true;
}
});
sharedSecrets.forEach((val) => {
diff --git a/frontend/src/hooks/api/secrets/types.ts b/frontend/src/hooks/api/secrets/types.ts
index 7888e64b32..567fecc9a4 100644
--- a/frontend/src/hooks/api/secrets/types.ts
+++ b/frontend/src/hooks/api/secrets/types.ts
@@ -90,7 +90,7 @@ export type BatchSecretDTO = {
export type GetProjectSecretsDTO = {
workspaceId: string;
- env: string;
+ env: string | string[];
decryptFileKey: UserWsKeyPair;
isPaused?: boolean;
onSuccess?: (data: DecryptedSecret[]) => void;
diff --git a/frontend/src/layouts/AppLayout/AppLayout.tsx b/frontend/src/layouts/AppLayout/AppLayout.tsx
index 93ed5b860b..85828c3c5c 100644
--- a/frontend/src/layouts/AppLayout/AppLayout.tsx
+++ b/frontend/src/layouts/AppLayout/AppLayout.tsx
@@ -20,6 +20,7 @@ import {
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { yupResolver } from '@hookform/resolvers/yup';
+import queryString from 'query-string';
import * as yup from 'yup';
import { useNotificationContext } from '@app/components/context/Notifications/NotificationProvider';
@@ -158,7 +159,10 @@ export const AppLayout = ({ children }: LayoutProps) => {
.map((workspace: { _id: string }) => workspace._id)
.includes(intendedWorkspaceId)
) {
- router.push(`/dashboard/${userWorkspaces[0]._id}`);
+ const { env } = queryString.parse(router.asPath.split('?')[1]);
+ if (!env) {
+ router.push(`/dashboard/${userWorkspaces[0]._id}`);
+ }
} else {
setWorkspaceMapping(
Object.fromEntries(
@@ -271,11 +275,12 @@ export const AppLayout = ({ children }: LayoutProps) => {
{name}
))}
-
+ {/*
*/}