From bfa533e9d25fe001bb1de100f3f53590b30f10cc Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Wed, 11 Sep 2024 22:59:19 +0800 Subject: [PATCH] misc: api property description --- backend/src/lib/api-docs/constants.ts | 14 ++++++++--- .../server/routes/v1/certificate-router.ts | 24 +++++++++++++++---- .../routes/v1/certificate-template-router.ts | 18 ++++++++++---- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts index b08c70d93..8970b3152 100644 --- a/backend/src/lib/api-docs/constants.ts +++ b/backend/src/lib/api-docs/constants.ts @@ -1110,11 +1110,15 @@ export const CERTIFICATE_AUTHORITIES = { issuingCaCertificate: "The certificate of the issuing CA", certificateChain: "The certificate chain of the issued certificate", privateKey: "The private key of the issued certificate", - serialNumber: "The serial number of the issued certificate" + serialNumber: "The serial number of the issued certificate", + keyUsages: "The key usage extension of the certificate", + extendedKeyUsages: "The extended key usage extension of the certificate" }, SIGN_CERT: { caId: "The ID of the CA to issue the certificate from", pkiCollectionId: "The ID of the PKI collection to add the certificate to", + keyUsages: "The key usage extension of the certificate", + extendedKeyUsages: "The extended key usage extension of the certificate", csr: "The pem-encoded CSR to sign with the CA to be used for certificate issuance", friendlyName: "A friendly name for the certificate", commonName: "The common name (CN) for the certificate", @@ -1164,7 +1168,9 @@ export const CERTIFICATE_TEMPLATES = { name: "The name of the template", commonName: "The regular expression string to use for validating common names", subjectAlternativeName: "The regular expression string to use for validating subject alternative names", - ttl: "The max TTL for the template" + ttl: "The max TTL for the template", + keyUsages: "The key usage constraint or default value", + extendedKeyUsages: "The extended key usage constraint or default value" }, GET: { certificateTemplateId: "The ID of the certificate template to get" @@ -1176,7 +1182,9 @@ export const CERTIFICATE_TEMPLATES = { name: "The updated name of the template", commonName: "The updated regular expression string for validating common names", subjectAlternativeName: "The updated regular expression string for validating subject alternative names", - ttl: "The updated max TTL for the template" + ttl: "The updated max TTL for the template", + keyUsages: "The updated key usage constraint or default value", + extendedKeyUsages: "The updated extended key usage constraint or default value" }, DELETE: { certificateTemplateId: "The ID of the certificate template to delete" diff --git a/backend/src/server/routes/v1/certificate-router.ts b/backend/src/server/routes/v1/certificate-router.ts index b13a790d5..99d57e802 100644 --- a/backend/src/server/routes/v1/certificate-router.ts +++ b/backend/src/server/routes/v1/certificate-router.ts @@ -87,8 +87,16 @@ export const registerCertRouter = async (server: FastifyZodProvider) => { .describe(CERTIFICATE_AUTHORITIES.ISSUE_CERT.ttl), notBefore: validateCaDateField.optional().describe(CERTIFICATE_AUTHORITIES.ISSUE_CERT.notBefore), notAfter: validateCaDateField.optional().describe(CERTIFICATE_AUTHORITIES.ISSUE_CERT.notAfter), - keyUsages: z.nativeEnum(CertKeyUsage).array().optional(), - extendedKeyUsages: z.nativeEnum(CertExtendedKeyUsage).array().optional() + keyUsages: z + .nativeEnum(CertKeyUsage) + .array() + .optional() + .describe(CERTIFICATE_AUTHORITIES.ISSUE_CERT.keyUsages), + extendedKeyUsages: z + .nativeEnum(CertExtendedKeyUsage) + .array() + .optional() + .describe(CERTIFICATE_AUTHORITIES.ISSUE_CERT.extendedKeyUsages) }) .refine( (data) => { @@ -180,8 +188,16 @@ export const registerCertRouter = async (server: FastifyZodProvider) => { .describe(CERTIFICATE_AUTHORITIES.SIGN_CERT.ttl), notBefore: validateCaDateField.optional().describe(CERTIFICATE_AUTHORITIES.SIGN_CERT.notBefore), notAfter: validateCaDateField.optional().describe(CERTIFICATE_AUTHORITIES.SIGN_CERT.notAfter), - keyUsages: z.nativeEnum(CertKeyUsage).array().optional(), - extendedKeyUsages: z.nativeEnum(CertExtendedKeyUsage).array().optional() + keyUsages: z + .nativeEnum(CertKeyUsage) + .array() + .optional() + .describe(CERTIFICATE_AUTHORITIES.SIGN_CERT.keyUsages), + extendedKeyUsages: z + .nativeEnum(CertExtendedKeyUsage) + .array() + .optional() + .describe(CERTIFICATE_AUTHORITIES.SIGN_CERT.extendedKeyUsages) }) .refine( (data) => { diff --git a/backend/src/server/routes/v1/certificate-template-router.ts b/backend/src/server/routes/v1/certificate-template-router.ts index c87639be1..54ce571a2 100644 --- a/backend/src/server/routes/v1/certificate-template-router.ts +++ b/backend/src/server/routes/v1/certificate-template-router.ts @@ -80,8 +80,14 @@ export const registerCertificateTemplateRouter = async (server: FastifyZodProvid .nativeEnum(CertKeyUsage) .array() .optional() - .default([CertKeyUsage.DIGITAL_SIGNATURE, CertKeyUsage.KEY_ENCIPHERMENT]), - extendedKeyUsages: z.nativeEnum(CertExtendedKeyUsage).array().optional().default([]) + .default([CertKeyUsage.DIGITAL_SIGNATURE, CertKeyUsage.KEY_ENCIPHERMENT]) + .describe(CERTIFICATE_TEMPLATES.CREATE.keyUsages), + extendedKeyUsages: z + .nativeEnum(CertExtendedKeyUsage) + .array() + .optional() + .default([]) + .describe(CERTIFICATE_TEMPLATES.CREATE.extendedKeyUsages) }), response: { 200: sanitizedCertificateTemplate @@ -138,8 +144,12 @@ export const registerCertificateTemplateRouter = async (server: FastifyZodProvid .refine((val) => ms(val) > 0, "TTL must be a positive number") .optional() .describe(CERTIFICATE_TEMPLATES.UPDATE.ttl), - keyUsages: z.nativeEnum(CertKeyUsage).array().optional(), - extendedKeyUsages: z.nativeEnum(CertExtendedKeyUsage).array().optional() + keyUsages: z.nativeEnum(CertKeyUsage).array().optional().describe(CERTIFICATE_TEMPLATES.UPDATE.keyUsages), + extendedKeyUsages: z + .nativeEnum(CertExtendedKeyUsage) + .array() + .optional() + .describe(CERTIFICATE_TEMPLATES.UPDATE.extendedKeyUsages) }), params: z.object({ certificateTemplateId: z.string().describe(CERTIFICATE_TEMPLATES.UPDATE.certificateTemplateId)