feature secret rotations v2

This commit is contained in:
Scott Wilson
2025-03-31 20:34:48 -07:00
parent da094383b8
commit 766c1242fd
275 changed files with 9692 additions and 783 deletions
+43 -5
View File
@@ -132,6 +132,21 @@ export const fetchDashboardProjectSecretsByKeys = async ({
return data;
};
const mergePersonalRotationSecrets = (secrets: (SecretV3Raw | null)[]) => {
const actualSecrets: SecretV3Raw[] = [];
const dummySecrets: null[] = [];
secrets.forEach((secret) => {
if (secret !== null) {
actualSecrets.push(secret);
} else {
dummySecrets.push(secret);
}
});
return [...mergePersonalSecrets(actualSecrets), ...dummySecrets];
};
export const useGetProjectSecretsOverview = (
{
projectId,
@@ -145,6 +160,7 @@ export const useGetProjectSecretsOverview = (
includeFolders,
includeImports,
includeDynamicSecrets,
includeSecretRotations,
environments
}: TGetDashboardProjectSecretsOverviewDTO,
options?: Omit<
@@ -173,6 +189,7 @@ export const useGetProjectSecretsOverview = (
includeFolders,
includeImports,
includeDynamicSecrets,
includeSecretRotations,
environments
}),
queryFn: () =>
@@ -188,10 +205,11 @@ export const useGetProjectSecretsOverview = (
includeFolders,
includeImports,
includeDynamicSecrets,
includeSecretRotations,
environments
}),
select: useCallback((data: Awaited<ReturnType<typeof fetchProjectSecretsOverview>>) => {
const { secrets, ...select } = data;
const { secrets, secretRotations, ...select } = data;
const uniqueSecrets = secrets ? unique(secrets, (i) => i.secretKey) : [];
const uniqueFolders = select.folders ? unique(select.folders, (i) => i.name) : [];
@@ -201,14 +219,22 @@ export const useGetProjectSecretsOverview = (
: [];
const uniqueSecretImports = select.imports ? unique(select.imports, (i) => i.id) : [];
const uniqueSecretRotations = secretRotations ? unique(secretRotations, (i) => i.name) : [];
return {
...select,
secrets: secrets ? mergePersonalSecrets(secrets) : undefined,
secretRotations: secretRotations?.map((rotation) => {
return {
...rotation,
secrets: mergePersonalRotationSecrets(rotation.secrets)
};
}),
totalUniqueSecretsInPage: uniqueSecrets.length,
totalUniqueDynamicSecretsInPage: uniqueDynamicSecrets.length,
totalUniqueFoldersInPage: uniqueFolders.length,
totalUniqueSecretImportsInPage: uniqueSecretImports.length
totalUniqueSecretImportsInPage: uniqueSecretImports.length,
totalUniqueSecretRotationsInPage: uniqueSecretRotations.length
};
}, []),
placeholderData: (previousData) => previousData
@@ -230,6 +256,7 @@ export const useGetProjectSecretsDetails = (
viewSecretValue,
includeImports,
includeDynamicSecrets,
includeSecretRotations,
tags
}: TGetDashboardProjectSecretsDetailsDTO,
options?: Omit<
@@ -260,6 +287,7 @@ export const useGetProjectSecretsDetails = (
includeFolders,
includeImports,
includeDynamicSecrets,
includeSecretRotations,
tags
}),
queryFn: () =>
@@ -277,12 +305,17 @@ export const useGetProjectSecretsDetails = (
includeFolders,
includeImports,
includeDynamicSecrets,
includeSecretRotations,
tags
}),
select: useCallback(
(data: Awaited<ReturnType<typeof fetchProjectSecretsDetails>>) => ({
...data,
secrets: data.secrets ? mergePersonalSecrets(data.secrets) : undefined
secrets: data.secrets ? mergePersonalSecrets(data.secrets) : undefined,
secretRotations: data.secretRotations?.map((rotation) => ({
...rotation,
secrets: mergePersonalRotationSecrets(rotation.secrets)
}))
}),
[]
),
@@ -371,7 +404,7 @@ export const useGetProjectSecretsQuickSearch = (
tags
}),
select: useCallback((data: Awaited<ReturnType<typeof fetchProjectSecretsQuickSearch>>) => {
const { secrets, folders, dynamicSecrets } = data;
const { secrets, folders, dynamicSecrets, secretRotations } = data;
const groupedFolders = groupBy(folders, (folder) => folder.path);
const groupedSecrets = groupBy(
@@ -383,11 +416,16 @@ export const useGetProjectSecretsQuickSearch = (
(dynamicSecret) =>
`${dynamicSecret.path === "/" ? "" : dynamicSecret.path}/${dynamicSecret.name}`
);
const groupedRotations = groupBy(
secretRotations,
(rotation) => `${rotation.folder.path === "/" ? "" : rotation.folder.path}/${rotation.name}`
);
return {
folders: groupedFolders,
secrets: groupedSecrets,
dynamicSecrets: groupedDynamicSecrets
dynamicSecrets: groupedDynamicSecrets,
secretRotations: groupedRotations
};
}, []),
placeholderData: (previousData) => previousData
+20 -1
View File
@@ -3,6 +3,7 @@ import { TDynamicSecret } from "@app/hooks/api/dynamicSecret/types";
import { OrderByDirection } from "@app/hooks/api/generic/types";
import { TSecretFolder } from "@app/hooks/api/secretFolders/types";
import { TSecretImport } from "@app/hooks/api/secretImports/types";
import { TSecretRotationV2 } from "@app/hooks/api/secretRotationsV2";
import { SecretV3Raw, SecretV3RawSanitized } from "@app/hooks/api/secrets/types";
export type DashboardProjectSecretsOverviewResponse = {
@@ -14,11 +15,16 @@ export type DashboardProjectSecretsOverviewResponse = {
totalFolderCount?: number;
totalDynamicSecretCount?: number;
totalImportCount?: number;
secretRotations?: (TSecretRotationV2 & {
secrets: (SecretV3Raw | null)[];
})[];
totalSecretRotationCount?: number;
totalCount: number;
totalUniqueSecretsInPage: number;
totalUniqueDynamicSecretsInPage: number;
totalUniqueFoldersInPage: number;
totalUniqueSecretImportsInPage: number;
totalUniqueSecretRotationsInPage: number;
};
export type DashboardProjectSecretsDetailsResponse = {
@@ -26,10 +32,14 @@ export type DashboardProjectSecretsDetailsResponse = {
folders?: TSecretFolder[];
dynamicSecrets?: TDynamicSecret[];
secrets?: SecretV3Raw[];
secretRotations?: (TSecretRotationV2 & {
secrets: (SecretV3Raw | null)[];
})[];
totalImportCount?: number;
totalFolderCount?: number;
totalDynamicSecretCount?: number;
totalSecretCount?: number;
totalSecretRotationCount?: number;
totalCount: number;
};
@@ -39,9 +49,12 @@ export type DashboardProjectSecretsByKeys = {
export type DashboardProjectSecretsOverview = Omit<
DashboardProjectSecretsOverviewResponse,
"secrets"
"secrets" | "secretRotations"
> & {
secrets?: SecretV3RawSanitized[];
secretRotations?: (TSecretRotationV2 & {
secrets: (SecretV3RawSanitized | null)[];
})[];
};
export type DashboardProjectSecretsDetails = Omit<
@@ -49,6 +62,9 @@ export type DashboardProjectSecretsDetails = Omit<
"secrets"
> & {
secrets?: SecretV3RawSanitized[];
secretRotations?: (TSecretRotationV2 & {
secrets: (SecretV3RawSanitized | null)[];
})[];
};
export enum DashboardSecretsOrderBy {
@@ -67,6 +83,7 @@ export type TGetDashboardProjectSecretsOverviewDTO = {
includeFolders?: boolean;
includeDynamicSecrets?: boolean;
includeImports?: boolean;
includeSecretRotations?: boolean;
environments: string[];
};
@@ -83,6 +100,7 @@ export type TGetDashboardProjectSecretsDetailsDTO = Omit<
export type TDashboardProjectSecretsQuickSearchResponse = {
folders: (TSecretFolder & { envId: string; path: string })[];
dynamicSecrets: (TDynamicSecret & { environment: string; path: string })[];
secretRotations: TSecretRotationV2[];
secrets: SecretV3Raw[];
};
@@ -90,6 +108,7 @@ export type TDashboardProjectSecretsQuickSearch = {
folders: Record<string, TDashboardProjectSecretsQuickSearchResponse["folders"]>;
secrets: Record<string, SecretV3RawSanitized[]>;
dynamicSecrets: Record<string, TDashboardProjectSecretsQuickSearchResponse["dynamicSecrets"]>;
secretRotations: Record<string, TDashboardProjectSecretsQuickSearchResponse["secretRotations"]>;
};
export type TGetDashboardProjectSecretsQuickSearchDTO = {