Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Extract fns

Fang-Pen Lin431fc222a129
diff --git a/backend/src/ee/services/pki-acme/pki-acme-fns.ts b/backend/src/ee/services/pki-acme/pki-acme-fns.ts
new file mode 100644
index 0000000000..0763a8ed06
--- /dev/null
+++ b/backend/src/ee/services/pki-acme/pki-acme-fns.ts
@@ -0,0 +1,17 @@
+import { getConfig } from "@app/lib/config/env";
+import { z } from "zod";
+import { AcmeMalformedError } from "./pki-acme-errors";
+
+export const buildUrl = (profileId: string, path: string): string => {
+ const appCfg = getConfig();
+ const baseUrl = appCfg.SITE_URL ?? "";
+ return `${baseUrl}/api/v1/pki/acme/profiles/${profileId}${path}`;
+};
+
+export const extractAccountIdFromKid = (kid: string, profileId: string): string => {
+ const kidPrefix = buildUrl(profileId, "/accounts/");
+ if (!kid.startsWith(kidPrefix)) {
+ throw new AcmeMalformedError({ detail: "KID must start with the profile account URL" });
+ }
+ return z.string().uuid().parse(kid.slice(kidPrefix.length));
+};
diff --git a/backend/src/ee/services/pki-acme/pki-acme-service.ts b/backend/src/ee/services/pki-acme/pki-acme-service.ts
index cc3df7ce77..43c77b3d1c 100644
--- a/backend/src/ee/services/pki-acme/pki-acme-service.ts
+++ b/backend/src/ee/services/pki-acme/pki-acme-service.ts
@@ -1,6 +1,5 @@
import { TPkiAcmeAccounts } from "@app/db/schemas/pki-acme-accounts";
import { TPkiAcmeAuths } from "@app/db/schemas/pki-acme-auths";
-import { getConfig } from "@app/lib/config/env";
import { crypto } from "@app/lib/crypto/cryptography";
import { BadRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
@@ -39,6 +38,7 @@ import {
AcmeUnauthorizedError,
AcmeUnsupportedIdentifierError
} from "./pki-acme-errors";
+import { buildUrl, extractAccountIdFromKid } from "./pki-acme-fns";
import { TPkiAcmeOrderAuthDALFactory } from "./pki-acme-order-auth-dal";
import { TPkiAcmeOrderDALFactory } from "./pki-acme-order-dal";
import {
@@ -115,20 +115,6 @@ export const pkiAcmeServiceFactory = ({
return profile;
};
- const buildUrl = (profileId: string, path: string): string => {
- const appCfg = getConfig();
- const baseUrl = appCfg.SITE_URL ?? "";
- return `${baseUrl}/api/v1/pki/acme/profiles/${profileId}${path}`;
- };
-
- const extractAccountIdFromKid = (kid: string, profileId: string): string => {
- const kidPrefix = buildUrl(profileId, "/accounts/");
- if (!kid.startsWith(kidPrefix)) {
- throw new AcmeMalformedError({ detail: "KID must start with the profile account URL" });
- }
- return z.string().uuid().parse(kid.slice(kidPrefix.length));
- };
-
const validateJwsPayload = async <
TSchema extends z.ZodSchema<any> | undefined = undefined,
T = TSchema extends z.ZodSchema<infer R> ? R : string