PKI cleanup continued: queryParams and moving routes/models/serializers to pki folder (#15980)

* routing params

* wip for cert

* move pki-config

* clean up
This commit is contained in:
Angel Garbarino 2022-06-15 16:51:42 -07:00 committed by GitHub
parent 753e925f22
commit f67efae0a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 27 additions and 19 deletions

View File

@ -2,7 +2,7 @@ import AdapterError from '@ember-data/adapter/error';
import { hash, resolve } from 'rsvp';
import { capitalize } from '@ember/string';
import { set } from '@ember/object';
import ApplicationAdapter from './application';
import ApplicationAdapter from '../application';
export default ApplicationAdapter.extend({
namespace: 'v1',

View File

@ -16,7 +16,7 @@ const MODEL_TYPES = {
backIsListLink: true,
},
'pki-issue': {
model: 'pki/pki-certificate',
model: 'pki/cert',
title: 'Issue Certificate',
},
'pki-sign': {

View File

@ -34,13 +34,13 @@ const SECRET_BACKENDS = {
editComponent: 'pki/role-pki-edit',
},
{
name: 'certs',
name: 'cert',
modelPrefix: 'cert/',
label: 'Certificates',
searchPlaceholder: 'Filter certificates',
item: 'certificates',
create: 'Create role',
tab: 'certs',
tab: 'cert',
listItemPartial: 'secret-list/pki-cert-item',
editComponent: 'pki/pki-cert-show',
},

View File

@ -1,6 +1,6 @@
import { attr } from '@ember-data/model';
import { computed } from '@ember/object';
import Certificate from './pki/pki-certificate';
import Certificate from './pki/cert';
export default Certificate.extend({
DISPLAY_FIELDS: computed(function () {

View File

@ -1,7 +1,7 @@
import { attr } from '@ember-data/model';
import { copy } from 'ember-copy';
import { computed } from '@ember/object';
import Certificate from './pki/pki-certificate';
import Certificate from './pki/cert';
import { combineFieldGroups } from 'vault/utils/openapi-to-attrs';
export default Certificate.extend({

View File

@ -80,7 +80,7 @@ export default Route.extend({
ssh: 'role-ssh',
transform: this.modelTypeForTransform(tab),
aws: 'role-aws',
pki: tab === 'certs' ? 'pki/pki-certificate' : 'pki/pki-role',
pki: `pki/${tab || 'pki-role'}`,
// secret or secret-v2
cubbyhole: 'secret',
kv: secretEngine.get('modelTypeForKV'),
@ -130,7 +130,7 @@ export default Route.extend({
afterModel(model) {
const { tab } = this.paramsFor(this.routeName);
const backend = this.enginePathParam();
if (!tab || tab !== 'certs') {
if (!tab || tab !== 'cert') {
return;
}
return all(
@ -138,7 +138,7 @@ export default Route.extend({
// possible that there is no certificate for them in order to know,
// we fetch them specifically on the list page, and then unload the
// records if there is no `certificate` attribute on the resultant model
['ca', 'crl', 'ca_chain'].map((id) => this.store.queryRecord('pki/pki-certificate', { id, backend }))
['ca', 'crl', 'ca_chain'].map((id) => this.store.queryRecord('pki/cert', { id, backend }))
).then(
(results) => {
results.rejectBy('certificate').forEach((record) => record.unloadRecord());

View File

@ -101,7 +101,7 @@ export default Route.extend(UnloadModelRoute, {
ssh: 'role-ssh',
transform: this.modelTypeForTransform(secret),
aws: 'role-aws',
pki: secret && secret.startsWith('cert/') ? 'pki/pki-certificate' : 'pki/pki-role',
pki: secret && secret.startsWith('cert/') ? 'pki/cert' : 'pki/pki-role',
cubbyhole: 'secret',
kv: backendModel.get('modelTypeForKV'),
keymgmt: `keymgmt/${options.queryParams?.itemType || 'key'}`,
@ -230,7 +230,7 @@ export default Route.extend(UnloadModelRoute, {
if (!secret) {
secret = '\u0020';
}
if (modelType === 'pki/pki-certificate') {
if (modelType === 'pki/cert') {
secret = secret.replace('cert/', '');
}
if (modelType.startsWith('transform/')) {

View File

@ -2,6 +2,7 @@ import AdapterError from '@ember-data/adapter/error';
import { set } from '@ember/object';
import Route from '@ember/routing/route';
// ARG TODO glimmerize
const SECTIONS_FOR_TYPE = {
pki: ['cert', 'urls', 'crl', 'tidy'],
};
@ -9,14 +10,21 @@ export default Route.extend({
fetchModel() {
const { section_name: sectionName } = this.paramsFor(this.routeName);
const backendModel = this.modelFor('vault.cluster.settings.configure-secret-backend');
const modelType = `${backendModel.get('type')}-config`;
const type = backendModel.get('type');
let modelType;
if (type === 'pki') {
// pki models are in models/pki
modelType = `${type}/${type}-config`;
} else {
modelType = `${type}-config`;
}
return this.store
.queryRecord(modelType, {
backend: backendModel.id,
section: sectionName,
})
.then((model) => {
model.set('backendType', backendModel.get('type'));
model.set('backendType', type);
model.set('section', sectionName);
return model;
});

View File

@ -75,7 +75,7 @@
</CopyButton>
</div>
<div class="control">
<LinkTo @route="vault.cluster.secrets.backend.list-root" @query={{hash tab="certs"}} class="button">
<LinkTo @route="vault.cluster.secrets.backend.list-root" @query={{hash tab="cert"}} class="button">
Back
</LinkTo>
</div>

View File

@ -1,5 +1,5 @@
<SecretListHeader
@isCertTab={{eq this.tab "certs"}}
@isCertTab={{eq this.tab "cert"}}
@model={{this.backendModel}}
@baseKey={{this.baseKey}}
@backendCrumb={{this.backendCrumb}}
@ -49,7 +49,7 @@
@baseKey={{get this.baseKey "id"}}
@shouldNavigateTree={{options.navigateTree}}
@placeholder={{options.searchPlaceholder}}
@mode={{if (eq this.tab "certs") "secrets-cert" "secrets"}}
@mode={{if (eq this.tab "cert") "secrets-cert" "secrets"}}
/>
{{#if this.filterFocused}}
{{#if this.filterMatchesKey}}

View File

@ -1,5 +1,5 @@
<SecretListHeader
@isCertTab={{eq this.tab "certs"}}
@isCertTab={{eq this.tab "cert"}}
@model={{this.model}}
@baseKey={{this.baseKey}}
@backendCrumb={{this.backendCrumb}}

View File

@ -9,7 +9,7 @@ import enablePage from 'vault/tests/pages/settings/mount-secret-backend';
import authPage from 'vault/tests/pages/auth';
import { SELECTORS } from 'vault/tests/helpers/pki';
module('Acceptance | secrets/pki/list?tab=certs', function (hooks) {
module('Acceptance | secrets/pki/list?tab=cert', function (hooks) {
setupApplicationTest(hooks);
hooks.beforeEach(function () {
@ -88,7 +88,7 @@ elRplAzrMF4=
const path = await setup(assert);
await generatePage.issueCert('foo');
await settled();
await listPage.visitRoot({ backend: path, tab: 'certs' });
await listPage.visitRoot({ backend: path, tab: 'cert' });
await settled();
assert.ok(listPage.secrets.length > 0, 'lists certs');
await listPage.secrets.objectAt(0).click();