mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 21:28:18 +00:00
Implement a bit of get auth
This commit is contained in:
@@ -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 {
|
return {
|
||||||
...pkiAcmeAuthOrm,
|
...pkiAcmeAuthOrm,
|
||||||
create,
|
create,
|
||||||
updateById,
|
updateById,
|
||||||
findById,
|
findById
|
||||||
findByAccountId,
|
|
||||||
findByStatus,
|
|
||||||
findByAccountIdAndStatus,
|
|
||||||
findByIdentifier,
|
|
||||||
findByCertificateId,
|
|
||||||
deleteById,
|
|
||||||
deleteByAccountId
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ type TPkiAcmeServiceFactoryDep = {
|
|||||||
certificateProfileDAL: Pick<TCertificateProfileDALFactory, "findById">;
|
certificateProfileDAL: Pick<TCertificateProfileDALFactory, "findById">;
|
||||||
acmeAccountDAL: Pick<TPkiAcmeAccountDALFactory, "findByProjectIdAndAccountId" | "findByPublicKey" | "create">;
|
acmeAccountDAL: Pick<TPkiAcmeAccountDALFactory, "findByProjectIdAndAccountId" | "findByPublicKey" | "create">;
|
||||||
acmeOrderDAL: Pick<TPkiAcmeOrderDALFactory, "create" | "transaction" | "findByIdWithAuthorizations">;
|
acmeOrderDAL: Pick<TPkiAcmeOrderDALFactory, "create" | "transaction" | "findByIdWithAuthorizations">;
|
||||||
acmeAuthDAL: Pick<TPkiAcmeAuthDALFactory, "create">;
|
acmeAuthDAL: Pick<TPkiAcmeAuthDALFactory, "create" | "findById">;
|
||||||
acmeOrderAuthDAL: Pick<TPkiAcmeOrderAuthDALFactory, "insertMany">;
|
acmeOrderAuthDAL: Pick<TPkiAcmeOrderAuthDALFactory, "insertMany">;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -468,22 +468,21 @@ export const pkiAcmeServiceFactory = ({
|
|||||||
accountId: string;
|
accountId: string;
|
||||||
authzId: string;
|
authzId: string;
|
||||||
}): Promise<TAcmeResponse<TGetAcmeAuthorizationResponse>> => {
|
}): Promise<TAcmeResponse<TGetAcmeAuthorizationResponse>> => {
|
||||||
const profile = await validateAcmeProfile(profileId);
|
const auth = await acmeAuthDAL.findById(authzId);
|
||||||
const order = await acmeOrderDAL.findByIdWithAuthorizations(orderId);
|
if (!auth || auth.accountId !== accountId) {
|
||||||
if (!order || order.accountId !== accountId) {
|
throw new NotFoundError({ message: "ACME authorization not found" });
|
||||||
throw new NotFoundError({ message: "ACME order not found" });
|
|
||||||
}
|
}
|
||||||
// FIXME: Implement ACME authorization retrieval
|
|
||||||
return {
|
return {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: {
|
body: {
|
||||||
status: "pending",
|
status: auth.status,
|
||||||
expires: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
|
expires: auth.expiresAt.toISOString(),
|
||||||
identifier: {
|
identifier: {
|
||||||
type: "dns",
|
type: auth.identifierType,
|
||||||
value: "FIXME-domain-name"
|
value: auth.identifierValue
|
||||||
},
|
},
|
||||||
challenges: [
|
challenges: [
|
||||||
|
// TODO: fixme
|
||||||
{
|
{
|
||||||
type: "http-01",
|
type: "http-01",
|
||||||
url: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}/challenges/http-01`),
|
url: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}/challenges/http-01`),
|
||||||
|
|||||||
Reference in New Issue
Block a user