Skip to content

Commit 2eb42c5

Browse files
committed
fix: suggestion
Signed-off-by: Hemant M Mehta <[email protected]>
1 parent 4698868 commit 2eb42c5

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

backend/src/server/routes/v4/secret-router.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,13 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
391391
environment: z.string().trim().describe(RAW_SECRETS.CREATE.environment),
392392
secretPath: z.string().trim().default("/").transform(removeTrailingSlash).describe(RAW_SECRETS.CREATE.secretPath),
393393
type: z.nativeEnum(SecretType).default(SecretType.Shared).describe(RAW_SECRETS.CREATE.type),
394-
secretValue: z.string().describe(RAW_SECRETS.CREATE.secretValue),
395-
secretComment: z.string().default("").describe(RAW_SECRETS.CREATE.secretComment),
394+
secretValue: z.string().transform((val) => (val.at(-1) === "\n" ? `${val.trim()}\n` : val.trim())).describe(RAW_SECRETS.CREATE.secretValue),
395+
secretComment: z.string().trim().optional().default("").describe(RAW_SECRETS.CREATE.secretComment),
396396
tagIds: z.string().array().optional().describe(RAW_SECRETS.CREATE.tagIds),
397397
secretReminderNote: z.string().nullish().describe(RAW_SECRETS.CREATE.secretReminderNote),
398398
secretReminderRepeatDays: z.number().nullish().describe(RAW_SECRETS.CREATE.secretReminderRepeatDays),
399399
skipMultilineEncoding: z.boolean().optional().describe(RAW_SECRETS.CREATE.skipMultilineEncoding),
400-
secretMetadata: ResourceMetadataSchema.optional().describe(RAW_SECRETS.CREATE.secretMetadata)
400+
secretMetadata: ResourceMetadataSchema.optional(),
401401
}),
402402
response: {
403403
200: z.object({
@@ -413,31 +413,23 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
413413
handler: async (req) => {
414414
// Validate projectId exists
415415
const { projectId, environment, secretPath } = req.body;
416-
417-
if (!projectId) {
418-
throw new BadRequestError({
419-
message: "Missing projectId in request body",
420-
name: "CreateSecret"
421-
});
422-
}
423-
424-
if (!environment) {
425-
throw new BadRequestError({
426-
message: "Missing environment in request body",
427-
name: "CreateSecret"
428-
});
429-
}
430-
431416
const secret = await server.services.secret.createSecretRaw({
432417
actorId: req.permission.id,
433418
actor: req.permission.type,
434419
actorAuthMethod: req.permission.authMethod,
435420
actorOrgId: req.permission.orgId,
436421
projectId,
437422
environment,
438-
path: secretPath,
439-
...req.body,
440-
secretKey: req.params.secretName
423+
secretPath,
424+
secretName: req.params.secretName,
425+
type: req.body.type,
426+
secretValue: req.body.secretValue,
427+
secretComment: req.body.secretComment,
428+
skipMultilineEncoding: req.body.skipMultilineEncoding,
429+
tagIds: req.body.tagIds,
430+
secretReminderNote: req.body.secretReminderNote,
431+
secretReminderRepeatDays: req.body.secretReminderRepeatDays,
432+
secretMetadata: req.body.secretMetadata
441433
});
442434

443435
await server.services.auditLog.createAuditLog({

0 commit comments

Comments
 (0)