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*
This commit is contained in:
Chelsea Shaw
2023-12-13 15:38:43 -06:00
committed by GitHub
parent ac1e9194da
commit e122ce80de
7 changed files with 85 additions and 9 deletions

View File

@@ -0,0 +1,20 @@
/**
* 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;
}
}