diff --git a/ui/app/adapters/pki/key.js b/ui/app/adapters/pki/key.js index 32e014baff94..91a979509a24 100644 --- a/ui/app/adapters/pki/key.js +++ b/ui/app/adapters/pki/key.js @@ -4,24 +4,21 @@ import { encodePath } from 'vault/utils/path-encoding-helpers'; export default class PkiKeyAdapter extends ApplicationAdapter { namespace = 'v1'; - optionsForQuery(id) { - const data = {}; - if (!id) { - data['list'] = true; - } - return { data }; - } - - urlForQuery(backend, id) { - let url = `${this.buildURL()}/${encodePath(backend)}/keys`; + getUrl(backend, id) { + const url = `${this.buildURL()}/${encodePath(backend)}`; if (id) { - url = url + '/' + encodePath(id); + return url + '/key/' + encodePath(id); } - return url; + return url + '/keys'; } query(store, type, query) { + const { backend } = query; + return this.ajax(this.getUrl(backend), 'GET', { data: { list: true } }); + } + + queryRecord(store, type, query) { const { backend, id } = query; - return this.ajax(this.urlForQuery(backend, id), 'GET', this.optionsForQuery(id)); + return this.ajax(this.getUrl(backend, id), 'GET'); } } diff --git a/ui/app/models/pki/key.js b/ui/app/models/pki/key.js index 6c465a10d1ae..d767289e773f 100644 --- a/ui/app/models/pki/key.js +++ b/ui/app/models/pki/key.js @@ -1,10 +1,18 @@ import Model, { attr } from '@ember-data/model'; +import { expandAttributeMeta } from 'vault/utils/field-to-attrs'; export default class PkiKeyModel extends Model { @attr('string', { readOnly: true }) backend; @attr('boolean') isDefault; - @attr('string') keyRef; // reference to an existing key: either, vault generate identifier, literal string 'default', or the name assigned to the key. Part of the request URL. - @attr('string') keyId; + @attr('string', { possibleValues: ['internal', 'external'] }) type; + @attr('string', { detailsLabel: 'Key ID' }) keyId; @attr('string') keyName; @attr('string') keyType; + @attr('string', { detailsLabel: 'Key bit length' }) keyBits; // TODO confirm with crypto team to remove this field from details page + + // TODO refactor when field-to-attrs util is refactored as decorator + constructor() { + super(...arguments); + this.formFields = expandAttributeMeta(this, ['keyId', 'keyName', 'keyType', 'keyBits']); + } } diff --git a/ui/app/serializers/pki/key.js b/ui/app/serializers/pki/key.js index de645399d252..c2f7ef0b1d7e 100644 --- a/ui/app/serializers/pki/key.js +++ b/ui/app/serializers/pki/key.js @@ -1,11 +1,12 @@ import ApplicationSerializer from '../application'; export default class PkiKeySerializer extends ApplicationSerializer { + primaryKey = 'key_id'; // rehydrate each keys model so all model attributes are accessible from the LIST response normalizeItems(payload) { if (payload.data) { if (payload.data?.keys && Array.isArray(payload.data.keys)) { - return payload.data.keys.map((key) => ({ id: key, ...payload.data.key_info[key] })); + return payload.data.keys.map((key) => ({ key_id: key, ...payload.data.key_info[key] })); } Object.assign(payload, payload.data); delete payload.data; diff --git a/ui/lib/pki/addon/components/pki-key-details.hbs b/ui/lib/pki/addon/components/pki-key-details.hbs new file mode 100644 index 000000000000..070eb1daceda --- /dev/null +++ b/ui/lib/pki/addon/components/pki-key-details.hbs @@ -0,0 +1,56 @@ + + + {{! TODO: This should be replaced with HDS::Breadcrumbs }} + + + +

+ + View key +

+
+
+ + + + Delete + + + Edit key + + + + +
+ {{#each @key.formFields as |attr|}} + + {{/each}} +
\ No newline at end of file diff --git a/ui/lib/pki/addon/components/pki-key-details.ts b/ui/lib/pki/addon/components/pki-key-details.ts new file mode 100644 index 000000000000..0f3f52006571 --- /dev/null +++ b/ui/lib/pki/addon/components/pki-key-details.ts @@ -0,0 +1,24 @@ +import { action } from '@ember/object'; +import Component from '@glimmer/component'; + +interface Args { + key: { + backend: string; + keyName: string; + keyId: string; + }; +} + +export default class PkiKeyDetails extends Component { + get breadcrumbs() { + return [ + { label: this.args.key.backend || 'pki', path: 'overview' }, + { label: 'keys', path: 'keys.index' }, + { label: this.args.key.keyId }, + ]; + } + + @action deleteKey() { + // TODO handle delete + } +} diff --git a/ui/lib/pki/addon/controllers/issuers/index.js b/ui/lib/pki/addon/controllers/issuers/index.js index f829d7f37107..381e7d107c4f 100644 --- a/ui/lib/pki/addon/controllers/issuers/index.js +++ b/ui/lib/pki/addon/controllers/issuers/index.js @@ -3,7 +3,7 @@ import { action } from '@ember/object'; import { next } from '@ember/runloop'; import { getOwner } from '@ember/application'; -export default class PkiRolesIssuerController extends Controller { +export default class PkiIssuerIndexController extends Controller { get mountPoint() { return getOwner(this).mountPoint; } diff --git a/ui/lib/pki/addon/controllers/keys/index.js b/ui/lib/pki/addon/controllers/keys/index.js index 518e459540f0..792031c9be15 100644 --- a/ui/lib/pki/addon/controllers/keys/index.js +++ b/ui/lib/pki/addon/controllers/keys/index.js @@ -1,7 +1,7 @@ import Controller from '@ember/controller'; import { getOwner } from '@ember/application'; -export default class PkiRolesIssuerController extends Controller { +export default class PkiKeysIndexController extends Controller { get mountPoint() { return getOwner(this).mountPoint; } diff --git a/ui/lib/pki/addon/routes.js b/ui/lib/pki/addon/routes.js index 568a4ce7e79d..d1e2f074652f 100644 --- a/ui/lib/pki/addon/routes.js +++ b/ui/lib/pki/addon/routes.js @@ -40,7 +40,7 @@ export default buildRoutes(function () { this.route('index', { path: '/' }); this.route('create'); this.route('import'); - this.route('key', { path: '/:key_ref' }, function () { + this.route('key', { path: '/:key_id' }, function () { this.route('details'); this.route('edit'); }); diff --git a/ui/lib/pki/addon/routes/keys/key.js b/ui/lib/pki/addon/routes/keys/key.js new file mode 100644 index 000000000000..d61ec6baf696 --- /dev/null +++ b/ui/lib/pki/addon/routes/keys/key.js @@ -0,0 +1,11 @@ +import PkiKeysIndexRoute from './index'; + +export default class PkiKeyRoute extends PkiKeysIndexRoute { + model() { + const { key_id } = this.paramsFor('keys/key'); + return this.store.queryRecord('pki/key', { + backend: this.secretMountPath.currentPath, + id: key_id, + }); + } +} diff --git a/ui/lib/pki/addon/templates/keys/index.hbs b/ui/lib/pki/addon/templates/keys/index.hbs index 32b609f03426..1159275b23f6 100644 --- a/ui/lib/pki/addon/templates/keys/index.hbs +++ b/ui/lib/pki/addon/templates/keys/index.hbs @@ -23,7 +23,7 @@ secret used to prove who they are and who they trust.

{{#if this.model.keyModel.length}} {{#each this.model.keyModel as |pkiKey|}} - +
@@ -44,12 +44,12 @@