mirror of
https://github.com/hashicorp/vault.git
synced 2026-06-27 10:00:32 -04:00
* VAULT-42427 - initial code updates for aws form * VAULT-42756 - implemented wif support for secret sync * VAULT-42756 - added acceptance and integration test cases for WIF support * refactor: streamline WIF credential handling and enhance destination details management * added changelog * fixed review comments * updated changelog * fixed failing tests * fixed review comments * fixed validation for Edit scenario * fixed region field to have no default value selected * Refactor: updated string literals with centralized enums and some other refactors Co-authored-by: mohit-hashicorp <mohit.ojha@hashicorp.com>
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
/**
|
|
* Copyright IBM Corp. 2016, 2025
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { findDestination } from 'core/helpers/sync-destinations';
|
|
import { DestinationType } from 'sync/utils/constants';
|
|
|
|
import type { ListDestination } from 'vault/sync';
|
|
import type { SystemListSyncDestinationsResponse } from '@hashicorp/vault-client-typescript';
|
|
|
|
// transforms the systemListSyncDestinations response to a flat array
|
|
// destination name and type are the only properties returned from the request
|
|
// to satisfy the list views, combine this data with static properties icon and typeDisplayName
|
|
// the flat array is then filtered by name and type if filter values are provided
|
|
export const listDestinationsTransform = (
|
|
response: SystemListSyncDestinationsResponse,
|
|
nameFilter?: string,
|
|
typeFilter?: string
|
|
) => {
|
|
const { key_info } = response;
|
|
const destinations: ListDestination[] = [];
|
|
// build ListDestination objects from keyInfo
|
|
for (const key in key_info) {
|
|
// iterate through each type's destination names
|
|
const names = (key_info as Record<string, string[]>)[key];
|
|
// remove trailing slash from key
|
|
const type = key.replace(/\/$/, '') as DestinationType;
|
|
|
|
names?.forEach((name: string) => {
|
|
const id = `${type}/${name}`;
|
|
const { icon, name: type_display_name } = findDestination(type);
|
|
// create object with destination's id and attributes
|
|
destinations.push({ id, name, type, icon, type_display_name });
|
|
});
|
|
}
|
|
|
|
// optionally filter by name and type
|
|
let filteredDestinations = [...destinations];
|
|
|
|
const filter = (key: 'type' | 'name', value: string) => {
|
|
return filteredDestinations.filter((destination: ListDestination) => {
|
|
return destination[key].toLowerCase().includes(value.toLowerCase());
|
|
});
|
|
};
|
|
if (typeFilter) {
|
|
filteredDestinations = filter('type', typeFilter);
|
|
}
|
|
if (nameFilter) {
|
|
filteredDestinations = filter('name', nameFilter);
|
|
}
|
|
|
|
return filteredDestinations;
|
|
};
|