vault/ui/app/helpers/engines-display-data.ts
Vault Automation 8cf2228f22
Fix auth method config submit following ember data migration (#9755) (#9793)
* fix broken form after ember data migration

* convert to typescript, add tests

* only transition on success

* use test.each

* use AuthMethodResource

* add tests and refactor fallback for engine-display-data

* fix token_type submitting for token auth methods

* fix imports

* fix conditional for token_type

* update comments add check for token_type

* fix test and add comment to clarify different setting types

* revert and keep unknown type, blowing the scope out too much!

Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
2025-10-02 17:52:31 +00:00

38 lines
1.5 KiB
TypeScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { ALL_ENGINES, type EngineDisplayData } from 'vault/utils/all-engines-metadata';
/**
* Helper function to retrieve engine metadata for a given `methodType`.
* It searches the `ALL_ENGINES` array for an engine with a matching type and returns its metadata object.
* The `ALL_ENGINES` array includes secret and auth engines, including those supported only in enterprise.
* These details (such as mount type and enterprise licensing) are included in the returned engine object.
*
* Example usage:
* const engineMetadata = engineDisplayData('kmip');
* if (engineMetadata?.requiresEnterprise) {
* console.log(`This mount: ${engineMetadata.engineType} requires an enterprise license`);
* }
*
* @param {string} methodType - The engine type (sometimes called backend) to look up (e.g., "aws", "azure").
* @returns {Object|undefined} - The engine metadata, which includes information about its mount type (e.g., secret or auth)
* and whether it requires an enterprise license. Returns undefined if no match is found.
*/
export default function engineDisplayData(methodType: string): EngineDisplayData {
const engine = ALL_ENGINES?.find((t) => t.type === methodType);
if (!engine) {
return {
displayName: methodType || 'Unknown plugin',
type: 'unknown',
isOldEngine: true,
glyph: 'lock',
mountCategory: ['secret', 'auth'],
};
}
return engine;
}