Implement a bit of get auth

This commit is contained in:
Fang-Pen Lin
2025-10-29 21:10:42 -07:00
parent 68e4e6b36a
commit 011b0df414
2 changed files with 10 additions and 89 deletions

View File

@@ -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
};
};

View File

@@ -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`),