mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 15:27:27 +00:00
Fix ts
This commit is contained in:
@@ -21,23 +21,33 @@ import {
|
|||||||
import { ApiDocsTags } from "@app/lib/api-docs";
|
import { ApiDocsTags } from "@app/lib/api-docs";
|
||||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
||||||
|
|
||||||
|
const SharedParamsSchema = z.object({
|
||||||
|
profileId: z.string().uuid()
|
||||||
|
});
|
||||||
|
|
||||||
|
export interface MyRequestInterface {
|
||||||
|
Params: { profileId: string; accountId?: string };
|
||||||
|
Body: TRawJwsPayload;
|
||||||
|
}
|
||||||
|
|
||||||
export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
||||||
const validateExistingAccount = async <
|
const validateExistingAccount = async <
|
||||||
|
R extends FastifyRequest<any>,
|
||||||
TSchema extends z.ZodSchema<any> | undefined = undefined,
|
TSchema extends z.ZodSchema<any> | undefined = undefined,
|
||||||
T = TSchema extends z.ZodSchema<infer R> ? R : string
|
T = TSchema extends z.ZodSchema<infer R> ? R : string
|
||||||
>({
|
>({
|
||||||
req,
|
req,
|
||||||
schema
|
schema
|
||||||
}: {
|
}: {
|
||||||
req: FastifyRequest<{ Params: { profileId: string; accountId?: string }; Body: TRawJwsPayload }>;
|
req: R;
|
||||||
schema?: TSchema;
|
schema?: TSchema;
|
||||||
}): Promise<TAuthenciatedJwsPayload<T>> => {
|
}): Promise<TAuthenciatedJwsPayload<T>> => {
|
||||||
return await server.services.pkiAcme.validateExistingAccountJwsPayload({
|
return await server.services.pkiAcme.validateExistingAccountJwsPayload({
|
||||||
url: new URL(req.url, `${req.protocol}://${req.hostname}`),
|
url: new URL(req.url, `${req.protocol}://${req.hostname}`),
|
||||||
profileId: req.params.profileId,
|
profileId: (req.params as { profileId: string }).profileId,
|
||||||
rawJwsPayload: req.body,
|
rawJwsPayload: req.body as TRawJwsPayload,
|
||||||
schema,
|
schema,
|
||||||
expectedAccountId: req.params.accountId
|
expectedAccountId: (req.params as { accountId?: string }).accountId
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -131,9 +141,7 @@ export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
|||||||
hide: false,
|
hide: false,
|
||||||
tags: [ApiDocsTags.PkiAcme],
|
tags: [ApiDocsTags.PkiAcme],
|
||||||
description: "ACME New Account - register a new account or find existing one",
|
description: "ACME New Account - register a new account or find existing one",
|
||||||
params: z.object({
|
params: SharedParamsSchema,
|
||||||
profileId: z.string().uuid()
|
|
||||||
}),
|
|
||||||
body: RawJwsPayloadSchema,
|
body: RawJwsPayloadSchema,
|
||||||
response: {
|
response: {
|
||||||
201: CreateAcmeAccountResponseSchema
|
201: CreateAcmeAccountResponseSchema
|
||||||
@@ -141,7 +149,7 @@ export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
|||||||
},
|
},
|
||||||
handler: async (req, res) => {
|
handler: async (req, res) => {
|
||||||
const { payload, protectedHeader } = await server.services.pkiAcme.validateNewAccountJwsPayload({
|
const { payload, protectedHeader } = await server.services.pkiAcme.validateNewAccountJwsPayload({
|
||||||
url: req.url,
|
url: new URL(req.url, `${req.protocol}://${req.hostname}`),
|
||||||
rawJwsPayload: req.body
|
rawJwsPayload: req.body
|
||||||
});
|
});
|
||||||
const { alg, jwk } = protectedHeader;
|
const { alg, jwk } = protectedHeader;
|
||||||
@@ -170,8 +178,7 @@ export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
|||||||
hide: false,
|
hide: false,
|
||||||
tags: [ApiDocsTags.PkiAcme],
|
tags: [ApiDocsTags.PkiAcme],
|
||||||
description: "ACME Account Deactivation",
|
description: "ACME Account Deactivation",
|
||||||
params: z.object({
|
params: SharedParamsSchema.extend({
|
||||||
profileId: z.string().uuid(),
|
|
||||||
accountId: z.string()
|
accountId: z.string()
|
||||||
}),
|
}),
|
||||||
body: RawJwsPayloadSchema,
|
body: RawJwsPayloadSchema,
|
||||||
@@ -210,9 +217,7 @@ export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
|||||||
hide: false,
|
hide: false,
|
||||||
tags: [ApiDocsTags.PkiAcme],
|
tags: [ApiDocsTags.PkiAcme],
|
||||||
description: "ACME New Order - apply for a new certificate",
|
description: "ACME New Order - apply for a new certificate",
|
||||||
params: z.object({
|
params: SharedParamsSchema,
|
||||||
profileId: z.string().uuid()
|
|
||||||
}),
|
|
||||||
body: RawJwsPayloadSchema,
|
body: RawJwsPayloadSchema,
|
||||||
response: {
|
response: {
|
||||||
201: AcmeOrderResourceSchema
|
201: AcmeOrderResourceSchema
|
||||||
@@ -249,8 +254,7 @@ export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
|||||||
hide: false,
|
hide: false,
|
||||||
tags: [ApiDocsTags.PkiAcme],
|
tags: [ApiDocsTags.PkiAcme],
|
||||||
description: "ACME Get Order - return status and details of the order",
|
description: "ACME Get Order - return status and details of the order",
|
||||||
params: z.object({
|
params: SharedParamsSchema.extend({
|
||||||
profileId: z.string().uuid(),
|
|
||||||
orderId: z.string().uuid()
|
orderId: z.string().uuid()
|
||||||
}),
|
}),
|
||||||
body: RawJwsPayloadSchema,
|
body: RawJwsPayloadSchema,
|
||||||
@@ -289,8 +293,7 @@ export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
|||||||
hide: false,
|
hide: false,
|
||||||
tags: [ApiDocsTags.PkiAcme],
|
tags: [ApiDocsTags.PkiAcme],
|
||||||
description: "ACME Finalize Order - finalize cert order by providing CSR",
|
description: "ACME Finalize Order - finalize cert order by providing CSR",
|
||||||
params: z.object({
|
params: SharedParamsSchema.extend({
|
||||||
profileId: z.string().uuid(),
|
|
||||||
orderId: z.string().uuid()
|
orderId: z.string().uuid()
|
||||||
}),
|
}),
|
||||||
body: RawJwsPayloadSchema,
|
body: RawJwsPayloadSchema,
|
||||||
@@ -329,8 +332,7 @@ export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
|||||||
hide: false,
|
hide: false,
|
||||||
tags: [ApiDocsTags.PkiAcme],
|
tags: [ApiDocsTags.PkiAcme],
|
||||||
description: "ACME List Orders - get existing orders from current account",
|
description: "ACME List Orders - get existing orders from current account",
|
||||||
params: z.object({
|
params: SharedParamsSchema.extend({
|
||||||
profileId: z.string().uuid(),
|
|
||||||
accountId: z.string()
|
accountId: z.string()
|
||||||
}),
|
}),
|
||||||
body: RawJwsPayloadSchema,
|
body: RawJwsPayloadSchema,
|
||||||
@@ -368,8 +370,7 @@ export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
|||||||
hide: false,
|
hide: false,
|
||||||
tags: [ApiDocsTags.PkiAcme],
|
tags: [ApiDocsTags.PkiAcme],
|
||||||
description: "ACME Download Certificate - download certificate when ready",
|
description: "ACME Download Certificate - download certificate when ready",
|
||||||
params: z.object({
|
params: SharedParamsSchema.extend({
|
||||||
profileId: z.string().uuid(),
|
|
||||||
orderId: z.string().uuid()
|
orderId: z.string().uuid()
|
||||||
}),
|
}),
|
||||||
body: RawJwsPayloadSchema,
|
body: RawJwsPayloadSchema,
|
||||||
@@ -404,8 +405,7 @@ export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
|||||||
hide: false,
|
hide: false,
|
||||||
tags: [ApiDocsTags.PkiAcme],
|
tags: [ApiDocsTags.PkiAcme],
|
||||||
description: "ACME Identifier Authorization - get authorization info (challenges)",
|
description: "ACME Identifier Authorization - get authorization info (challenges)",
|
||||||
params: z.object({
|
params: SharedParamsSchema.extend({
|
||||||
profileId: z.string().uuid(),
|
|
||||||
authzId: z.string().uuid()
|
authzId: z.string().uuid()
|
||||||
}),
|
}),
|
||||||
body: RawJwsPayloadSchema,
|
body: RawJwsPayloadSchema,
|
||||||
@@ -447,8 +447,7 @@ export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
|||||||
hide: false,
|
hide: false,
|
||||||
tags: [ApiDocsTags.PkiAcme],
|
tags: [ApiDocsTags.PkiAcme],
|
||||||
description: "ACME Respond to Challenge - let ACME server know challenge is ready",
|
description: "ACME Respond to Challenge - let ACME server know challenge is ready",
|
||||||
params: z.object({
|
params: SharedParamsSchema.extend({
|
||||||
profileId: z.string().uuid(),
|
|
||||||
authzId: z.string().uuid()
|
authzId: z.string().uuid()
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
|
|||||||
Reference in New Issue
Block a user