mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 18:41:21 +00:00
misc: initial setup
This commit is contained in:
@@ -1,13 +1,80 @@
|
||||
import { Knex } from "knex";
|
||||
|
||||
import { TDbClient } from "@app/db";
|
||||
import { TableName } from "@app/db/schemas";
|
||||
import { CertificateAuthoritiesSchema, TableName } from "@app/db/schemas";
|
||||
import { DatabaseError } from "@app/lib/errors";
|
||||
import { ormify } from "@app/lib/knex";
|
||||
import { ormify, selectAllTableCols } from "@app/lib/knex";
|
||||
|
||||
export type TCertificateAuthorityDALFactory = ReturnType<typeof certificateAuthorityDALFactory>;
|
||||
|
||||
export const certificateAuthorityDALFactory = (db: TDbClient) => {
|
||||
const caOrm = ormify(db, TableName.CertificateAuthority);
|
||||
|
||||
const findByIdWithAssociatedCa = async (caId: string, tx?: Knex) => {
|
||||
const result = await (tx || db.replicaNode())(TableName.CertificateAuthority)
|
||||
.leftJoin(
|
||||
TableName.InternalCertificateAuthority,
|
||||
`${TableName.CertificateAuthority}.id`,
|
||||
`${TableName.InternalCertificateAuthority}.certificateAuthorityId`
|
||||
)
|
||||
.where(`${TableName.CertificateAuthority}.id`, caId)
|
||||
.select(selectAllTableCols(TableName.CertificateAuthority))
|
||||
.select(
|
||||
db.ref("id").withSchema(TableName.InternalCertificateAuthority).as("internalCaId"),
|
||||
db.ref("parentCaId").withSchema(TableName.InternalCertificateAuthority).as("internalParentCaId"),
|
||||
db.ref("type").withSchema(TableName.InternalCertificateAuthority).as("internalType"),
|
||||
db.ref("status").withSchema(TableName.InternalCertificateAuthority).as("internalStatus"),
|
||||
db.ref("friendlyName").withSchema(TableName.InternalCertificateAuthority).as("internalFriendlyName"),
|
||||
db.ref("organization").withSchema(TableName.InternalCertificateAuthority).as("internalOrganization"),
|
||||
db.ref("ou").withSchema(TableName.InternalCertificateAuthority).as("internalOu"),
|
||||
db.ref("country").withSchema(TableName.InternalCertificateAuthority).as("internalCountry"),
|
||||
db.ref("province").withSchema(TableName.InternalCertificateAuthority).as("internalProvince"),
|
||||
db.ref("locality").withSchema(TableName.InternalCertificateAuthority).as("internalLocality"),
|
||||
db.ref("commonName").withSchema(TableName.InternalCertificateAuthority).as("internalCommonName"),
|
||||
db.ref("dn").withSchema(TableName.InternalCertificateAuthority).as("internalDn"),
|
||||
db.ref("serialNumber").withSchema(TableName.InternalCertificateAuthority).as("internalSerialNumber"),
|
||||
db.ref("maxPathLength").withSchema(TableName.InternalCertificateAuthority).as("internalMaxPathLength"),
|
||||
db.ref("keyAlgorithm").withSchema(TableName.InternalCertificateAuthority).as("internalKeyAlgorithm"),
|
||||
db.ref("notBefore").withSchema(TableName.InternalCertificateAuthority).as("internalNotBefore"),
|
||||
db.ref("notAfter").withSchema(TableName.InternalCertificateAuthority).as("internalNotAfter"),
|
||||
db.ref("activeCaCertId").withSchema(TableName.InternalCertificateAuthority).as("internalActiveCaCertId"),
|
||||
db
|
||||
.ref("certificateAuthorityId")
|
||||
.withSchema(TableName.InternalCertificateAuthority)
|
||||
.as("internalCertificateAuthorityId")
|
||||
)
|
||||
.first();
|
||||
|
||||
const data = {
|
||||
...CertificateAuthoritiesSchema.parse(result),
|
||||
internalCa: result
|
||||
? {
|
||||
id: result.internalCaId,
|
||||
parentCaId: result.internalParentCaId,
|
||||
type: result.internalType,
|
||||
status: result.internalStatus,
|
||||
friendlyName: result.internalFriendlyName,
|
||||
organization: result.internalOrganization,
|
||||
ou: result.internalOu,
|
||||
country: result.internalCountry,
|
||||
province: result.internalProvince,
|
||||
locality: result.internalLocality,
|
||||
commonName: result.internalCommonName,
|
||||
dn: result.internalDn,
|
||||
serialNumber: result.internalSerialNumber,
|
||||
maxPathLength: result.internalMaxPathLength,
|
||||
keyAlgorithm: result.internalKeyAlgorithm,
|
||||
notBefore: result.internalNotBefore,
|
||||
notAfter: result.internalNotAfter,
|
||||
activeCaCertId: result.internalActiveCaCertId,
|
||||
certificateAuthorityId: result.internalCertificateAuthorityId
|
||||
}
|
||||
: undefined
|
||||
};
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
// note: not used
|
||||
const buildCertificateChain = async (caId: string) => {
|
||||
try {
|
||||
@@ -44,6 +111,7 @@ export const certificateAuthorityDALFactory = (db: TDbClient) => {
|
||||
|
||||
return {
|
||||
...caOrm,
|
||||
buildCertificateChain
|
||||
buildCertificateChain,
|
||||
findByIdWithAssociatedCa
|
||||
};
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ import { NotFoundError } from "@app/lib/errors";
|
||||
import { getProjectKmsCertificateKeyId } from "@app/services/project/project-fns";
|
||||
|
||||
import { CertKeyAlgorithm, CertStatus } from "../certificate/certificate-types";
|
||||
import { TCertificateAuthorityDALFactory } from "./certificate-authority-dal";
|
||||
import {
|
||||
TDNParts,
|
||||
TGetCaCertChainDTO,
|
||||
@@ -318,3 +319,10 @@ export const rebuildCaCrl = async ({
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const expandInternalCa = (
|
||||
ca: Awaited<ReturnType<TCertificateAuthorityDALFactory["findByIdWithAssociatedCa"]>>
|
||||
) => ({
|
||||
...ca,
|
||||
...ca.internalCa
|
||||
});
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { TDbClient } from "@app/db";
|
||||
import { TableName } from "@app/db/schemas";
|
||||
import { ormify } from "@app/lib/knex";
|
||||
|
||||
export type TInternalCertificateAuthorityDALFactory = ReturnType<typeof internalCertificateAuthorityDALFactory>;
|
||||
|
||||
export const internalCertificateAuthorityDALFactory = (db: TDbClient) => {
|
||||
const caOrm = ormify(db, TableName.InternalCertificateAuthority);
|
||||
|
||||
return {
|
||||
...caOrm
|
||||
};
|
||||
};
|
||||
+1945
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user