From 3679be155fe23ec0401ed7e2e6b71dca139b0d60 Mon Sep 17 00:00:00 2001 From: Vault Automation Date: Fri, 15 May 2026 11:39:49 -0600 Subject: [PATCH] Ember Data Migration - Keymanagement Provider views | VAULT-44905 (#14816) (#14828) * VAULT-44904 - edm for keymgmt key views * resolved pr review comments * moved distribution fields to component and added util tests * fixed review comments * updated key-edit component to use form and fixed failing tests * VAULT-44905 - edm keymgmt provider views --------- Co-authored-by: mohit-hashicorp Co-authored-by: Copilot --- ui/app/components/keymgmt/distribute.hbs | 10 +- ui/app/components/keymgmt/distribute.js | 93 +++++++-- ui/app/components/keymgmt/key-edit.js | 2 +- ui/app/components/keymgmt/provider-edit.hbs | 103 ++++++---- ui/app/components/keymgmt/provider-edit.js | 182 ++++++++++++++---- .../vault/cluster/secrets/backend/list.js | 31 +-- ui/app/forms/keymgmt/provider.ts | 161 ++++++++++++++++ .../cluster/secrets/backend/create-root.js | 9 + .../vault/cluster/secrets/backend/list.js | 72 ++++++- .../cluster/secrets/backend/secret-edit.js | 53 ++++- ui/app/utils/constants/capabilities.ts | 3 + ui/app/utils/keymgmt-provider-utils.ts | 30 +++ .../components/keymgmt/provider-edit-test.js | 87 +++++---- .../unit/utils/keymgmt-provider-utils-test.ts | 49 +++++ 14 files changed, 726 insertions(+), 159 deletions(-) create mode 100644 ui/app/forms/keymgmt/provider.ts create mode 100644 ui/app/utils/keymgmt-provider-utils.ts create mode 100644 ui/tests/unit/utils/keymgmt-provider-utils-test.ts diff --git a/ui/app/components/keymgmt/distribute.hbs b/ui/app/components/keymgmt/distribute.hbs index 68fed818a3..d59a523e25 100644 --- a/ui/app/components/keymgmt/distribute.hbs +++ b/ui/app/components/keymgmt/distribute.hbs @@ -15,16 +15,15 @@
{{#if (and this.validMatchError.key (not this.isNewKey))}} @@ -94,15 +93,14 @@
diff --git a/ui/app/components/keymgmt/distribute.js b/ui/app/components/keymgmt/distribute.js index 3e7b9077ff..51ebcd7785 100644 --- a/ui/app/components/keymgmt/distribute.js +++ b/ui/app/components/keymgmt/distribute.js @@ -9,7 +9,11 @@ import { service } from '@ember/service'; import { tracked } from '@glimmer/tracking'; import { task } from 'ember-concurrency'; import { waitFor } from '@ember/test-waiters'; -import { KeyManagementUpdateKeyRequestTypeEnum } from '@hashicorp/vault-client-typescript'; +import { + KeyManagementUpdateKeyRequestTypeEnum, + SecretsApiKeyManagementListKeysListEnum, + SecretsApiKeyManagementListKmsProvidersListEnum, +} from '@hashicorp/vault-client-typescript'; const KEY_TYPES = Object.values(KeyManagementUpdateKeyRequestTypeEnum); @@ -21,7 +25,7 @@ const KEY_TYPES = Object.values(KeyManagementUpdateKeyRequestTypeEnum); * ```js * * ``` - * @param {string} backend - name of backend, which will be the basis of other store queries + * @param {string} backend - name of backend, which is used in API requests * @param {string} [key] - key is the name of the existing key which is being distributed. Will hide the key field in UI * @param {string} [provider] - provider is the name of the existing provider which is being distributed to. Will hide the provider field in UI */ @@ -39,14 +43,16 @@ const VALID_TYPES_BY_PROVIDER = { azurekeyvault: ['rsa-2048', 'rsa-3072', 'rsa-4096'], }; export default class KeymgmtDistribute extends Component { - @service store; @service api; @service flashMessages; - @service router; @tracked keyModel; @tracked isNewKey = false; + @tracked keyOptions = []; + @tracked canListKeys = true; @tracked providerType; + @tracked providerOptions = []; + @tracked canListProviders = true; @tracked formData; @tracked formErrors; @@ -59,9 +65,13 @@ export default class KeymgmtDistribute extends Component { // Side effects to get types of key or provider passed in if (this.args.provider) { this.getProviderType(this.args.provider); + } else { + this.fetchProviderOptions(); } if (this.args.key) { this.getKeyInfo(this.args.key); + } else { + this.fetchKeyOptions(); } this.formData.operations = []; } @@ -145,19 +155,52 @@ export default class KeymgmtDistribute extends Component { } } + async fetchKeyOptions() { + try { + const { keys } = await this.api.secrets.keyManagementListKeys( + this.args.backend, + SecretsApiKeyManagementListKeysListEnum.TRUE + ); + this.keyOptions = (keys || []).map((name) => ({ id: name, name })); + this.canListKeys = true; + } catch (error) { + const { status } = await this.api.parseError(error); + if (status === 403) { + this.canListKeys = false; + } + this.keyOptions = []; + } + } + async getProviderType(id) { if (!id) { this.providerType = ''; return; } - const provider = await this.store - .queryRecord('keymgmt/provider', { - backend: this.args.backend, - id, - }) - .catch(() => {}); - this.providerType = provider?.provider; + try { + const { data } = await this.api.secrets.keyManagementReadKmsProvider(id, this.args.backend); + this.providerType = data.provider; + } catch { + this.providerType = ''; + } + } + + async fetchProviderOptions() { + try { + const { keys } = await this.api.secrets.keyManagementListKmsProviders( + this.args.backend, + SecretsApiKeyManagementListKmsProvidersListEnum.TRUE + ); + this.providerOptions = (keys || []).map((name) => ({ id: name, name })); + this.canListProviders = true; + } catch (error) { + const { status } = await this.api.parseError(error); + if (status === 403) { + this.canListProviders = false; + } + this.providerOptions = []; + } } destroyKey() { @@ -224,13 +267,33 @@ export default class KeymgmtDistribute extends Component { @action async handleKeySelect(selected) { - const selectedKey = selected[0] || null; - if (!selectedKey) { + let keyName; + let isNew = false; + + if (typeof selected === 'string') { + keyName = selected; + } else if (Array.isArray(selected)) { + const selectedKey = selected[0] || null; + if (!selectedKey) { + this.formData.key = null; + return this.destroyKey(); + } + + if (typeof selectedKey === 'string') { + keyName = selectedKey; + } else { + keyName = selectedKey.id; + isNew = !!selectedKey.isNew; + } + } + + if (!keyName) { this.formData.key = null; return this.destroyKey(); } - this.formData.key = selectedKey.id; - return this.getKeyInfo(selectedKey.id, selectedKey.isNew); + + this.formData.key = keyName; + return this.getKeyInfo(keyName, isNew); } @task diff --git a/ui/app/components/keymgmt/key-edit.js b/ui/app/components/keymgmt/key-edit.js index a0f288895d..9d5232263b 100644 --- a/ui/app/components/keymgmt/key-edit.js +++ b/ui/app/components/keymgmt/key-edit.js @@ -9,7 +9,7 @@ import { action } from '@ember/object'; import { tracked } from '@glimmer/tracking'; import { task } from 'ember-concurrency'; import { waitFor } from '@ember/test-waiters'; -import { isValidProvider } from 'vault/utils/keymgmt-provider-validator'; +import { isValidProvider } from 'vault/utils/keymgmt-provider-utils'; /** * @module KeymgmtKeyEdit diff --git a/ui/app/components/keymgmt/provider-edit.hbs b/ui/app/components/keymgmt/provider-edit.hbs index 4e85239f75..1a2461ce9e 100644 --- a/ui/app/components/keymgmt/provider-edit.hbs +++ b/ui/app/components/keymgmt/provider-edit.hbs @@ -10,20 +10,24 @@ {{#if this.isDistributing}} - + {{else}} {{#if this.isShowing}}