feat: set default key value when is empty #31619
Open
+52
−12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes an issue where creating a secret in the Vault UI with an empty key field results in a secret with an empty string as the key (
"": "value"), which causes problems when accessing the secret from Kubernetes and other clients.What
When a user enters a value in the secret data section but leaves the key field empty (showing the "key" placeholder), the system now defaults the key to
"key"(or the custom placeholder text if specified) instead of using an empty string.Why
Empty string keys are problematic in many scenarios:
VaultSecretsOperator, Kubernetes cannot properly access secrets with empty string keys.How
The fix modifies the
KVObjectutility class to:defaultKeyparameter in thetoJSONandtoJSONStringmethods.defaultKey(defaults to'key') when a key is empty but the value is not empty.The
KvObjectEditorcomponent was updated to pass the placeholder key value when callingtoJSON, ensuring that custom placeholders are respected.Changes
Core Logic:
app/lib/kv-object.jsdefaultKeyparameter totoJSONmethod.defaultKeywhen key is empty and value is not empty.toJSONStringto propagate the parameter.UI Component:
lib/core/addon/components/kv-object-editor.jsupdateRowanddeleteRowactions to pass placeholder key totoJSON.Tests:
tests/unit/lib/kv-object-test.js.tests/integration/components/kv-object-editor-test.js.Testing
Unit Tests
Integration Tests
KvObjectEditorcomponent uses "key" as the default.Manual Testing Steps
test/mysecret).secret.data.key.Backward Compatibility
The changes are fully backward compatible:
defaultKeyparameter has a default value, so existing code continues to work.Screenshots
Before
Creating a secret with empty key resulted in:
{ "": "myvalue" }After
Creating a secret with empty key now results in:
{ "key": "myvalue" }