feat(server): switched from workspace id to project slug

This commit is contained in:
Akhil Mohan
2024-04-22 21:19:06 +05:30
parent a339c473d5
commit aa5cd0fd0f
5 changed files with 42 additions and 24 deletions
+3 -3
View File
@@ -945,7 +945,7 @@ describe.each([{ auth: AuthMode.JWT }, { auth: AuthMode.IDENTITY_ACCESS_TOKEN }]
test.each(testRawSecrets)("Bulk create secret raw in path $path", async ({ path, secret }) => { test.each(testRawSecrets)("Bulk create secret raw in path $path", async ({ path, secret }) => {
const createSecretReqBody = { const createSecretReqBody = {
workspaceId: seedData1.project.id, projectSlug: seedData1.project.slug,
environment: seedData1.environment.slug, environment: seedData1.environment.slug,
secretPath: path, secretPath: path,
secrets: [ secrets: [
@@ -986,7 +986,7 @@ describe.each([{ auth: AuthMode.JWT }, { auth: AuthMode.IDENTITY_ACCESS_TOKEN }]
test.each(testRawSecrets)("Bulk update secret raw in path $path", async ({ secret, path }) => { test.each(testRawSecrets)("Bulk update secret raw in path $path", async ({ secret, path }) => {
await createRawSecret({ path, ...secret }); await createRawSecret({ path, ...secret });
const updateSecretReqBody = { const updateSecretReqBody = {
workspaceId: seedData1.project.id, projectSlug: seedData1.project.slug,
environment: seedData1.environment.slug, environment: seedData1.environment.slug,
secretPath: path, secretPath: path,
secrets: [ secrets: [
@@ -1028,7 +1028,7 @@ describe.each([{ auth: AuthMode.JWT }, { auth: AuthMode.IDENTITY_ACCESS_TOKEN }]
await createRawSecret({ path, ...secret }); await createRawSecret({ path, ...secret });
const deletedSecretReqBody = { const deletedSecretReqBody = {
workspaceId: seedData1.project.id, projectSlug: seedData1.project.slug,
environment: seedData1.environment.slug, environment: seedData1.environment.slug,
secretPath: path, secretPath: path,
secrets: [{ secretKey: secret.key }] secrets: [{ secretKey: secret.key }]
+3
View File
@@ -282,6 +282,7 @@ export const RAW_SECRETS = {
}, },
CREATE: { CREATE: {
secretName: "The name of the secret to create.", secretName: "The name of the secret to create.",
projectSlug: "The slug of the project to create the secret in.",
environment: "The slug of the environment to create the secret in.", environment: "The slug of the environment to create the secret in.",
secretComment: "Attach a comment to the secret.", secretComment: "Attach a comment to the secret.",
secretPath: "The path to create the secret in.", secretPath: "The path to create the secret in.",
@@ -307,6 +308,7 @@ export const RAW_SECRETS = {
secretValue: "The new value of the secret.", secretValue: "The new value of the secret.",
skipMultilineEncoding: "Skip multiline encoding for the secret value.", skipMultilineEncoding: "Skip multiline encoding for the secret value.",
type: "The type of the secret to update.", 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." workspaceId: "The ID of the project to update the secret in."
}, },
DELETE: { DELETE: {
@@ -314,6 +316,7 @@ export const RAW_SECRETS = {
environment: "The slug of the environment where the secret is located.", environment: "The slug of the environment where the secret is located.",
secretPath: "The path of the secret.", secretPath: "The path of the secret.",
type: "The type of the secret to delete.", 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." workspaceId: "The ID of the project where the secret is located."
} }
} as const; } as const;
+15 -15
View File
@@ -1671,7 +1671,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
} }
], ],
body: z.object({ body: z.object({
workspaceId: z.string().trim().describe(RAW_SECRETS.CREATE.workspaceId), projectSlug: z.string().trim().describe(RAW_SECRETS.CREATE.projectSlug),
environment: z.string().trim().describe(RAW_SECRETS.CREATE.environment), environment: z.string().trim().describe(RAW_SECRETS.CREATE.environment),
secretPath: z secretPath: z
.string() .string()
@@ -1700,7 +1700,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
}, },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.SERVICE_TOKEN, AuthMode.IDENTITY_ACCESS_TOKEN]), onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.SERVICE_TOKEN, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => { handler: async (req) => {
const { environment, workspaceId: projectId, secretPath, secrets: inputSecrets } = req.body; const { environment, projectSlug, secretPath, secrets: inputSecrets } = req.body;
const secrets = await server.services.secret.createManySecretsRaw({ const secrets = await server.services.secret.createManySecretsRaw({
actorId: req.permission.id, actorId: req.permission.id,
@@ -1709,12 +1709,12 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
secretPath, secretPath,
environment, environment,
projectId, projectSlug,
secrets: inputSecrets secrets: inputSecrets
}); });
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
projectId: req.body.workspaceId, projectId: secrets[0].workspace,
...req.auditLogInfo, ...req.auditLogInfo,
event: { event: {
type: EventType.CREATE_SECRETS, type: EventType.CREATE_SECRETS,
@@ -1735,7 +1735,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
distinctId: getTelemetryDistinctId(req), distinctId: getTelemetryDistinctId(req),
properties: { properties: {
numberOfSecrets: secrets.length, numberOfSecrets: secrets.length,
workspaceId: req.body.workspaceId, workspaceId: secrets[0].workspace,
environment: req.body.environment, environment: req.body.environment,
secretPath: req.body.secretPath, secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]), channel: getUserAgentType(req.headers["user-agent"]),
@@ -1760,7 +1760,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
} }
], ],
body: z.object({ body: z.object({
workspaceId: z.string().trim().describe(RAW_SECRETS.UPDATE.workspaceId), projectSlug: z.string().trim().describe(RAW_SECRETS.UPDATE.projectSlug),
environment: z.string().trim().describe(RAW_SECRETS.UPDATE.environment), environment: z.string().trim().describe(RAW_SECRETS.UPDATE.environment),
secretPath: z secretPath: z
.string() .string()
@@ -1789,7 +1789,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
}, },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.SERVICE_TOKEN, AuthMode.IDENTITY_ACCESS_TOKEN]), onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.SERVICE_TOKEN, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => { handler: async (req) => {
const { environment, workspaceId: projectId, secretPath, secrets: inputSecrets } = req.body; const { environment, projectSlug, secretPath, secrets: inputSecrets } = req.body;
const secrets = await server.services.secret.updateManySecretsRaw({ const secrets = await server.services.secret.updateManySecretsRaw({
actorId: req.permission.id, actorId: req.permission.id,
actor: req.permission.type, actor: req.permission.type,
@@ -1797,12 +1797,12 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
secretPath, secretPath,
environment, environment,
projectId, projectSlug,
secrets: inputSecrets secrets: inputSecrets
}); });
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
projectId: req.body.workspaceId, projectId: secrets[0].workspace,
...req.auditLogInfo, ...req.auditLogInfo,
event: { event: {
type: EventType.UPDATE_SECRETS, type: EventType.UPDATE_SECRETS,
@@ -1823,7 +1823,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
distinctId: getTelemetryDistinctId(req), distinctId: getTelemetryDistinctId(req),
properties: { properties: {
numberOfSecrets: secrets.length, numberOfSecrets: secrets.length,
workspaceId: req.body.workspaceId, workspaceId: secrets[0].workspace,
environment: req.body.environment, environment: req.body.environment,
secretPath: req.body.secretPath, secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]), channel: getUserAgentType(req.headers["user-agent"]),
@@ -1848,7 +1848,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
} }
], ],
body: z.object({ body: z.object({
workspaceId: z.string().trim().describe(RAW_SECRETS.DELETE.workspaceId), projectSlug: z.string().trim().describe(RAW_SECRETS.DELETE.projectSlug),
environment: z.string().trim().describe(RAW_SECRETS.DELETE.environment), environment: z.string().trim().describe(RAW_SECRETS.DELETE.environment),
secretPath: z secretPath: z
.string() .string()
@@ -1871,20 +1871,20 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
}, },
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.SERVICE_TOKEN, AuthMode.IDENTITY_ACCESS_TOKEN]), onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.SERVICE_TOKEN, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => { handler: async (req) => {
const { environment, workspaceId: projectId, secretPath, secrets: inputSecrets } = req.body; const { environment, projectSlug, secretPath, secrets: inputSecrets } = req.body;
const secrets = await server.services.secret.deleteManySecretsRaw({ const secrets = await server.services.secret.deleteManySecretsRaw({
actorId: req.permission.id, actorId: req.permission.id,
actor: req.permission.type, actor: req.permission.type,
actorAuthMethod: req.permission.authMethod, actorAuthMethod: req.permission.authMethod,
actorOrgId: req.permission.orgId, actorOrgId: req.permission.orgId,
environment, environment,
projectId, projectSlug,
secretPath, secretPath,
secrets: inputSecrets secrets: inputSecrets
}); });
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
projectId: req.body.workspaceId, projectId: secrets[0].workspace,
...req.auditLogInfo, ...req.auditLogInfo,
event: { event: {
type: EventType.DELETE_SECRETS, type: EventType.DELETE_SECRETS,
@@ -1905,7 +1905,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
distinctId: getTelemetryDistinctId(req), distinctId: getTelemetryDistinctId(req),
properties: { properties: {
numberOfSecrets: secrets.length, numberOfSecrets: secrets.length,
workspaceId: req.body.workspaceId, workspaceId: secrets[0].workspace,
environment: req.body.environment, environment: req.body.environment,
secretPath: req.body.secretPath, secretPath: req.body.secretPath,
channel: getUserAgentType(req.headers["user-agent"]), channel: getUserAgentType(req.headers["user-agent"]),
+15 -3
View File
@@ -1041,7 +1041,7 @@ export const secretServiceFactory = ({
const createManySecretsRaw = async ({ const createManySecretsRaw = async ({
actorId, actorId,
projectId, projectSlug,
environment, environment,
actor, actor,
actorOrgId, actorOrgId,
@@ -1049,6 +1049,10 @@ export const secretServiceFactory = ({
secretPath, secretPath,
secrets: inputSecrets = [] secrets: inputSecrets = []
}: TCreateManySecretRawDTO) => { }: TCreateManySecretRawDTO) => {
const project = await projectDAL.findProjectBySlug(projectSlug, actorOrgId);
if (!project) throw new BadRequestError({ message: "Project not found" });
const projectId = project.id;
const botKey = await projectBotService.getBotKey(projectId); const botKey = await projectBotService.getBotKey(projectId);
if (!botKey) throw new BadRequestError({ message: "Project bot not found", name: "bot_not_found_error" }); if (!botKey) throw new BadRequestError({ message: "Project bot not found", name: "bot_not_found_error" });
@@ -1088,7 +1092,7 @@ export const secretServiceFactory = ({
const updateManySecretsRaw = async ({ const updateManySecretsRaw = async ({
actorId, actorId,
projectId, projectSlug,
environment, environment,
actor, actor,
actorOrgId, actorOrgId,
@@ -1096,6 +1100,10 @@ export const secretServiceFactory = ({
secretPath, secretPath,
secrets: inputSecrets = [] secrets: inputSecrets = []
}: TUpdateManySecretRawDTO) => { }: TUpdateManySecretRawDTO) => {
const project = await projectDAL.findProjectBySlug(projectSlug, actorOrgId);
if (!project) throw new BadRequestError({ message: "Project not found" });
const projectId = project.id;
const botKey = await projectBotService.getBotKey(projectId); const botKey = await projectBotService.getBotKey(projectId);
if (!botKey) throw new BadRequestError({ message: "Project bot not found", name: "bot_not_found_error" }); if (!botKey) throw new BadRequestError({ message: "Project bot not found", name: "bot_not_found_error" });
@@ -1136,7 +1144,7 @@ export const secretServiceFactory = ({
const deleteManySecretsRaw = async ({ const deleteManySecretsRaw = async ({
actorId, actorId,
projectId, projectSlug,
environment, environment,
actor, actor,
actorOrgId, actorOrgId,
@@ -1144,6 +1152,10 @@ export const secretServiceFactory = ({
secretPath, secretPath,
secrets: inputSecrets = [] secrets: inputSecrets = []
}: TDeleteManySecretRawDTO) => { }: TDeleteManySecretRawDTO) => {
const project = await projectDAL.findProjectBySlug(projectSlug, actorOrgId);
if (!project) throw new BadRequestError({ message: "Project not found" });
const projectId = project.id;
const botKey = await projectBotService.getBotKey(projectId); const botKey = await projectBotService.getBotKey(projectId);
if (!botKey) throw new BadRequestError({ message: "Project bot not found", name: "bot_not_found_error" }); if (!botKey) throw new BadRequestError({ message: "Project bot not found", name: "bot_not_found_error" });
+6 -3
View File
@@ -181,8 +181,9 @@ export type TDeleteSecretRawDTO = TProjectPermission & {
type: SecretType; type: SecretType;
}; };
export type TCreateManySecretRawDTO = TProjectPermission & { export type TCreateManySecretRawDTO = Omit<TProjectPermission, "projectId"> & {
secretPath: string; secretPath: string;
projectSlug: string;
environment: string; environment: string;
secrets: { secrets: {
secretKey: string; secretKey: string;
@@ -192,8 +193,9 @@ export type TCreateManySecretRawDTO = TProjectPermission & {
}[]; }[];
}; };
export type TUpdateManySecretRawDTO = TProjectPermission & { export type TUpdateManySecretRawDTO = Omit<TProjectPermission, "projectId"> & {
secretPath: string; secretPath: string;
projectSlug: string;
environment: string; environment: string;
secrets: { secrets: {
secretKey: string; secretKey: string;
@@ -203,8 +205,9 @@ export type TUpdateManySecretRawDTO = TProjectPermission & {
}[]; }[];
}; };
export type TDeleteManySecretRawDTO = TProjectPermission & { export type TDeleteManySecretRawDTO = Omit<TProjectPermission, "projectId"> & {
secretPath: string; secretPath: string;
projectSlug: string;
environment: string; environment: string;
secrets: { secrets: {
secretKey: string; secretKey: string;