mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 09:28:06 +00:00
Merge pull request #4679 from Infisical/fix/secretImportsUITable
Fix secret imports in dashboard when fetching secret values fails
This commit is contained in:
@@ -258,10 +258,6 @@ export const fnSecretsV2FromImports = async ({
|
|||||||
})[];
|
})[];
|
||||||
}[] = [{ secretImports: rootSecretImports, depth: 0, parentImportedSecrets: [] }];
|
}[] = [{ secretImports: rootSecretImports, depth: 0, parentImportedSecrets: [] }];
|
||||||
|
|
||||||
const processedSecretImports = await processReservedImports(rootSecretImports, secretImportDAL);
|
|
||||||
|
|
||||||
stack[0] = { secretImports: processedSecretImports, depth: 0, parentImportedSecrets: [] };
|
|
||||||
|
|
||||||
const processedImports: TSecretImportSecretsV2[] = [];
|
const processedImports: TSecretImportSecretsV2[] = [];
|
||||||
|
|
||||||
while (stack.length) {
|
while (stack.length) {
|
||||||
@@ -299,7 +295,9 @@ export const fnSecretsV2FromImports = async ({
|
|||||||
);
|
);
|
||||||
const importedSecretsGroupByFolderId = groupBy(importedSecrets, (i) => i.folderId);
|
const importedSecretsGroupByFolderId = groupBy(importedSecrets, (i) => i.folderId);
|
||||||
|
|
||||||
sanitizedImports.forEach(({ importPath, importEnv }) => {
|
const processedBatchImports = await processReservedImports(sanitizedImports, secretImportDAL);
|
||||||
|
|
||||||
|
processedBatchImports.forEach(({ importPath, importEnv }) => {
|
||||||
cyclicDetector.add(getImportUniqKey(importEnv.slug, importPath));
|
cyclicDetector.add(getImportUniqKey(importEnv.slug, importPath));
|
||||||
});
|
});
|
||||||
// now we need to check recursively deeper imports made inside other imports
|
// now we need to check recursively deeper imports made inside other imports
|
||||||
@@ -308,7 +306,7 @@ export const fnSecretsV2FromImports = async ({
|
|||||||
const deeperImportsGroupByFolderId = groupBy(deeperImports, (i) => i.folderId);
|
const deeperImportsGroupByFolderId = groupBy(deeperImports, (i) => i.folderId);
|
||||||
|
|
||||||
const isFirstIteration = !processedImports.length;
|
const isFirstIteration = !processedImports.length;
|
||||||
sanitizedImports.forEach(({ importPath, importEnv, id, folderId }, i) => {
|
processedBatchImports.forEach(({ importPath, importEnv, id, folderId }, i) => {
|
||||||
const sourceImportFolder = importedFolderGroupBySourceImport[`${importEnv.id}-${importPath}`]?.[0];
|
const sourceImportFolder = importedFolderGroupBySourceImport[`${importEnv.id}-${importPath}`]?.[0];
|
||||||
const secretsWithDuplicate = (importedSecretsGroupByFolderId?.[importedFolders?.[i]?.id as string] || [])
|
const secretsWithDuplicate = (importedSecretsGroupByFolderId?.[importedFolders?.[i]?.id as string] || [])
|
||||||
.filter((item) =>
|
.filter((item) =>
|
||||||
|
|||||||
+23
-9
@@ -33,11 +33,15 @@ type TImportedSecrets = Array<{
|
|||||||
}>;
|
}>;
|
||||||
|
|
||||||
export const computeImportedSecretRows = (
|
export const computeImportedSecretRows = (
|
||||||
importedSecEnv: string,
|
secretImport: TSecretImport,
|
||||||
importedSecPath: string,
|
|
||||||
importSecrets: TImportedSecrets = [],
|
importSecrets: TImportedSecrets = [],
|
||||||
secrets: SecretV3RawSanitized[] = []
|
secrets: SecretV3RawSanitized[] = [],
|
||||||
|
replicatedFolder?: TSecretImport
|
||||||
) => {
|
) => {
|
||||||
|
const importedSecEnv = replicatedFolder?.importEnv.slug ?? secretImport.importEnv.slug;
|
||||||
|
const importedSecPath = replicatedFolder?.importPath ?? secretImport.importPath;
|
||||||
|
const overrideEnv = secretImport.isReserved ? secretImport.importEnv.slug : undefined;
|
||||||
|
const overridePath = secretImport.isReserved ? secretImport.importPath : undefined;
|
||||||
const importedSecIndex = importSecrets.findIndex(
|
const importedSecIndex = importSecrets.findIndex(
|
||||||
({ secretPath, environmentInfo }) =>
|
({ secretPath, environmentInfo }) =>
|
||||||
secretPath === importedSecPath && importedSecEnv === environmentInfo.slug
|
secretPath === importedSecPath && importedSecEnv === environmentInfo.slug
|
||||||
@@ -73,13 +77,13 @@ export const computeImportedSecretRows = (
|
|||||||
isEmpty?: boolean;
|
isEmpty?: boolean;
|
||||||
}[] = [];
|
}[] = [];
|
||||||
|
|
||||||
importedSec.secrets.forEach(({ key, value, env, path, isEmpty }) => {
|
importedSec.secrets.forEach(({ key, value, isEmpty }) => {
|
||||||
if (!importedEntry[key]) {
|
if (!importedEntry[key]) {
|
||||||
importedSecretEntries.push({
|
importedSecretEntries.push({
|
||||||
key,
|
key,
|
||||||
value,
|
value,
|
||||||
environment: env,
|
environment: overrideEnv ?? importedSec.environmentInfo.slug,
|
||||||
secretPath: path,
|
secretPath: overridePath ?? importedSec.secretPath,
|
||||||
overridden: overridenSec?.[key],
|
overridden: overridenSec?.[key],
|
||||||
isEmpty
|
isEmpty
|
||||||
});
|
});
|
||||||
@@ -125,6 +129,12 @@ export const SecretImportListView = ({
|
|||||||
|
|
||||||
const [items, setItems] = useState(secretImports ?? []);
|
const [items, setItems] = useState(secretImports ?? []);
|
||||||
|
|
||||||
|
const getImportReplicatedFolder = (importPath: string) => {
|
||||||
|
const cleanImportPath = importPath.replace("/__reserve_replication_", "");
|
||||||
|
const replicatedFolder = items?.find(({ id }) => id === cleanImportPath);
|
||||||
|
return replicatedFolder;
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isFetching) {
|
if (!isFetching) {
|
||||||
setItems(secretImports ?? []);
|
setItems(secretImports ?? []);
|
||||||
@@ -204,6 +214,9 @@ export const SecretImportListView = ({
|
|||||||
<SortableContext items={items} strategy={verticalListSortingStrategy}>
|
<SortableContext items={items} strategy={verticalListSortingStrategy}>
|
||||||
{items?.map((item) => {
|
{items?.map((item) => {
|
||||||
// TODO(akhilmhdh): change this and pass this whole object instead of one by one
|
// TODO(akhilmhdh): change this and pass this whole object instead of one by one
|
||||||
|
const replicatedFolder = item.isReserved
|
||||||
|
? getImportReplicatedFolder(item.importPath)
|
||||||
|
: undefined;
|
||||||
return (
|
return (
|
||||||
<SecretImportItem
|
<SecretImportItem
|
||||||
searchTerm={searchTerm}
|
searchTerm={searchTerm}
|
||||||
@@ -212,10 +225,11 @@ export const SecretImportListView = ({
|
|||||||
onExpandReplicateSecrets={handleOpenReplicationSecrets}
|
onExpandReplicateSecrets={handleOpenReplicationSecrets}
|
||||||
secretImport={item}
|
secretImport={item}
|
||||||
importedSecrets={computeImportedSecretRows(
|
importedSecrets={computeImportedSecretRows(
|
||||||
item.importEnv.slug,
|
item,
|
||||||
item.importPath,
|
importedSecrets,
|
||||||
importedSecrets
|
[],
|
||||||
// secrets scott - now that secrets are paginated we are not showing if they are overridden (yet?)
|
// secrets scott - now that secrets are paginated we are not showing if they are overridden (yet?)
|
||||||
|
replicatedFolder
|
||||||
)}
|
)}
|
||||||
secretPath={secretPath}
|
secretPath={secretPath}
|
||||||
environment={environment}
|
environment={environment}
|
||||||
|
|||||||
Reference in New Issue
Block a user