Files
vault/ui/lib/core/addon/utils/advanced-secret.js
Chelsea Shaw e122ce80de UI: better calculation for advanced secret in KV v2 (#24513)
* Add util for determining whether secret data is advanced

* Add test coverage for bug

* use non-dumb logic for detecting advanced object

* Add changelog

* Add header

* Move util to core

* Add escaped newline to test coverage

* headers again *eyeroll*
2023-12-13 21:38:43 +00:00

21 lines
504 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
/**
* Method to check whether the secret value is a nested object (returns true)
* All other values return false
* @param value string or stringified JSON
* @returns boolean
*/
export function isAdvancedSecret(value) {
try {
const json = JSON.parse(value);
if (Array.isArray(json)) return false;
return Object.values(json).some((value) => typeof value !== 'string');
} catch (e) {
return false;
}
}