Skip to content

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

Implement a bit of get auth

Fang-Pen Lin011b0df4145d
diff --git a/backend/src/ee/services/pki-acme/pki-acme-auth-dal.ts b/backend/src/ee/services/pki-acme/pki-acme-auth-dal.ts
index c06954f4a0..97d2584508 100644
--- a/backend/src/ee/services/pki-acme/pki-acme-auth-dal.ts
+++ b/backend/src/ee/services/pki-acme/pki-acme-auth-dal.ts
@@ -51,88 +51,10 @@ export const pkiAcmeAuthDALFactory = (db: TDbClient) => {
}
};
- const findByAccountId = async (accountId: string, tx?: Knex) => {
- try {
- const auths = await (tx || db)(TableName.PkiAcmeAuth).where({ accountId });
-
- return auths;
- } catch (error) {
- throw new DatabaseError({ error, name: "Find PKI ACME auths by account id" });
- }
- };
-
- const findByStatus = async (status: string, tx?: Knex) => {
- try {
- const auths = await (tx || db)(TableName.PkiAcmeAuth).where({ status });
-
- return auths;
- } catch (error) {
- throw new DatabaseError({ error, name: "Find PKI ACME auths by status" });
- }
- };
-
- const findByAccountIdAndStatus = async (accountId: string, status: string, tx?: Knex) => {
- try {
- const auths = await (tx || db)(TableName.PkiAcmeAuth).where({ accountId, status });
-
- return auths;
- } catch (error) {
- throw new DatabaseError({ error, name: "Find PKI ACME auths by account id and status" });
- }
- };
-
- const findByIdentifier = async (identifierType: string, identifierValue: string, tx?: Knex) => {
- try {
- const auths = await (tx || db)(TableName.PkiAcmeAuth).where({ identifierType, identifierValue });
-
- return auths;
- } catch (error) {
- throw new DatabaseError({ error, name: "Find PKI ACME auths by identifier" });
- }
- };
-
- const findByCertificateId = async (certificateId: string, tx?: Knex) => {
- try {
- const auths = await (tx || db)(TableName.PkiAcmeAuth).where({ certificateId });
-
- return auths;
- } catch (error) {
- throw new DatabaseError({ error, name: "Find PKI ACME auths by certificate id" });
- }
- };
-
- const deleteById = async (id: string, tx?: Knex) => {
- try {
- const result = await (tx || db)(TableName.PkiAcmeAuth).where({ id }).delete().returning("*");
- const [auth] = result;
-
- return auth || null;
- } catch (error) {
- throw new DatabaseError({ error, name: "Delete PKI ACME auth by id" });
- }
- };
-
- const deleteByAccountId = async (accountId: string, tx?: Knex) => {
- try {
- const result = await (tx || db)(TableName.PkiAcmeAuth).where({ accountId }).delete().returning("*");
-
- return result;
- } catch (error) {
- throw new DatabaseError({ error, name: "Delete PKI ACME auths by account id" });
- }
- };
-
return {
...pkiAcmeAuthOrm,
create,
updateById,
- findById,
- findByAccountId,
- findByStatus,
- findByAccountIdAndStatus,
- findByIdentifier,
- findByCertificateId,
- deleteById,
- deleteByAccountId
+ findById
};
};
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 c7138bc273..d15992c990 100644
--- a/backend/src/ee/services/pki-acme/pki-acme-service.ts
+++ b/backend/src/ee/services/pki-acme/pki-acme-service.ts
@@ -56,7 +56,7 @@ type TPkiAcmeServiceFactoryDep = {
certificateProfileDAL: Pick<TCertificateProfileDALFactory, "findById">;
acmeAccountDAL: Pick<TPkiAcmeAccountDALFactory, "findByProjectIdAndAccountId" | "findByPublicKey" | "create">;
acmeOrderDAL: Pick<TPkiAcmeOrderDALFactory, "create" | "transaction" | "findByIdWithAuthorizations">;
- acmeAuthDAL: Pick<TPkiAcmeAuthDALFactory, "create">;
+ acmeAuthDAL: Pick<TPkiAcmeAuthDALFactory, "create" | "findById">;
acmeOrderAuthDAL: Pick<TPkiAcmeOrderAuthDALFactory, "insertMany">;
};
@@ -468,22 +468,21 @@ export const pkiAcmeServiceFactory = ({
accountId: string;
authzId: string;
}): Promise<TAcmeResponse<TGetAcmeAuthorizationResponse>> => {
- const profile = await validateAcmeProfile(profileId);
- const order = await acmeOrderDAL.findByIdWithAuthorizations(orderId);
- if (!order || order.accountId !== accountId) {
- throw new NotFoundError({ message: "ACME order not found" });
+ const auth = await acmeAuthDAL.findById(authzId);
+ if (!auth || auth.accountId !== accountId) {
+ throw new NotFoundError({ message: "ACME authorization not found" });
}
- // FIXME: Implement ACME authorization retrieval
return {
status: 200,
body: {
- status: "pending",
- expires: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
+ status: auth.status,
+ expires: auth.expiresAt.toISOString(),
identifier: {
- type: "dns",
- value: "FIXME-domain-name"
+ type: auth.identifierType,
+ value: auth.identifierValue
},
challenges: [
+ // TODO: fixme
{
type: "http-01",
url: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}/challenges/http-01`),