fix(api): передавать наблюдаемые состояния сертификатов

This commit is contained in:
Denozordec committed 2026-10-01 11:18:32 +07:00
1 parent 71cc6fa3a7
commit 26869632a0
9 files changed
+151 -5

No files matched your search

+30
View File
@@ -127,3 +127,33 @@ export type CertificateIssueRequest = z.infer<typeof certificateIssueRequestSche
export type CertificateIssueJob = z.infer<typeof certificateIssueJobSchema>
export type AcmeCloudflareSettingsDto = z.infer<typeof acmeCloudflareSettingsDtoSchema>
export type CertificateRenewSettingsDto = z.infer<typeof certificateRenewSettingsDtoSchema>
export const certificateObservedSchema = certificateDtoSchema.extend({
rosId: z.string().min(1).nullable(),
validFrom: z.string().datetime({ offset: true }).nullable(),
validUntil: z.string().datetime({ offset: true }).nullable(),
rawValidFrom: z.string().nullable(), rawValidUntil: z.string().nullable(),
daysLeft: z.number().int().nullable(), keySize: z.number().int().positive().nullable(),
trusted: z.boolean().nullable(), status: z.enum(["valid", "expired", "revoked", "unknown"]),
}).superRefine((value,ctx) => {
if ((value.validUntil === null) !== (value.daysLeft === null)) ctx.addIssue({code:"custom",message:"Срок не соответствует дате"})
if (value.status === "valid" && (!value.validFrom || !value.validUntil || value.daysLeft === null || value.daysLeft < 0 || Date.parse(value.validFrom)>Date.parse(value.validUntil))) ctx.addIssue({code:"custom",message:"Действительность не подтверждена датами"})
})
export const certificateServerStateSchema = z.object({
serverId: z.string().regex(/^[1-9]\d*$/).refine(value => Number.isSafeInteger(Number(value))),
serverName: z.string(), collectedAt: z.string().datetime({ offset: true }),
certificates: z.array(certificateObservedSchema),
error: z.string().min(1).nullable(),
}).superRefine((value,ctx) => {
if (value.error && value.certificates.length) ctx.addIssue({code:"custom",message:"Ошибка загрузки содержит сертификаты"})
if (new Set(value.certificates.map(row=>row.id)).size !== value.certificates.length) ctx.addIssue({code:"custom",message:"Дубли сертификатов"})
if (value.certificates.some(row=>row.serverId !== value.serverId || !row.id.startsWith(value.serverId + ":"))) ctx.addIssue({code:"custom",message:"Чужой контекст сертификата"})
})
export const certificatesStateSchema = z.object({
collectedAt: z.string().datetime({ offset: true }), servers: z.array(certificateServerStateSchema),
}).superRefine((value,ctx) => {
if(new Set(value.servers.map(server=>server.serverId)).size!==value.servers.length)ctx.addIssue({code:"custom",message:"Дубли устройств"})
})
export type CertificateObserved = z.infer<typeof certificateObservedSchema>
export type CertificateServerState = z.infer<typeof certificateServerStateSchema>
export type CertificatesState = z.infer<typeof certificatesStateSchema>