Revert stuff

This commit is contained in:
Fang-Pen Lin
2025-11-12 10:47:56 -08:00
parent cb750c8c13
commit 192cf5a8f9
4 changed files with 3 additions and 45 deletions
@@ -85,7 +85,6 @@ export const certificateProfileDALFactory = (db: TDbClient) => {
const findByIdWithConfigs = async (id: string, tx?: Knex): Promise<TCertificateProfileWithConfigs | undefined> => { const findByIdWithConfigs = async (id: string, tx?: Knex): Promise<TCertificateProfileWithConfigs | undefined> => {
try { try {
const query = (tx || db)(TableName.PkiCertificateProfile) const query = (tx || db)(TableName.PkiCertificateProfile)
.leftJoin(TableName.Project, `${TableName.PkiCertificateProfile}.projectId`, `${TableName.Project}.id`)
.leftJoin( .leftJoin(
TableName.CertificateAuthority, TableName.CertificateAuthority,
`${TableName.PkiCertificateProfile}.caId`, `${TableName.PkiCertificateProfile}.caId`,
@@ -113,8 +112,6 @@ export const certificateProfileDALFactory = (db: TDbClient) => {
) )
.select(selectAllTableCols(TableName.PkiCertificateProfile)) .select(selectAllTableCols(TableName.PkiCertificateProfile))
.select( .select(
db.ref("id").withSchema(TableName.Project).as("projectId"),
db.ref("orgId").withSchema(TableName.Project).as("orgId"),
db.ref("id").withSchema(TableName.CertificateAuthority).as("caId"), db.ref("id").withSchema(TableName.CertificateAuthority).as("caId"),
db.ref("projectId").withSchema(TableName.CertificateAuthority).as("caProjectId"), db.ref("projectId").withSchema(TableName.CertificateAuthority).as("caProjectId"),
db.ref("status").withSchema(TableName.CertificateAuthority).as("caStatus"), db.ref("status").withSchema(TableName.CertificateAuthority).as("caStatus"),
@@ -188,11 +185,6 @@ export const certificateProfileDALFactory = (db: TDbClient) => {
} as TCertificateProfileWithConfigs["certificateTemplate"]) } as TCertificateProfileWithConfigs["certificateTemplate"])
: undefined; : undefined;
const project = {
id: result.projectId,
orgId: result.orgId
} as TCertificateProfileWithConfigs["project"];
const transformedResult: TCertificateProfileWithConfigs = { const transformedResult: TCertificateProfileWithConfigs = {
id: result.id, id: result.id,
projectId: result.projectId, projectId: result.projectId,
@@ -209,7 +201,6 @@ export const certificateProfileDALFactory = (db: TDbClient) => {
estConfig, estConfig,
apiConfig, apiConfig,
acmeConfig, acmeConfig,
project,
certificateAuthority, certificateAuthority,
certificateTemplate certificateTemplate
}; };
@@ -22,7 +22,6 @@ import type { TProjectDALFactory } from "../project/project-dal";
import type { TCertificateProfileDALFactory } from "./certificate-profile-dal"; import type { TCertificateProfileDALFactory } from "./certificate-profile-dal";
import { certificateProfileServiceFactory, TCertificateProfileServiceFactory } from "./certificate-profile-service"; import { certificateProfileServiceFactory, TCertificateProfileServiceFactory } from "./certificate-profile-service";
import { EnrollmentType, TCertificateProfile, TCertificateProfileWithConfigs } from "./certificate-profile-types"; import { EnrollmentType, TCertificateProfile, TCertificateProfileWithConfigs } from "./certificate-profile-types";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
vi.mock("@app/lib/crypto/cryptography", () => ({ vi.mock("@app/lib/crypto/cryptography", () => ({
crypto: { crypto: {
@@ -100,10 +99,6 @@ describe("CertificateProfileService", () => {
const sampleProfileWithConfigs: TCertificateProfileWithConfigs = { const sampleProfileWithConfigs: TCertificateProfileWithConfigs = {
...sampleProfile, ...sampleProfile,
project: {
id: "project-123",
orgId: "org-123"
},
certificateAuthority: { certificateAuthority: {
id: "ca-123", id: "ca-123",
projectId: "project-123", projectId: "project-123",
@@ -179,12 +174,6 @@ describe("CertificateProfileService", () => {
generateKmsKey: vi.fn() generateKmsKey: vi.fn()
} as unknown as Pick<TKmsServiceFactory, "generateKmsKey" | "encryptWithKmsKey" | "decryptWithKmsKey">; } as unknown as Pick<TKmsServiceFactory, "generateKmsKey" | "encryptWithKmsKey" | "decryptWithKmsKey">;
const mockLicenseService = {
getPlan: vi.fn().mockResolvedValue({
pkiAcme: true
})
} as unknown as Pick<TLicenseServiceFactory, "getPlan">;
const mockProjectDAL = { const mockProjectDAL = {
findById: vi.fn(), findById: vi.fn(),
findOne: vi.fn(), findOne: vi.fn(),
@@ -264,7 +253,6 @@ describe("CertificateProfileService", () => {
certificateAuthorityCertDAL: mockCertificateAuthorityCertDAL, certificateAuthorityCertDAL: mockCertificateAuthorityCertDAL,
permissionService: mockPermissionService, permissionService: mockPermissionService,
kmsService: mockKmsService, kmsService: mockKmsService,
licenseService: mockLicenseService,
projectDAL: mockProjectDAL projectDAL: mockProjectDAL
}); });
}); });
@@ -14,14 +14,13 @@ import { getConfig } from "@app/lib/config/env";
import { crypto } from "@app/lib/crypto/cryptography"; import { crypto } from "@app/lib/crypto/cryptography";
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors"; import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { ActorAuthMethod, ActorType } from "../auth/auth-type"; import { ActorAuthMethod, ActorType } from "../auth/auth-type";
import { TCertificateAuthorityCertDALFactory } from "../certificate-authority/certificate-authority-cert-dal";
import { TCertificateAuthorityDALFactory } from "../certificate-authority/certificate-authority-dal";
import { TCertificateTemplateV2DALFactory } from "../certificate-template-v2/certificate-template-v2-dal";
import { TCertificateBodyDALFactory } from "../certificate/certificate-body-dal"; import { TCertificateBodyDALFactory } from "../certificate/certificate-body-dal";
import { getCertificateCredentials, isCertChainValid } from "../certificate/certificate-fns"; import { getCertificateCredentials, isCertChainValid } from "../certificate/certificate-fns";
import { TCertificateSecretDALFactory } from "../certificate/certificate-secret-dal"; import { TCertificateSecretDALFactory } from "../certificate/certificate-secret-dal";
import { TCertificateAuthorityCertDALFactory } from "../certificate-authority/certificate-authority-cert-dal";
import { TCertificateAuthorityDALFactory } from "../certificate-authority/certificate-authority-dal";
import { TCertificateTemplateV2DALFactory } from "../certificate-template-v2/certificate-template-v2-dal";
import { TAcmeEnrollmentConfigDALFactory } from "../enrollment-config/acme-enrollment-config-dal"; import { TAcmeEnrollmentConfigDALFactory } from "../enrollment-config/acme-enrollment-config-dal";
import { TApiEnrollmentConfigDALFactory } from "../enrollment-config/api-enrollment-config-dal"; import { TApiEnrollmentConfigDALFactory } from "../enrollment-config/api-enrollment-config-dal";
import { TAcmeConfigData, TApiConfigData, TEstConfigData } from "../enrollment-config/enrollment-config-types"; import { TAcmeConfigData, TApiConfigData, TEstConfigData } from "../enrollment-config/enrollment-config-types";
@@ -154,7 +153,6 @@ type TCertificateProfileServiceFactoryDep = {
certificateAuthorityCertDAL: Pick<TCertificateAuthorityCertDALFactory, "findById">; certificateAuthorityCertDAL: Pick<TCertificateAuthorityCertDALFactory, "findById">;
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">; permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
kmsService: Pick<TKmsServiceFactory, "generateKmsKey" | "encryptWithKmsKey" | "decryptWithKmsKey">; kmsService: Pick<TKmsServiceFactory, "generateKmsKey" | "encryptWithKmsKey" | "decryptWithKmsKey">;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
projectDAL: Pick<TProjectDALFactory, "findProjectBySlug" | "findOne" | "updateById" | "findById" | "transaction">; projectDAL: Pick<TProjectDALFactory, "findProjectBySlug" | "findOne" | "updateById" | "findById" | "transaction">;
}; };
@@ -177,7 +175,6 @@ export const certificateProfileServiceFactory = ({
certificateSecretDAL, certificateSecretDAL,
permissionService, permissionService,
kmsService, kmsService,
licenseService,
projectDAL projectDAL
}: TCertificateProfileServiceFactoryDep) => { }: TCertificateProfileServiceFactoryDep) => {
const createProfile = async ({ const createProfile = async ({
@@ -240,20 +237,6 @@ export const certificateProfileServiceFactory = ({
message: "API enrollment requires API configuration" message: "API enrollment requires API configuration"
}); });
} }
if (data.enrollmentType === EnrollmentType.ACME) {
const orgLicensePlan = await licenseService.getPlan(actorOrgId);
if (!orgLicensePlan.pkiAcme) {
throw new BadRequestError({
message:
"Failed to create certificate profile due to plan restriction. Upgrade plan to create ACME certificate profile."
});
}
if (!data.acmeConfig) {
throw new ForbiddenRequestError({
message: "ACME enrollment requires ACME configuration"
});
}
}
// TODO: acme type currently doesn't require config obj, but add a check in the future if // TODO: acme type currently doesn't require config obj, but add a check in the future if
// we have options // we have options
@@ -33,10 +33,6 @@ export type TCertificateProfileUpdate = Omit<TPkiCertificateProfilesUpdate, "enr
}; };
export type TCertificateProfileWithConfigs = TCertificateProfile & { export type TCertificateProfileWithConfigs = TCertificateProfile & {
project: {
id: string;
orgId: string;
};
certificateAuthority?: { certificateAuthority?: {
id: string; id: string;
projectId: string; projectId: string;