mirror of
https://github.com/hashicorp/vault.git
synced 2025-11-09 21:01:27 +01:00
* adds error handling for control groups to api service as post request middleware * updates kv list route to use api service * updates kv config route to use api service * updates kv secrets overview route to use api service * updates kv secret details route to use api service * adds kv form * updates kv metadata details route to use api service * updates kv paths and version history routes to use api service * refactors kv-data-fields component to form component * updates kv secret create route to use api service * updates kv secret edit route to use api service * updates kv metadata edit route to use api service * adds waitFor to async middleware in api service to attempt to fix race conditions in tests * adds kvMetadata path to capabilities path map * fixes kv list item delete test selector * removes kv models, adapters and serializers * removes store from kv addon * removes ember data related test helpers from kv-run-commands * updates comments that referred to kv ember data models * updates kv-page-header tests * updates model-form-fields test to use totp-key model rather than kv/data * removes another reference to kv/data model from path-help test * fixes kv v2 workflow create tests * fixes issue returning metadata for secret when latest version is deleted * decodes uri in path returned by api service parseError method * fixes kv v2 edge cases tests * fixes issue deleteing control group token in api service * decodes url for control group token lookup in api service * fixes version history linked block link * defaults cas to 0 when creating new secret * removes log * adds ember-template-lint to kv engine * more test fixes * updates kv-suggestion-input component to use api service * removes kv metadata model reference from quick actions card * fixes sync destination sync secrets tests * updates kv helpers from classic format * updates kv helpers imports * reverts to use secret.version in details edit route * fixes isDeleted import in kv version history test * adds waitFor to api service parseError method * reverts removing async from addQueryParams api method * attempts to fix test flakiness requesting custom metadata from data endpoint * more tweaks to requesting metadata from data * adds waitFor to requestData method Co-authored-by: Jordan Reimer <zofskeez@gmail.com>
154 lines
4.5 KiB
JavaScript
154 lines
4.5 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Component from '@glimmer/component';
|
|
import { action } from '@ember/object';
|
|
import { tracked } from '@glimmer/tracking';
|
|
import { service } from '@ember/service';
|
|
import { pathIsDirectory } from 'kv/utils/kv-breadcrumbs';
|
|
/**
|
|
* @module DashboardQuickActionsCard
|
|
* DashboardQuickActionsCard component allows users to see a list of secrets engines filtered by
|
|
* kv, pki and database and perform certain actions based on the type of secret engine selected
|
|
*
|
|
* @example
|
|
* ```js
|
|
* <Dashboard::QuickActionsCard @secretsEngines={{@model.secretsEngines}} />
|
|
* ```
|
|
*/
|
|
|
|
const QUICK_ACTION_ENGINES = ['pki', 'database'];
|
|
|
|
export default class DashboardQuickActionsCard extends Component {
|
|
@service router;
|
|
|
|
@tracked selectedEngine;
|
|
@tracked selectedAction;
|
|
@tracked paramValue;
|
|
|
|
get actionOptions() {
|
|
switch (this.selectedEngine.type) {
|
|
case 'kv':
|
|
return ['Find KV secrets'];
|
|
case 'database':
|
|
return ['Generate credentials for database'];
|
|
case 'pki':
|
|
return ['Issue certificate', 'View certificate', 'View issuer'];
|
|
default:
|
|
return [];
|
|
}
|
|
}
|
|
|
|
get searchSelectParams() {
|
|
switch (this.selectedAction) {
|
|
case 'Find KV secrets':
|
|
return {
|
|
isKV: true,
|
|
buttonText: 'Read secrets',
|
|
route: 'vault.cluster.secrets.backend.kv.secret.index',
|
|
};
|
|
case 'Generate credentials for database':
|
|
return {
|
|
title: 'Role to use',
|
|
buttonText: 'Generate credentials',
|
|
model: 'database/role',
|
|
route: 'vault.cluster.secrets.backend.credentials',
|
|
queryObject: { backend: this.selectedEngine.id },
|
|
};
|
|
case 'Issue certificate':
|
|
return {
|
|
title: 'Role to use',
|
|
placeholder: 'Type to find a role',
|
|
buttonText: 'Issue leaf certificate',
|
|
model: 'pki/role',
|
|
route: 'vault.cluster.secrets.backend.pki.roles.role.generate',
|
|
queryObject: { backend: this.selectedEngine.id },
|
|
};
|
|
case 'View certificate':
|
|
return {
|
|
title: 'Certificate serial number',
|
|
placeholder: '33:a3:...',
|
|
buttonText: 'View certificate',
|
|
model: 'pki/certificate/base',
|
|
route: 'vault.cluster.secrets.backend.pki.certificates.certificate.details',
|
|
queryObject: { backend: this.selectedEngine.id },
|
|
};
|
|
case 'View issuer':
|
|
return {
|
|
title: 'Issuer',
|
|
placeholder: 'Type issuer name or ID',
|
|
buttonText: 'View issuer',
|
|
model: 'pki/issuer',
|
|
route: 'vault.cluster.secrets.backend.pki.issuers.issuer.details',
|
|
nameKey: 'issuerName',
|
|
queryObject: { backend: this.selectedEngine.id },
|
|
objectKeys: ['id', 'issuerName'],
|
|
};
|
|
default:
|
|
return {
|
|
placeholder: 'Please select an action above',
|
|
buttonText: 'Select an action',
|
|
model: '',
|
|
};
|
|
}
|
|
}
|
|
|
|
get filteredSecretEngines() {
|
|
return this.args.secretsEngines?.filter(
|
|
(engine) => (engine.type === 'kv' && engine.version == 2) || QUICK_ACTION_ENGINES.includes(engine.type)
|
|
);
|
|
}
|
|
|
|
get mountOptions() {
|
|
return this.filteredSecretEngines?.map((engine) => {
|
|
const { id, type } = engine;
|
|
|
|
return { name: id, type, id };
|
|
});
|
|
}
|
|
|
|
@action
|
|
handleSearchEngineSelect([selection]) {
|
|
this.selectedEngine = selection;
|
|
// reset tracked properties
|
|
this.selectedAction = null;
|
|
this.paramValue = null;
|
|
}
|
|
|
|
@action
|
|
setSelectedAction(selectedAction) {
|
|
this.selectedAction = selectedAction;
|
|
this.paramValue = null;
|
|
}
|
|
|
|
@action
|
|
handleActionSelect(val) {
|
|
if (Array.isArray(val)) {
|
|
this.paramValue = val[0];
|
|
} else {
|
|
this.paramValue = val;
|
|
}
|
|
}
|
|
|
|
@action
|
|
navigateToPage() {
|
|
let route = this.searchSelectParams.route;
|
|
// If search-select falls back to stringInput, paramValue is a string not object
|
|
let param = this.paramValue.id || this.paramValue;
|
|
|
|
// kv has a special use case where if the paramValue ends in a '/' you should
|
|
// link to different route
|
|
if (this.selectedEngine.type === 'kv') {
|
|
const path = this.paramValue.path || this.paramValue;
|
|
route = pathIsDirectory(path)
|
|
? 'vault.cluster.secrets.backend.kv.list-directory'
|
|
: 'vault.cluster.secrets.backend.kv.secret.index';
|
|
param = path;
|
|
}
|
|
|
|
this.router.transitionTo(route, this.selectedEngine.id, param);
|
|
}
|
|
}
|