mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-11 15:29:46 +00:00
Rename azure flag to enableVersions
This commit is contained in:
+4
-4
@@ -3,6 +3,7 @@ import * as AWS from "aws-sdk";
|
||||
import RE2 from "re2";
|
||||
import { z } from "zod";
|
||||
|
||||
import { TCertificateSyncs } from "@app/db/schemas";
|
||||
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
||||
import { logger } from "@app/lib/logger";
|
||||
import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";
|
||||
@@ -397,11 +398,10 @@ export const awsCertificateManagerPkiSyncFactory = ({
|
||||
});
|
||||
|
||||
const existingSyncRecords = await certificateSyncDAL.findByPkiSyncId(pkiSync.id);
|
||||
type SyncRecord = (typeof existingSyncRecords)[0];
|
||||
const syncRecordsByCertId = new Map<string, SyncRecord>();
|
||||
const syncRecordsByExternalId = new Map<string, SyncRecord>();
|
||||
const syncRecordsByCertId = new Map<string, TCertificateSyncs>();
|
||||
const syncRecordsByExternalId = new Map<string, TCertificateSyncs>();
|
||||
|
||||
existingSyncRecords.forEach((record: SyncRecord) => {
|
||||
existingSyncRecords.forEach((record: TCertificateSyncs) => {
|
||||
if (record.certificateId) {
|
||||
syncRecordsByCertId.set(record.certificateId, record);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { AxiosError } from "axios";
|
||||
import * as crypto from "crypto";
|
||||
|
||||
import { TCertificateSyncs } from "@app/db/schemas";
|
||||
import { request } from "@app/lib/config/request";
|
||||
import { logger } from "@app/lib/logger";
|
||||
import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";
|
||||
@@ -346,11 +347,10 @@ export const azureKeyVaultPkiSyncFactory = ({
|
||||
);
|
||||
|
||||
const existingSyncRecords = await certificateSyncDAL.findByPkiSyncId(pkiSync.id);
|
||||
type SyncRecord = (typeof existingSyncRecords)[0];
|
||||
const syncRecordsByCertId = new Map<string, SyncRecord>();
|
||||
const syncRecordsByExternalId = new Map<string, SyncRecord>();
|
||||
const syncRecordsByCertId = new Map<string, TCertificateSyncs>();
|
||||
const syncRecordsByExternalId = new Map<string, TCertificateSyncs>();
|
||||
|
||||
existingSyncRecords.forEach((record: SyncRecord) => {
|
||||
existingSyncRecords.forEach((record: TCertificateSyncs) => {
|
||||
if (record.certificateId) {
|
||||
syncRecordsByCertId.set(record.certificateId, record);
|
||||
}
|
||||
@@ -368,10 +368,10 @@ export const azureKeyVaultPkiSyncFactory = ({
|
||||
}[] = [];
|
||||
|
||||
const syncOptions = pkiSync.syncOptions as
|
||||
| { certificateNameSchema?: string; canRemoveCertificates?: boolean; preserveVersion?: boolean }
|
||||
| { certificateNameSchema?: string; canRemoveCertificates?: boolean; enableVersioning?: boolean }
|
||||
| undefined;
|
||||
const canRemoveCertificates = syncOptions?.canRemoveCertificates ?? true;
|
||||
const preserveVersion = syncOptions?.preserveVersion ?? true;
|
||||
const enableVersioning = syncOptions?.enableVersioning ?? true;
|
||||
|
||||
const activeExternalIdentifiers = new Set<string>();
|
||||
|
||||
@@ -382,7 +382,7 @@ export const azureKeyVaultPkiSyncFactory = ({
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preserveVersion && typeof certificateId === "string") {
|
||||
if (enableVersioning && typeof certificateId === "string") {
|
||||
const certificate = await certificateDAL.findById(certificateId);
|
||||
if (certificate?.renewedByCertificateId) {
|
||||
// eslint-disable-next-line no-continue
|
||||
@@ -399,7 +399,7 @@ export const azureKeyVaultPkiSyncFactory = ({
|
||||
if (existingSyncRecord?.externalIdentifier) {
|
||||
const existingAzureCert = vaultCertificates[existingSyncRecord.externalIdentifier];
|
||||
|
||||
if (existingAzureCert && preserveVersion) {
|
||||
if (existingAzureCert && enableVersioning) {
|
||||
targetCertName = existingSyncRecord.externalIdentifier;
|
||||
activeExternalIdentifiers.add(targetCertName);
|
||||
|
||||
@@ -409,7 +409,7 @@ export const azureKeyVaultPkiSyncFactory = ({
|
||||
}
|
||||
} else if (!existingAzureCert) {
|
||||
shouldCreateNew = true;
|
||||
} else if (!preserveVersion) {
|
||||
} else if (!enableVersioning) {
|
||||
shouldCreateNew = true;
|
||||
}
|
||||
} else {
|
||||
@@ -544,7 +544,7 @@ export const azureKeyVaultPkiSyncFactory = ({
|
||||
]);
|
||||
}
|
||||
|
||||
if (preserveVersion) {
|
||||
if (enableVersioning) {
|
||||
const currentCertificate = await certificateDAL.findById(certificateId);
|
||||
if (currentCertificate?.renewedFromCertificateId) {
|
||||
await certificateSyncDAL.removeCertificates(pkiSync.id, [currentCertificate.renewedFromCertificateId]);
|
||||
|
||||
@@ -14,7 +14,7 @@ export const AzureKeyVaultPkiSyncConfigSchema = z.object({
|
||||
const AzureKeyVaultPkiSyncOptionsSchema = z.object({
|
||||
canImportCertificates: z.boolean().default(false),
|
||||
canRemoveCertificates: z.boolean().default(true),
|
||||
preserveVersion: z.boolean().default(true),
|
||||
enableVersioning: z.boolean().default(true),
|
||||
certificateNameSchema: z
|
||||
.string()
|
||||
.optional()
|
||||
|
||||
@@ -95,10 +95,17 @@ export const pkiSyncServiceFactory = ({
|
||||
});
|
||||
}
|
||||
|
||||
const invalidCertificates = certificates.filter((cert) => cert.projectId !== expectedProjectId);
|
||||
if (invalidCertificates.length > 0) {
|
||||
const invalidProjectCertificates = certificates.filter((cert) => cert.projectId !== expectedProjectId);
|
||||
if (invalidProjectCertificates.length > 0) {
|
||||
throw new BadRequestError({
|
||||
message: `Certificates do not belong to the same project: ${invalidCertificates.map((cert) => cert.id).join(", ")}`
|
||||
message: `Certificates do not belong to the same project: ${invalidProjectCertificates.map((cert) => cert.id).join(", ")}`
|
||||
});
|
||||
}
|
||||
|
||||
const invalidRenewedCertificates = certificates.filter((cert) => cert.renewedByCertificateId);
|
||||
if (invalidRenewedCertificates.length > 0) {
|
||||
throw new BadRequestError({
|
||||
message: `Cannot add renewed certificates to PKI sync: ${invalidRenewedCertificates.map((cert) => cert.id).join(", ")}`
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user