feat: migrated secret router

This commit is contained in:
=
2025-09-13 15:58:51 +05:30
parent 02dc2e2106
commit 5f902229f6
12 changed files with 1472 additions and 269 deletions

View File

@@ -431,7 +431,7 @@ export const secretRotationQueueFactory = ({
numberOfSecrets: numberOfSecretsRotated,
environment: secretRotation.environment.slug,
secretPath: secretRotation.secretPath,
workspaceId: secretRotation.projectId
projectId: secretRotation.projectId
}
});

View File

@@ -984,7 +984,7 @@ export const RAW_SECRETS = {
secretValue: "The value of the secret to create.",
skipMultilineEncoding: "Skip multiline encoding for the secret value.",
type: "The type of the secret to create.",
workspaceId: "The ID of the project to create the secret in.",
projectId: "The ID of the project to create the secret in.",
tagIds: "The ID of the tags to be attached to the created secret.",
secretReminderRepeatDays: "Interval for secret rotation notifications, measured in days.",
secretReminderNote: "Note to be attached in notification email."
@@ -992,7 +992,7 @@ export const RAW_SECRETS = {
GET: {
expand: "Whether or not to expand secret references.",
secretName: "The name of the secret to get.",
workspaceId: "The ID of the project to get the secret from.",
projectId: "The ID of the project to get the secret from.",
workspaceSlug: "The slug of the project to get the secret from.",
environment: "The slug of the environment to get the secret from.",
secretPath: "The path of the secret to get.",
@@ -1011,7 +1011,7 @@ export const RAW_SECRETS = {
skipMultilineEncoding: "Skip multiline encoding for the secret value.",
type: "The type of the secret to update.",
projectSlug: "The slug of the project to update the secret in.",
workspaceId: "The ID of the project to update the secret in.",
projectId: "The ID of the project to update the secret in.",
tagIds: "The ID of the tags to be attached to the updated secret.",
secretReminderRepeatDays: "Interval for secret rotation notifications, measured in days.",
secretReminderNote: "Note to be attached in notification email.",
@@ -1025,7 +1025,7 @@ export const RAW_SECRETS = {
secretPath: "The path of the secret.",
type: "The type of the secret to delete.",
projectSlug: "The slug of the project to delete the secret in.",
workspaceId: "The ID of the project where the secret is located."
projectId: "The ID of the project where the secret is located."
},
GET_REFERENCE_TREE: {
secretName: "The name of the secret to get the reference tree for.",

View File

@@ -328,6 +328,7 @@ import { registerV1Routes } from "./v1";
import { initializeOauthConfigSync } from "./v1/sso-router";
import { registerV2Routes } from "./v2";
import { registerV3Routes } from "./v3";
import { registerV4Routes } from "./v4";
const histogram = monitorEventLoopDelay({ resolution: 20 });
histogram.enable();
@@ -2294,6 +2295,7 @@ export const registerRoutes = async (
{ prefix: "/api/v2" }
);
await server.register(registerV3Routes, { prefix: "/api/v3" });
await server.register(registerV4Routes, { prefix: "/api/v4" });
server.addHook("onClose", async () => {
cronJobs.forEach((job) => job.stop());

View File

@@ -474,7 +474,7 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: secretCountFromEnv,
workspaceId: projectId,
projectId: projectId,
environment,
secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -1001,7 +1001,7 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: secretCount,
workspaceId: projectId,
projectId: projectId,
environment,
secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -1168,7 +1168,7 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: secretCountForEnv,
workspaceId: projectId,
projectId: projectId,
environment,
secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -1361,7 +1361,7 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: secrets.length,
workspaceId: projectId,
projectId: projectId,
environment,
secretPath,
channel: getUserAgentType(req.headers["user-agent"]),

View File

@@ -336,7 +336,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: secrets.length,
workspaceId,
projectId: workspaceId,
environment,
secretPath: req.query.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -405,7 +405,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
secretName: z.string().trim().describe(RAW_SECRETS.GET.secretName)
}),
querystring: z.object({
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.GET.workspaceId),
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.GET.projectId),
workspaceSlug: z.string().trim().optional().describe(RAW_SECRETS.GET.workspaceSlug),
environment: z.string().trim().optional().describe(RAW_SECRETS.GET.environment),
secretPath: z.string().trim().default("/").transform(removeTrailingSlash).describe(RAW_SECRETS.GET.secretPath),
@@ -495,7 +495,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
distinctId: getTelemetryDistinctId(req),
properties: {
numberOfSecrets: 1,
workspaceId: secret.workspace,
projectId: secret.workspace,
environment,
secretPath: req.query.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -526,7 +526,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
secretName: SecretNameSchema.describe(RAW_SECRETS.CREATE.secretName)
}),
body: z.object({
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.CREATE.workspaceId),
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.CREATE.projectId),
projectSlug: z.string().trim().optional().describe(RAW_SECRETS.CREATE.projectSlug),
environment: z.string().trim().describe(RAW_SECRETS.CREATE.environment),
secretPath: z
@@ -638,7 +638,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: 1,
workspaceId: projectId,
projectId,
environment: req.body.environment,
secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -669,7 +669,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
secretName: BaseSecretNameSchema.describe(RAW_SECRETS.UPDATE.secretName)
}),
body: z.object({
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.UPDATE.workspaceId),
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.UPDATE.projectId),
projectSlug: z.string().trim().optional().describe(RAW_SECRETS.UPDATE.projectSlug),
environment: z.string().trim().describe(RAW_SECRETS.UPDATE.environment),
secretValue: z
@@ -791,7 +791,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: 1,
workspaceId: projectId,
projectId,
environment: req.body.environment,
secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -821,7 +821,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
secretName: z.string().min(1).describe(RAW_SECRETS.DELETE.secretName)
}),
body: z.object({
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.DELETE.workspaceId),
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.DELETE.projectId),
projectSlug: z.string().trim().optional().describe(RAW_SECRETS.DELETE.projectSlug),
environment: z.string().trim().describe(RAW_SECRETS.DELETE.environment),
secretPath: z
@@ -909,7 +909,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: 1,
workspaceId: projectId,
projectId,
environment: req.body.environment,
secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -1017,7 +1017,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: secrets.length,
workspaceId: req.query.workspaceId,
projectId: req.query.workspaceId,
environment: req.query.environment,
secretPath: req.query.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -1097,7 +1097,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: 1,
workspaceId: req.query.workspaceId,
projectId: req.query.workspaceId,
environment: req.query.environment,
secretPath: req.query.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -1272,7 +1272,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: 1,
workspaceId: req.body.workspaceId,
projectId: req.body.workspaceId,
environment: req.body.environment,
secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -1466,7 +1466,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: 1,
workspaceId: req.body.workspaceId,
projectId: req.body.workspaceId,
environment: req.body.environment,
secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -1594,7 +1594,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: 1,
workspaceId: req.body.workspaceId,
projectId: req.body.workspaceId,
environment: req.body.environment,
secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -1781,7 +1781,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: secrets.length,
workspaceId: req.body.workspaceId,
projectId: req.body.workspaceId,
environment: req.body.environment,
secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -1914,7 +1914,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: secrets.length,
workspaceId: req.body.workspaceId,
projectId: req.body.workspaceId,
environment: req.body.environment,
secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -2039,7 +2039,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: secrets.length,
workspaceId: req.body.workspaceId,
projectId: req.body.workspaceId,
environment: req.body.environment,
secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -2067,7 +2067,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
],
body: z.object({
projectSlug: z.string().trim().optional().describe(RAW_SECRETS.UPDATE.projectSlug),
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.UPDATE.workspaceId),
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.UPDATE.projectId),
environment: z.string().trim().describe(RAW_SECRETS.CREATE.environment),
secretPath: z
.string()
@@ -2166,7 +2166,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: secrets.length,
workspaceId: secrets[0].workspace,
projectId: secrets[0].workspace,
environment: req.body.environment,
secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -2194,7 +2194,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
],
body: z.object({
projectSlug: z.string().trim().optional().describe(RAW_SECRETS.DELETE.projectSlug),
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.DELETE.workspaceId),
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.DELETE.projectId),
environment: z.string().trim().describe(RAW_SECRETS.UPDATE.environment),
secretPath: z
.string()
@@ -2341,7 +2341,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: secrets.length,
workspaceId: secrets[0].workspace,
projectId: secrets[0].workspace,
environment: req.body.environment,
secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -2369,7 +2369,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
],
body: z.object({
projectSlug: z.string().trim().optional().describe(RAW_SECRETS.DELETE.projectSlug),
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.DELETE.workspaceId),
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.DELETE.projectId),
environment: z.string().trim().describe(RAW_SECRETS.DELETE.environment),
secretPath: z
.string()
@@ -2459,7 +2459,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
organizationId: req.permission.orgId,
properties: {
numberOfSecrets: secrets.length,
workspaceId: secrets[0].workspace,
projectId: secrets[0].workspace,
environment: req.body.environment,
secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]),
@@ -2469,95 +2469,4 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
return { secrets };
}
});
server.route({
method: "GET",
url: "/raw/:secretName/secret-reference-tree",
config: {
rateLimit: secretsLimit
},
schema: {
hide: false,
tags: [ApiDocsTags.Secrets],
description: "Get secret reference tree",
security: [
{
bearerAuth: []
}
],
params: z.object({
secretName: z.string().trim().describe(RAW_SECRETS.GET_REFERENCE_TREE.secretName)
}),
querystring: z.object({
workspaceId: z.string().trim().describe(RAW_SECRETS.GET_REFERENCE_TREE.workspaceId),
environment: z.string().trim().describe(RAW_SECRETS.GET_REFERENCE_TREE.environment),
secretPath: z
.string()
.trim()
.default("/")
.transform(removeTrailingSlash)
.describe(RAW_SECRETS.GET_REFERENCE_TREE.secretPath)
}),
response: {
200: z.object({
tree: SecretReferenceNodeTree,
value: z.string().optional()
})
}
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
const { secretName } = req.params;
const { secretPath, environment, workspaceId } = req.query;
const { tree, value } = await server.services.secret.getSecretReferenceTree({
actorId: req.permission.id,
actor: req.permission.type,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
projectId: workspaceId,
secretName,
secretPath,
environment
});
return { tree, value };
}
});
server.route({
method: "POST",
url: "/backfill-secret-references",
config: {
rateLimit: secretsLimit
},
schema: {
description: "Backfill secret references",
security: [
{
bearerAuth: []
}
],
body: z.object({
projectId: z.string().trim().min(1)
}),
response: {
200: z.object({
message: z.string()
})
}
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
const { projectId } = req.body;
const message = await server.services.secret.backfillSecretReferences({
actorId: req.permission.id,
actor: req.permission.type,
actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId,
projectId
});
return message;
}
});
};

