mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-19 04:08:21 +00:00
Address greptile comments
This commit is contained in:
@@ -54,28 +54,26 @@ export const apiEnrollmentConfigDALFactory = (db: TDbClient) => {
|
||||
|
||||
const findProfilesForAutoRenewal = async (renewalThresholdDays: number = 30, tx?: Knex) => {
|
||||
try {
|
||||
const now = new Date();
|
||||
const renewalDate = new Date();
|
||||
renewalDate.setDate(now.getDate() + renewalThresholdDays);
|
||||
|
||||
const profiles = await (tx || db)(TableName.CertificateProfile)
|
||||
const profiles = await (tx || db)(TableName.PkiCertificateProfile)
|
||||
.join(
|
||||
TableName.PkiApiEnrollmentConfig,
|
||||
`${TableName.CertificateProfile}.apiConfigId`,
|
||||
`${TableName.PkiCertificateProfile}.apiConfigId`,
|
||||
`${TableName.PkiApiEnrollmentConfig}.id`
|
||||
)
|
||||
.where(`${TableName.PkiApiEnrollmentConfig}.autoRenew`, true)
|
||||
.where((query) => {
|
||||
void query
|
||||
.whereNull(`${TableName.PkiApiEnrollmentConfig}.autoRenewDays`)
|
||||
.orWhere(`${TableName.PkiApiEnrollmentConfig}.autoRenewDays`, "<=", renewalThresholdDays);
|
||||
void query.where((qb) => {
|
||||
void qb
|
||||
.whereNull(`${TableName.PkiApiEnrollmentConfig}.autoRenewDays`)
|
||||
.orWhere(`${TableName.PkiApiEnrollmentConfig}.autoRenewDays`, "<=", renewalThresholdDays);
|
||||
});
|
||||
})
|
||||
.select((tx || db).ref("id").withSchema(TableName.CertificateProfile))
|
||||
.select((tx || db).ref("name").withSchema(TableName.CertificateProfile))
|
||||
.select((tx || db).ref("projectId").withSchema(TableName.CertificateProfile))
|
||||
.select((tx || db).ref("autoRenewDays").withSchema(TableName.CertificateProfile));
|
||||
.select((tx || db).ref("id").withSchema(TableName.PkiCertificateProfile))
|
||||
.select((tx || db).ref("name").withSchema(TableName.PkiCertificateProfile))
|
||||
.select((tx || db).ref("projectId").withSchema(TableName.PkiCertificateProfile))
|
||||
.select((tx || db).ref("autoRenewDays").withSchema(TableName.PkiCertificateProfile));
|
||||
|
||||
return profiles;
|
||||
return profiles as Array<{ id: string; name: string; projectId: string; autoRenewDays?: number }>;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Find profiles for auto renewal" });
|
||||
}
|
||||
@@ -83,9 +81,9 @@ export const apiEnrollmentConfigDALFactory = (db: TDbClient) => {
|
||||
|
||||
const isConfigInUse = async (configId: string, tx?: Knex) => {
|
||||
try {
|
||||
const doc = await (tx || db)(TableName.CertificateProfile).where({ apiConfigId: configId }).count("*").first();
|
||||
const doc = await (tx || db)(TableName.PkiCertificateProfile).where({ apiConfigId: configId }).count("*").first();
|
||||
|
||||
return parseInt(doc || "0", 10);
|
||||
return parseInt((doc as { count?: string })?.count || "0", 10);
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Check if API enrollment config is in use" });
|
||||
}
|
||||
|
||||
@@ -14,7 +14,12 @@ export const estEnrollmentConfigDALFactory = (db: TDbClient) => {
|
||||
|
||||
const create = async (data: TEstEnrollmentConfigInsert, tx?: Knex) => {
|
||||
try {
|
||||
const [estConfig] = await (tx || db)(TableName.PkiEstEnrollmentConfig).insert(data).returning("*");
|
||||
const result = await (tx || db)(TableName.PkiEstEnrollmentConfig).insert(data).returning("*");
|
||||
const [estConfig] = result;
|
||||
|
||||
if (!estConfig) {
|
||||
throw new Error("Failed to create EST enrollment config");
|
||||
}
|
||||
|
||||
return estConfig;
|
||||
} catch (error) {
|
||||
@@ -24,7 +29,12 @@ export const estEnrollmentConfigDALFactory = (db: TDbClient) => {
|
||||
|
||||
const updateById = async (id: string, data: TEstEnrollmentConfigUpdate, tx?: Knex) => {
|
||||
try {
|
||||
const [estConfig] = await (tx || db)(TableName.PkiEstEnrollmentConfig).where({ id }).update(data).returning("*");
|
||||
const result = await (tx || db)(TableName.PkiEstEnrollmentConfig).where({ id }).update(data).returning("*");
|
||||
const [estConfig] = result;
|
||||
|
||||
if (!estConfig) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return estConfig;
|
||||
} catch (error) {
|
||||
@@ -36,7 +46,7 @@ export const estEnrollmentConfigDALFactory = (db: TDbClient) => {
|
||||
try {
|
||||
const estConfig = await (tx || db)(TableName.PkiEstEnrollmentConfig).where({ id }).first();
|
||||
|
||||
return estConfig;
|
||||
return estConfig || null;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Find EST enrollment config by id" });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user