misc: created abstraction for get kms by id

This commit is contained in:
Sheen Capadngan
2024-07-30 23:03:55 +05:30
committed by =
parent ffc1b1ec1c
commit 64869ea8e0
3 changed files with 18 additions and 15 deletions
+1 -2
View File
@@ -627,8 +627,7 @@ export const registerRoutes = async (
projectUserMembershipRoleDAL, projectUserMembershipRoleDAL,
identityProjectMembershipRoleDAL, identityProjectMembershipRoleDAL,
keyStore, keyStore,
kmsService, kmsService
kmsDAL
}); });
const projectEnvService = projectEnvServiceFactory({ const projectEnvService = projectEnvServiceFactory({
+14 -1
View File
@@ -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 startService = async () => {
const appCfg = getConfig(); const appCfg = getConfig();
// This will switch to a seal process and HMS flow in future // This will switch to a seal process and HMS flow in future
@@ -725,6 +737,7 @@ export const kmsServiceFactory = ({
getProjectSecretManagerKmsKey, getProjectSecretManagerKmsKey,
updateProjectSecretManagerKmsKey, updateProjectSecretManagerKmsKey,
getProjectKeyBackup, getProjectKeyBackup,
loadProjectKeyBackup loadProjectKeyBackup,
getKmsById
}; };
}; };
@@ -21,7 +21,6 @@ import { TCertificateAuthorityDALFactory } from "../certificate-authority/certif
import { TIdentityOrgDALFactory } from "../identity/identity-org-dal"; import { TIdentityOrgDALFactory } from "../identity/identity-org-dal";
import { TIdentityProjectDALFactory } from "../identity-project/identity-project-dal"; import { TIdentityProjectDALFactory } from "../identity-project/identity-project-dal";
import { TIdentityProjectMembershipRoleDALFactory } from "../identity-project/identity-project-membership-role-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 { TKmsServiceFactory } from "../kms/kms-service";
import { TOrgDALFactory } from "../org/org-dal"; import { TOrgDALFactory } from "../org/org-dal";
import { TOrgServiceFactory } from "../org/org-service"; import { TOrgServiceFactory } from "../org/org-service";
@@ -82,9 +81,8 @@ type TProjectServiceFactoryDep = {
keyStore: Pick<TKeyStoreFactory, "deleteItem">; keyStore: Pick<TKeyStoreFactory, "deleteItem">;
kmsService: Pick< kmsService: Pick<
TKmsServiceFactory, TKmsServiceFactory,
"updateProjectSecretManagerKmsKey" | "getProjectKeyBackup" | "loadProjectKeyBackup" "updateProjectSecretManagerKmsKey" | "getProjectKeyBackup" | "loadProjectKeyBackup" | "getKmsById"
>; >;
kmsDAL: Pick<TKmsKeyDALFactory, "findByIdWithAssociatedKms">;
}; };
export type TProjectServiceFactory = ReturnType<typeof projectServiceFactory>; export type TProjectServiceFactory = ReturnType<typeof projectServiceFactory>;
@@ -110,8 +108,7 @@ export const projectServiceFactory = ({
certificateAuthorityDAL, certificateAuthorityDAL,
certificateDAL, certificateDAL,
keyStore, keyStore,
kmsService, kmsService
kmsDAL
}: TProjectServiceFactoryDep) => { }: TProjectServiceFactoryDep) => {
/* /*
* Create workspace. Make user the admin * Create workspace. Make user the admin
@@ -152,13 +149,7 @@ export const projectServiceFactory = ({
const ghostUser = await orgService.addGhostUser(organization.id, tx); const ghostUser = await orgService.addGhostUser(organization.id, tx);
if (kmsKeyId) { if (kmsKeyId) {
const kms = await kmsDAL.findByIdWithAssociatedKms(kmsKeyId, tx); const kms = await kmsService.getKmsById(kmsKeyId, tx);
if (!kms.id) {
throw new NotFoundError({
message: "KMS not found"
});
}
if (kms.orgId !== organization.id) { if (kms.orgId !== organization.id) {
throw new BadRequestError({ throw new BadRequestError({