View File

@@ -0,0 +1,5 @@
import { registerSecretRouter } from "./secret-router";
export const registerV4Routes = async (server: FastifyZodProvider) => {
await server.register(registerSecretRouter, { prefix: "/secrets" });
};

File diff suppressed because it is too large Load Diff

View File

@@ -534,7 +534,8 @@ export type TSyncSecretsDTO<T extends boolean = false> = {
});
export type TMoveSecretsDTO = {
projectSlug: string;
projectId?: string;
projectSlug?: string;
sourceEnvironment: string;
sourceSecretPath: string;
destinationEnvironment: string;

View File

@@ -46,7 +46,7 @@ export type TSecretModifiedEvent = {
properties: {
numberOfSecrets: number;
environment: string;
workspaceId: string;
projectId: string;
secretPath: string;
channel?: string;
userAgent?: string;

View File

@@ -33,18 +33,18 @@ export const useCreateSecretV3 = ({
secretPath = "/",
type,
environment,
workspaceId,
projectId,
secretKey,
secretValue,
secretComment,
skipMultilineEncoding,
tagIds
}) => {
const { data } = await apiRequest.post(`/api/v3/secrets/raw/${secretKey}`, {
const { data } = await apiRequest.post(`/api/v4/secrets/${secretKey}`, {
secretPath,
type,
environment,
workspaceId,
projectId,
secretValue,
secretComment,
skipMultilineEncoding,
@@ -52,26 +52,26 @@ export const useCreateSecretV3 = ({
});
return data;
},
onSuccess: (_, { workspaceId, environment, secretPath }) => {
onSuccess: (_, { projectId, environment, secretPath }) => {
queryClient.invalidateQueries({
queryKey: dashboardKeys.getDashboardSecrets({ projectId: workspaceId, secretPath })
queryKey: dashboardKeys.getDashboardSecrets({ projectId, secretPath })
});
queryClient.invalidateQueries({
queryKey: secretKeys.getProjectSecret({ workspaceId, environment, secretPath })
queryKey: secretKeys.getProjectSecret({ projectId, environment, secretPath })
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.list({ environment, workspaceId, directory: secretPath })
queryKey: secretSnapshotKeys.list({ environment, projectId, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
queryKey: secretSnapshotKeys.count({ environment, projectId, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
queryKey: commitKeys.count({ projectId, environment, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
queryKey: commitKeys.history({ projectId, environment, directory: secretPath })
});
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ workspaceId }) });
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ projectId }) });
},
...options
});
@@ -88,7 +88,7 @@ export const useUpdateSecretV3 = ({
secretPath = "/",
type,
environment,
workspaceId,
projectId,
secretKey,
secretValue,
tagIds,
@@ -100,8 +100,8 @@ export const useUpdateSecretV3 = ({
skipMultilineEncoding,
secretMetadata
}) => {
const { data } = await apiRequest.patch(`/api/v3/secrets/raw/${secretKey}`, {
workspaceId,
const { data } = await apiRequest.patch(`/api/v4/secrets/${secretKey}`, {
projectId,
environment,
type,
secretReminderNote,
@@ -117,26 +117,26 @@ export const useUpdateSecretV3 = ({
});
return data;
},
onSuccess: (_, { workspaceId, environment, secretPath }) => {
onSuccess: (_, { projectId, environment, secretPath }) => {
queryClient.invalidateQueries({
queryKey: dashboardKeys.getDashboardSecrets({ projectId: workspaceId, secretPath })
queryKey: dashboardKeys.getDashboardSecrets({ projectId, secretPath })
});
queryClient.invalidateQueries({
queryKey: secretKeys.getProjectSecret({ workspaceId, environment, secretPath })
queryKey: secretKeys.getProjectSecret({ projectId, environment, secretPath })
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.list({ environment, workspaceId, directory: secretPath })
queryKey: secretSnapshotKeys.list({ environment, projectId, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
queryKey: secretSnapshotKeys.count({ environment, projectId, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
queryKey: commitKeys.count({ projectId, environment, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
queryKey: commitKeys.history({ projectId, environment, directory: secretPath })
});
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ workspaceId }) });
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ projectId }) });
},
...options
});
@@ -150,17 +150,10 @@ export const useDeleteSecretV3 = ({
const queryClient = useQueryClient();
return useMutation<object, object, TDeleteSecretsV3DTO>({
mutationFn: async ({
secretPath = "/",
type,
environment,
workspaceId,
secretKey,
secretId
}) => {
const { data } = await apiRequest.delete(`/api/v3/secrets/raw/${secretKey}`, {
mutationFn: async ({ secretPath = "/", type, environment, projectId, secretKey, secretId }) => {
const { data } = await apiRequest.delete(`/api/v4/secrets/${secretKey}`, {
data: {
workspaceId,
projectId,
environment,
type,
secretPath,
@@ -169,26 +162,26 @@ export const useDeleteSecretV3 = ({
});
return data;
},
onSuccess: (_, { workspaceId, environment, secretPath }) => {
onSuccess: (_, { projectId, environment, secretPath }) => {
queryClient.invalidateQueries({
queryKey: dashboardKeys.getDashboardSecrets({ projectId: workspaceId, secretPath })
queryKey: dashboardKeys.getDashboardSecrets({ projectId, secretPath })
});
queryClient.invalidateQueries({
queryKey: secretKeys.getProjectSecret({ workspaceId, environment, secretPath })
queryKey: secretKeys.getProjectSecret({ projectId, environment, secretPath })
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.list({ environment, workspaceId, directory: secretPath })
queryKey: secretSnapshotKeys.list({ environment, projectId, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
queryKey: secretSnapshotKeys.count({ environment, projectId, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
queryKey: commitKeys.count({ projectId, environment, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
queryKey: commitKeys.history({ projectId, environment, directory: secretPath })
});
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ workspaceId }) });
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ projectId }) });
},
...options
});
@@ -202,35 +195,35 @@ export const useCreateSecretBatch = ({
const queryClient = useQueryClient();
return useMutation<object, object, TCreateSecretBatchDTO>({
mutationFn: async ({ secretPath = "/", workspaceId, environment, secrets }) => {
const { data } = await apiRequest.post("/api/v3/secrets/batch/raw", {
workspaceId,
mutationFn: async ({ secretPath = "/", projectId, environment, secrets }) => {
const { data } = await apiRequest.post("/api/v4/secrets/batch", {
projectId,
environment,
secretPath,
secrets
});
return data;
},
onSuccess: (_, { workspaceId, environment, secretPath }) => {
onSuccess: (_, { projectId, environment, secretPath }) => {
queryClient.invalidateQueries({
queryKey: dashboardKeys.getDashboardSecrets({ projectId: workspaceId, secretPath })
queryKey: dashboardKeys.getDashboardSecrets({ projectId, secretPath })
});
queryClient.invalidateQueries({
queryKey: secretKeys.getProjectSecret({ workspaceId, environment, secretPath })
queryKey: secretKeys.getProjectSecret({ projectId, environment, secretPath })
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.list({ environment, workspaceId, directory: secretPath })
queryKey: secretSnapshotKeys.list({ environment, projectId, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
queryKey: secretSnapshotKeys.count({ environment, projectId, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
queryKey: commitKeys.count({ projectId, environment, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
queryKey: commitKeys.history({ projectId, environment, directory: secretPath })
});
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ workspaceId }) });
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ projectId }) });
},
...options
});
@@ -244,35 +237,35 @@ export const useUpdateSecretBatch = ({
const queryClient = useQueryClient();
return useMutation<object, object, TUpdateSecretBatchDTO>({
mutationFn: async ({ secretPath = "/", workspaceId, environment, secrets }) => {
const { data } = await apiRequest.patch("/api/v3/secrets/batch/raw", {
workspaceId,
mutationFn: async ({ secretPath = "/", projectId, environment, secrets }) => {
const { data } = await apiRequest.patch("/api/v4/secrets/batch", {
projectId,
environment,
secretPath,
secrets
});
return data;
},
onSuccess: (_, { workspaceId, environment, secretPath }) => {
onSuccess: (_, { projectId, environment, secretPath }) => {
queryClient.invalidateQueries({
queryKey: dashboardKeys.getDashboardSecrets({ projectId: workspaceId, secretPath })
queryKey: dashboardKeys.getDashboardSecrets({ projectId, secretPath })
});
queryClient.invalidateQueries({
queryKey: secretKeys.getProjectSecret({ workspaceId, environment, secretPath })
queryKey: secretKeys.getProjectSecret({ projectId, environment, secretPath })
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.list({ environment, workspaceId, directory: secretPath })
queryKey: secretSnapshotKeys.list({ environment, projectId, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
queryKey: secretSnapshotKeys.count({ environment, projectId, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
queryKey: commitKeys.count({ projectId, environment, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
queryKey: commitKeys.history({ projectId, environment, directory: secretPath })
});
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ workspaceId }) });
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ projectId }) });
},
...options
});
@@ -286,10 +279,10 @@ export const useDeleteSecretBatch = ({
const queryClient = useQueryClient();
return useMutation<object, object, TDeleteSecretBatchDTO>({
mutationFn: async ({ secretPath = "/", workspaceId, environment, secrets }) => {
const { data } = await apiRequest.delete("/api/v3/secrets/batch/raw", {
mutationFn: async ({ secretPath = "/", projectId, environment, secrets }) => {
const { data } = await apiRequest.delete("/api/v4/secrets/batch", {
data: {
workspaceId,
projectId,
environment,
secretPath,
secrets
@@ -297,26 +290,26 @@ export const useDeleteSecretBatch = ({
});
return data;
},
onSuccess: (_, { workspaceId, environment, secretPath }) => {
onSuccess: (_, { projectId, environment, secretPath }) => {
queryClient.invalidateQueries({
queryKey: dashboardKeys.getDashboardSecrets({ projectId: workspaceId, secretPath })
queryKey: dashboardKeys.getDashboardSecrets({ projectId, secretPath })
});
queryClient.invalidateQueries({
queryKey: secretKeys.getProjectSecret({ workspaceId, environment, secretPath })
queryKey: secretKeys.getProjectSecret({ projectId, environment, secretPath })
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.list({ environment, workspaceId, directory: secretPath })
queryKey: secretSnapshotKeys.list({ environment, projectId, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
queryKey: secretSnapshotKeys.count({ environment, projectId, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
queryKey: commitKeys.count({ projectId, environment, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
queryKey: commitKeys.history({ projectId, environment, directory: secretPath })
});
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ workspaceId }) });
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ projectId }) });
},
...options
});
@@ -349,7 +342,7 @@ export const useMoveSecrets = ({
const { data } = await apiRequest.post<{
isSourceUpdated: boolean;
isDestinationUpdated: boolean;
}>("/api/v3/secrets/move", {
}>("/api/v4/secrets/move", {
sourceEnvironment,
sourceSecretPath,
projectSlug,
@@ -370,7 +363,7 @@ export const useMoveSecrets = ({
});
queryClient.invalidateQueries({
queryKey: secretKeys.getProjectSecret({
workspaceId: projectId,
projectId,
environment: sourceEnvironment,
secretPath: sourceSecretPath
})
@@ -378,33 +371,33 @@ export const useMoveSecrets = ({
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.list({
environment: sourceEnvironment,
workspaceId: projectId,
projectId,
directory: sourceSecretPath
})
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.count({
environment: sourceEnvironment,
workspaceId: projectId,
projectId,
directory: sourceSecretPath
})
});
queryClient.invalidateQueries({
queryKey: commitKeys.count({
projectId: projectId,
projectId,
environment: sourceEnvironment,
directory: sourceSecretPath
})
});
queryClient.invalidateQueries({
queryKey: commitKeys.history({
workspaceId: projectId,
projectId,
environment: sourceEnvironment,
directory: sourceSecretPath
})
});
queryClient.invalidateQueries({
queryKey: secretApprovalRequestKeys.count({ workspaceId: projectId })
queryKey: secretApprovalRequestKeys.count({ projectId })
});
},
...options
@@ -432,16 +425,16 @@ export const useCreateCommit = () => {
object,
object,
{
workspaceId: string;
projectId: string;
environment: string;
secretPath: string;
pendingChanges: PendingChanges;
message: string;
}
>({
mutationFn: async ({ workspaceId, environment, secretPath, pendingChanges, message }) => {
mutationFn: async ({ projectId, environment, secretPath, pendingChanges, message }) => {
const { data } = await apiRequest.post("/api/v1/pit/batch/commit", {
projectId: workspaceId,
projectId,
environment,
secretPath,
changes: {
@@ -501,26 +494,26 @@ export const useCreateCommit = () => {
});
return data;
},
onSuccess: (_, { workspaceId, environment, secretPath }) => {
onSuccess: (_, { projectId, environment, secretPath }) => {
queryClient.invalidateQueries({
queryKey: dashboardKeys.getDashboardSecrets({ projectId: workspaceId, secretPath })
queryKey: dashboardKeys.getDashboardSecrets({ projectId, secretPath })
});
queryClient.invalidateQueries({
queryKey: secretKeys.getProjectSecret({ workspaceId, environment, secretPath })
queryKey: secretKeys.getProjectSecret({ projectId, environment, secretPath })
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.list({ environment, workspaceId, directory: secretPath })
queryKey: secretSnapshotKeys.list({ environment, projectId, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
queryKey: secretSnapshotKeys.count({ environment, projectId, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: commitKeys.count({ projectId: workspaceId, environment, directory: secretPath })
queryKey: commitKeys.count({ projectId, environment, directory: secretPath })
});
queryClient.invalidateQueries({
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
queryKey: commitKeys.history({ projectId, environment, directory: secretPath })
});
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ workspaceId }) });
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ projectId }) });
}
});
};

View File

@@ -27,35 +27,35 @@ import {
export const secretKeys = {
// this is also used in secretSnapshot part
getProjectSecret: ({
workspaceId,
projectId,
environment,
secretPath,
viewSecretValue
}: TGetProjectSecretsKey) =>
[{ workspaceId, environment, secretPath, viewSecretValue }, "secrets"] as const,
[{ projectId, environment, secretPath, viewSecretValue }, "secrets"] as const,
getSecretVersion: (secretId: string) => [{ secretId }, "secret-versions"] as const,
getSecretAccessList: ({
workspaceId,
projectId,
environment,
secretPath,
secretKey
}: TGetSecretAccessListDTO) =>
["secret-access-list", { workspaceId, environment, secretPath, secretKey }] as const,
["secret-access-list", { projectId, environment, secretPath, secretKey }] as const,
getSecretReferenceTree: (dto: TGetSecretReferenceTreeDTO) => ["secret-reference-tree", dto]
};
export const fetchProjectSecrets = async ({
workspaceId,
projectId,
environment,
secretPath,
includeImports,
expandSecretReferences,
viewSecretValue
}: TGetProjectSecretsKey) => {
const { data } = await apiRequest.get<SecretV3RawResponse>("/api/v3/secrets/raw", {
const { data } = await apiRequest.get<SecretV3RawResponse>("/api/v4/secrets", {
params: {
environment,
workspaceId,
projectId,
secretPath,
viewSecretValue,
expandSecretReferences,
@@ -116,7 +116,7 @@ export const mergePersonalSecrets = (rawSecrets: SecretV3Raw[]) => {
};
export const useGetProjectSecrets = ({
workspaceId,
projectId,
environment,
secretPath,
viewSecretValue,
@@ -135,14 +135,14 @@ export const useGetProjectSecrets = ({
useQuery({
...options,
// wait for all values to be available
enabled: Boolean(workspaceId && environment) && (options?.enabled ?? true),
enabled: Boolean(projectId && environment) && (options?.enabled ?? true),
queryKey: secretKeys.getProjectSecret({
workspaceId,
projectId,
environment,
secretPath,
viewSecretValue
}),
queryFn: () => fetchProjectSecrets({ workspaceId, environment, secretPath, viewSecretValue }),
queryFn: () => fetchProjectSecrets({ projectId, environment, secretPath, viewSecretValue }),
select: useCallback(
(data: Awaited<ReturnType<typeof fetchProjectSecrets>>) => mergePersonalSecrets(data.secrets),
[]
@@ -150,7 +150,7 @@ export const useGetProjectSecrets = ({
});
export const useGetProjectSecretsAllEnv = ({
workspaceId,
projectId,
envs,
secretPath
}: TGetProjectSecretsAllEnvDTO) => {
@@ -159,11 +159,11 @@ export const useGetProjectSecretsAllEnv = ({
const secrets = useQueries({
queries: envs.map((environment) => ({
queryKey: secretKeys.getProjectSecret({
workspaceId,
projectId,
environment,
secretPath
}),
enabled: Boolean(workspaceId && environment),
enabled: Boolean(projectId && environment),
onError: (error: unknown) => {
if (axios.isAxiosError(error) && !isErrorHandled) {
const { message, requestId } = error.response?.data as {
@@ -187,7 +187,7 @@ export const useGetProjectSecretsAllEnv = ({
setIsErrorHandled.on();
}
},
queryFn: () => fetchProjectSecrets({ workspaceId, environment, secretPath }),
queryFn: () => fetchProjectSecrets({ projectId, environment, secretPath }),
staleTime: 60 * 1000,
// eslint-disable-next-line react-hooks/rules-of-hooks
select: useCallback(
@@ -270,7 +270,7 @@ export const useGetSecretAccessList = (dto: TGetSecretAccessListDTO) =>
users: SecretAccessListEntry[];
}>(`/api/v1/secrets/${dto.secretKey}/access-list`, {
params: {
workspaceId: dto.workspaceId,
projectId: dto.projectId,
environment: dto.environment,
secretPath: dto.secretPath
}
@@ -287,11 +287,11 @@ const fetchSecretReferenceTree = async ({
environmentSlug
}: TGetSecretReferenceTreeDTO) => {
const { data } = await apiRequest.get<{ tree: TSecretReferenceTraceNode; value: string }>(
`/api/v3/secrets/raw/${secretKey}/secret-reference-tree`,
`/api/v4/secrets/${secretKey}/secret-reference-tree`,
{
params: {
secretPath,
workspaceId: projectId,
projectId,
environment: environmentSlug
}
}

View File

@@ -17,30 +17,6 @@ export type SecretReminderRecipient = {
};
id: string;
};
export type EncryptedSecret = {
id: string;
version: number;
workspace: string;
type: SecretType;
environment: string;
secretKeyCiphertext: string;
secretKeyIV: string;
secretKeyTag: string;
secretValueCiphertext: string;
secretValueIV: string;
secretValueTag: string;
secretValueHidden: boolean;
__v: number;
createdAt: string;
updatedAt: string;
skipMultilineEncoding?: boolean;
secretCommentCiphertext: string;
secretCommentIV: string;
secretCommentTag: string;
secretReminderRepeatDays?: number | null;
secretReminderNote?: string | null;
tags: WsTag[];
};
// both personal and shared secret stitched together for dashboard
export type SecretV3RawSanitized = {
@@ -76,7 +52,7 @@ export type SecretV3RawSanitized = {
export type SecretV3Raw = {
id: string;
_id: string;
workspace: string;
project: string;
environment: string;
version: number;
type: string;
@@ -113,7 +89,7 @@ export type SecretVersions = {
id: string;
secretId: string;
version: number;
workspace: string;
project: string;
type: SecretType;
isDeleted: boolean;
envId: string;
@@ -136,7 +112,7 @@ export type SecretVersions = {
// dto
export type TGetProjectSecretsKey = {
workspaceId: string;
projectId: string;
environment: string;
secretPath?: string;
includeImports?: boolean;
@@ -148,7 +124,7 @@ export type TGetProjectSecretsKey = {
export type TGetProjectSecretsDTO = TGetProjectSecretsKey;
export type TGetProjectSecretsAllEnvDTO = {
workspaceId: string;
projectId: string;
envs: string[];
folderId?: string;
secretPath?: string;
@@ -162,7 +138,7 @@ export type GetSecretVersionsDTO = {
};
export type TGetSecretAccessListDTO = {
workspaceId: string;
projectId: string;
environment: string;
secretPath: string;
secretKey: string;
@@ -174,14 +150,14 @@ export type TCreateSecretsV3DTO = {
secretComment: string;
skipMultilineEncoding?: boolean;
secretPath: string;
workspaceId: string;
projectId: string;
environment: string;
type: SecretType;
tagIds?: string[];
};
export type TUpdateSecretsV3DTO = {
workspaceId: string;
projectId: string;
environment: string;
secretPath: string;
type: SecretType;
@@ -198,7 +174,7 @@ export type TUpdateSecretsV3DTO = {
};
export type TDeleteSecretsV3DTO = {
workspaceId: string;
projectId: string;
environment: string;
type: SecretType;
secretPath: string;
@@ -207,7 +183,7 @@ export type TDeleteSecretsV3DTO = {
};
export type TCreateSecretBatchDTO = {
workspaceId: string;
projectId: string;
environment: string;
secretPath: string;
secrets: Array<{
@@ -224,7 +200,7 @@ export type TCreateSecretBatchDTO = {
};
export type TUpdateSecretBatchDTO = {
workspaceId: string;
projectId: string;
environment: string;
secretPath: string;
secrets: Array<{
@@ -241,7 +217,7 @@ export type TUpdateSecretBatchDTO = {
};
export type TDeleteSecretBatchDTO = {
workspaceId: string;
projectId: string;
environment: string;
secretPath: string;
secrets: Array<{