Skip to content

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

misc: created abstraction for get kms by id

Sheen Capadngan64869ea8e08f
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 2224203460..9fc47c046b 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -627,8 +627,7 @@ export const registerRoutes = async (
projectUserMembershipRoleDAL,
identityProjectMembershipRoleDAL,
keyStore,
- kmsService,
- kmsDAL
+ kmsService
});
const projectEnvService = projectEnvServiceFactory({
diff --git a/backend/src/services/kms/kms-service.ts b/backend/src/services/kms/kms-service.ts
index 51ba93d9b5..0e8e946825 100644
--- a/backend/src/services/kms/kms-service.ts
+++ b/backend/src/services/kms/kms-service.ts
@@ -666,6 +666,18 @@ export const kmsServiceFactory = ({
};
};
+ const getKmsById = async (kmsKeyId: string, tx?: Knex) => {
+ const kms = await kmsDAL.findByIdWithAssociatedKms(kmsKeyId, tx);
+
+ if (!kms.id) {
+ throw new NotFoundError({
+ message: "KMS not found"
+ });
+ }
+
+ return kms;
+ };
+
const startService = async () => {
const appCfg = getConfig();
// This will switch to a seal process and HMS flow in future
@@ -725,6 +737,7 @@ export const kmsServiceFactory = ({
getProjectSecretManagerKmsKey,
updateProjectSecretManagerKmsKey,
getProjectKeyBackup,
- loadProjectKeyBackup
+ loadProjectKeyBackup,
+ getKmsById
};
};
diff --git a/backend/src/services/project/project-service.ts b/backend/src/services/project/project-service.ts
index 4876f8348f..368915521a 100644
--- a/backend/src/services/project/project-service.ts
+++ b/backend/src/services/project/project-service.ts
@@ -21,7 +21,6 @@ import { TCertificateAuthorityDALFactory } from "../certificate-authority/certif
import { TIdentityOrgDALFactory } from "../identity/identity-org-dal";
import { TIdentityProjectDALFactory } from "../identity-project/identity-project-dal";
import { TIdentityProjectMembershipRoleDALFactory } from "../identity-project/identity-project-membership-role-dal";
-import { TKmsKeyDALFactory } from "../kms/kms-key-dal";
import { TKmsServiceFactory } from "../kms/kms-service";
import { TOrgDALFactory } from "../org/org-dal";
import { TOrgServiceFactory } from "../org/org-service";
@@ -82,9 +81,8 @@ type TProjectServiceFactoryDep = {
keyStore: Pick<TKeyStoreFactory, "deleteItem">;
kmsService: Pick<
TKmsServiceFactory,
- "updateProjectSecretManagerKmsKey" | "getProjectKeyBackup" | "loadProjectKeyBackup"
+ "updateProjectSecretManagerKmsKey" | "getProjectKeyBackup" | "loadProjectKeyBackup" | "getKmsById"
>;
- kmsDAL: Pick<TKmsKeyDALFactory, "findByIdWithAssociatedKms">;
};
export type TProjectServiceFactory = ReturnType<typeof projectServiceFactory>;
@@ -110,8 +108,7 @@ export const projectServiceFactory = ({
certificateAuthorityDAL,
certificateDAL,
keyStore,
- kmsService,
- kmsDAL
+ kmsService
}: TProjectServiceFactoryDep) => {
/*
* Create workspace. Make user the admin
@@ -152,13 +149,7 @@ export const projectServiceFactory = ({
const ghostUser = await orgService.addGhostUser(organization.id, tx);
if (kmsKeyId) {
- const kms = await kmsDAL.findByIdWithAssociatedKms(kmsKeyId, tx);
-
- if (!kms.id) {
- throw new NotFoundError({
- message: "KMS not found"
- });
- }
+ const kms = await kmsService.getKmsById(kmsKeyId, tx);
if (kms.orgId !== organization.id) {
throw new BadRequestError({