misc: finalized descriptions and api reference

This commit is contained in:
Sheen Capadngan
2025-05-18 22:22:00 +08:00
parent e0f1311f6d
commit 10ed6f6b52
12 changed files with 123 additions and 38 deletions
@@ -1,5 +1,7 @@
import { z } from "zod";
import { CertificateAuthorities } from "@app/lib/api-docs/constants";
import { CaType } from "../certificate-authority-enums";
import {
BaseCertificateAuthoritySchema,
@@ -9,21 +11,21 @@ import {
import { AcmeDnsProvider } from "./acme-certificate-authority-enums";
export const AcmeCertificateAuthorityConfigurationSchema = z.object({
dnsAppConnectionId: z.string().trim(),
dnsAppConnectionId: z.string().trim().describe(CertificateAuthorities.CONFIGURATIONS.ACME.dnsAppConnectionId),
// soon, differentiate via the provider property
dnsProviderConfig: z.object({
provider: z.nativeEnum(AcmeDnsProvider),
hostedZoneId: z.string().trim().min(1)
provider: z.nativeEnum(AcmeDnsProvider).describe(CertificateAuthorities.CONFIGURATIONS.ACME.provider),
hostedZoneId: z.string().trim().min(1).describe(CertificateAuthorities.CONFIGURATIONS.ACME.hostedZoneId)
}),
directoryUrl: z.string().trim().min(1),
accountEmail: z.string().trim().min(1)
directoryUrl: z.string().trim().min(1).describe(CertificateAuthorities.CONFIGURATIONS.ACME.directoryUrl),
accountEmail: z.string().trim().min(1).describe(CertificateAuthorities.CONFIGURATIONS.ACME.accountEmail)
});
export const AcmeCertificateAuthorityCredentialsSchema = z.object({
accountKey: z.string()
});
export const AcmeCertificateAuthoritySchema = BaseCertificateAuthoritySchema(CaType.ACME).extend({
export const AcmeCertificateAuthoritySchema = BaseCertificateAuthoritySchema.extend({
type: z.literal(CaType.ACME),
configuration: AcmeCertificateAuthorityConfigurationSchema
});
@@ -0,0 +1,6 @@
import { CaType } from "./certificate-authority-enums";
export const CERTIFICATE_AUTHORITIES_TYPE_MAP: Record<CaType, string> = {
[CaType.INTERNAL]: "Internal",
[CaType.ACME]: "ACME"
};
@@ -1,32 +1,31 @@
import z from "zod";
import { CertificateAuthoritiesSchema } from "@app/db/schemas";
import { CertificateAuthorities } from "@app/lib/api-docs/constants";
import { slugSchema } from "@app/server/lib/schemas";
import { CaStatus, CaType } from "./certificate-authority-enums";
// SHEEN TODO: add description mapping using type
export const BaseCertificateAuthoritySchema = (type: CaType) =>
CertificateAuthoritiesSchema.pick({
projectId: true,
disableDirectIssuance: true,
id: true
}).extend({
name: z.string(),
status: z.nativeEnum(CaStatus)
});
export const BaseCertificateAuthoritySchema = CertificateAuthoritiesSchema.pick({
projectId: true,
disableDirectIssuance: true,
id: true
}).extend({
name: z.string(),
status: z.nativeEnum(CaStatus)
});
export const GenericCreateCertificateAuthorityFieldsSchema = (type: CaType) =>
z.object({
name: slugSchema({ field: "name" }),
projectId: z.string().trim().min(1, "Project ID required"),
disableDirectIssuance: z.boolean(),
status: z.nativeEnum(CaStatus)
name: slugSchema({ field: "name" }).describe(CertificateAuthorities.CREATE(type).name),
projectId: z.string().trim().min(1, "Project ID required").describe(CertificateAuthorities.CREATE(type).projectId),
disableDirectIssuance: z.boolean().describe(CertificateAuthorities.CREATE(type).disableDirectIssuance),
status: z.nativeEnum(CaStatus).describe(CertificateAuthorities.CREATE(type).status)
});
export const GenericUpdateCertificateAuthorityFieldsSchema = (type: CaType) =>
z.object({
name: slugSchema({ field: "name" }).optional(),
disableDirectIssuance: z.boolean().optional(),
status: z.nativeEnum(CaStatus).optional()
name: slugSchema({ field: "name" }).optional().describe(CertificateAuthorities.UPDATE(type).name),
disableDirectIssuance: z.boolean().optional().describe(CertificateAuthorities.UPDATE(type).disableDirectIssuance),
status: z.nativeEnum(CaStatus).optional().describe(CertificateAuthorities.UPDATE(type).status)
});
@@ -1,5 +1,6 @@
import { z } from "zod";
import { CertificateAuthorities } from "@app/lib/api-docs/constants";
import { CertKeyAlgorithm } from "@app/services/certificate/certificate-types";
import { CaType, InternalCaType } from "../certificate-authority-enums";
@@ -12,22 +13,24 @@ import { validateCaDateField } from "../certificate-authority-validators";
const InternalCertificateAuthorityConfigurationSchema = z
.object({
type: z.nativeEnum(InternalCaType),
friendlyName: z.string().optional(),
commonName: z.string().trim(),
organization: z.string().trim(),
ou: z.string().trim(),
type: z.nativeEnum(InternalCaType).describe(CertificateAuthorities.CONFIGURATIONS.INTERNAL.type),
friendlyName: z.string().optional().describe(CertificateAuthorities.CONFIGURATIONS.INTERNAL.friendlyName),
commonName: z.string().trim().describe(CertificateAuthorities.CONFIGURATIONS.INTERNAL.commonName),
organization: z.string().trim().describe(CertificateAuthorities.CONFIGURATIONS.INTERNAL.organization),
ou: z.string().trim().describe(CertificateAuthorities.CONFIGURATIONS.INTERNAL.ou),
country: z.string().trim().describe(CertificateAuthorities.CONFIGURATIONS.INTERNAL.country),
province: z.string().trim().describe(CertificateAuthorities.CONFIGURATIONS.INTERNAL.province),
locality: z.string().trim().describe(CertificateAuthorities.CONFIGURATIONS.INTERNAL.locality),
notBefore: validateCaDateField.optional().describe(CertificateAuthorities.CONFIGURATIONS.INTERNAL.notBefore),
notAfter: validateCaDateField.optional().describe(CertificateAuthorities.CONFIGURATIONS.INTERNAL.notAfter),
maxPathLength: z.number().min(-1).describe(CertificateAuthorities.CONFIGURATIONS.INTERNAL.maxPathLength),
keyAlgorithm: z.nativeEnum(CertKeyAlgorithm).describe(CertificateAuthorities.CONFIGURATIONS.INTERNAL.keyAlgorithm),
// no need for descriptions of the following fields because they are not exposed to the API user
dn: z.string().trim(),
parentCaId: z.string().uuid().nullish(),
serialNumber: z.string().trim().optional(),
activeCaCertId: z.string().uuid().optional(),
country: z.string().trim(),
province: z.string().trim(),
locality: z.string().trim(),
notBefore: validateCaDateField.optional(),
notAfter: validateCaDateField.optional(),
maxPathLength: z.number().min(-1),
keyAlgorithm: z.nativeEnum(CertKeyAlgorithm)
activeCaCertId: z.string().uuid().optional()
})
.refine(
(data) => {
@@ -43,7 +46,7 @@ const InternalCertificateAuthorityConfigurationSchema = z
}
);
export const InternalCertificateAuthoritySchema = BaseCertificateAuthoritySchema(CaType.INTERNAL).extend({
export const InternalCertificateAuthoritySchema = BaseCertificateAuthoritySchema.extend({
type: z.literal(CaType.INTERNAL),
configuration: InternalCertificateAuthorityConfigurationSchema
});