From 527f4fe2baef81685688feffe2993b23ad20f555 Mon Sep 17 00:00:00 2001 From: claire bontempo <68122737+hellobontempo@users.noreply.github.com> Date: Tue, 23 May 2023 15:24:53 -0700 Subject: [PATCH] UI: add pki cluster config parameters (#20724) * add config directory, rename crl and urls models * fix imports * add cluster config fields to edit form * reorder url save * update tests * add to details page * add details test; * fix adapter name * fix cluster adapter test name * combine adapter tests * update imports * fix git diff * move crl and urls adapters to config folder * add config file * woops add config adapter * final renaming!! * fix imports after naming to base * add cluster to beforeModel hook * hide help text * maybe you should write tests that actually pass, claire * seriously claire its embarrassing --- .../adapters/pki/{crl.js => config/base.js} | 9 +-- ui/app/adapters/pki/config/cluster.js | 15 ++++ ui/app/adapters/pki/config/crl.js | 15 ++++ ui/app/adapters/pki/config/urls.js | 15 ++++ ui/app/adapters/pki/urls.js | 24 ------- ui/app/models/pki/config/cluster.js | 40 +++++++++++ ui/app/models/pki/{ => config}/crl.js | 2 +- ui/app/models/pki/{ => config}/urls.js | 2 +- .../page/pki-configuration-details.hbs | 14 +++- .../page/pki-configuration-details.ts | 4 +- .../page/pki-configuration-edit.hbs | 19 ++++++ .../components/page/pki-configuration-edit.ts | 16 ++--- .../pki/addon/components/pki-generate-root.ts | 8 ++- ui/lib/pki/addon/routes/application.js | 3 +- ui/lib/pki/addon/routes/configuration.js | 5 +- ui/lib/pki/addon/routes/configuration/edit.js | 3 +- .../pki/addon/routes/configuration/index.js | 3 +- .../addon/templates/configuration/edit.hbs | 7 +- .../addon/templates/configuration/index.hbs | 3 +- .../pki/pki-engine-route-cleanup-test.js | 8 +-- .../pki/page/pki-configuration-edit.js | 2 + .../page/pki-configuration-details-test.js | 22 +++++- .../pki/page/pki-configuration-edit-test.js | 34 ++++++++-- .../pki/page/pki-configure-create-test.js | 2 +- .../components/pki/pki-generate-root-test.js | 2 +- ui/tests/unit/adapters/pki/config-test.js | 68 +++++++++++++++++++ ui/tests/unit/adapters/pki/crl-test.js | 45 ------------ ui/tests/unit/adapters/pki/urls-test.js | 45 ------------ .../vault/models/pki/{ => config}/crl.d.ts | 2 +- .../vault/models/pki/{ => config}/urls.d.ts | 2 +- 30 files changed, 278 insertions(+), 161 deletions(-) rename ui/app/adapters/pki/{crl.js => config/base.js} (59%) create mode 100644 ui/app/adapters/pki/config/cluster.js create mode 100644 ui/app/adapters/pki/config/crl.js create mode 100644 ui/app/adapters/pki/config/urls.js delete mode 100644 ui/app/adapters/pki/urls.js create mode 100644 ui/app/models/pki/config/cluster.js rename ui/app/models/pki/{ => config}/crl.js (98%) rename ui/app/models/pki/{ => config}/urls.js (95%) create mode 100644 ui/tests/unit/adapters/pki/config-test.js delete mode 100644 ui/tests/unit/adapters/pki/crl-test.js delete mode 100644 ui/tests/unit/adapters/pki/urls-test.js rename ui/types/vault/models/pki/{ => config}/crl.d.ts (86%) rename ui/types/vault/models/pki/{ => config}/urls.d.ts (81%) diff --git a/ui/app/adapters/pki/crl.js b/ui/app/adapters/pki/config/base.js similarity index 59% rename from ui/app/adapters/pki/crl.js rename to ui/app/adapters/pki/config/base.js index 037601a82..a655d09cf 100644 --- a/ui/app/adapters/pki/crl.js +++ b/ui/app/adapters/pki/config/base.js @@ -3,16 +3,11 @@ * SPDX-License-Identifier: MPL-2.0 */ -import { encodePath } from 'vault/utils/path-encoding-helpers'; -import ApplicationAdapter from '../application'; +import ApplicationAdapter from '../../application'; -export default class PkiCrlAdapter extends ApplicationAdapter { +export default class PkiConfigBaseAdapter extends ApplicationAdapter { namespace = 'v1'; - _url(backend) { - return `${this.buildURL()}/${encodePath(backend)}/config/crl`; - } - findRecord(store, type, backend) { return this.ajax(this._url(backend), 'GET').then((resp) => { return resp.data; diff --git a/ui/app/adapters/pki/config/cluster.js b/ui/app/adapters/pki/config/cluster.js new file mode 100644 index 000000000..aa164261c --- /dev/null +++ b/ui/app/adapters/pki/config/cluster.js @@ -0,0 +1,15 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +import { encodePath } from 'vault/utils/path-encoding-helpers'; +import PkiConfigBaseAdapter from './base'; + +export default class PkiConfigClusterAdapter extends PkiConfigBaseAdapter { + namespace = 'v1'; + + _url(backend) { + return `${this.buildURL()}/${encodePath(backend)}/config/cluster`; + } +} diff --git a/ui/app/adapters/pki/config/crl.js b/ui/app/adapters/pki/config/crl.js new file mode 100644 index 000000000..d7e5dc839 --- /dev/null +++ b/ui/app/adapters/pki/config/crl.js @@ -0,0 +1,15 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +import { encodePath } from 'vault/utils/path-encoding-helpers'; +import PkiConfigBaseAdapter from './base'; + +export default class PkiConfigCrlAdapter extends PkiConfigBaseAdapter { + namespace = 'v1'; + + _url(backend) { + return `${this.buildURL()}/${encodePath(backend)}/config/crl`; + } +} diff --git a/ui/app/adapters/pki/config/urls.js b/ui/app/adapters/pki/config/urls.js new file mode 100644 index 000000000..ae15f5959 --- /dev/null +++ b/ui/app/adapters/pki/config/urls.js @@ -0,0 +1,15 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +import { encodePath } from 'vault/utils/path-encoding-helpers'; +import PkiConfigBaseAdapter from './base'; + +export default class PkiConfigUrlsAdapter extends PkiConfigBaseAdapter { + namespace = 'v1'; + + _url(backend) { + return `${this.buildURL()}/${encodePath(backend)}/config/urls`; + } +} diff --git a/ui/app/adapters/pki/urls.js b/ui/app/adapters/pki/urls.js deleted file mode 100644 index 18f768b1c..000000000 --- a/ui/app/adapters/pki/urls.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) HashiCorp, Inc. - * SPDX-License-Identifier: MPL-2.0 - */ - -import { encodePath } from 'vault/utils/path-encoding-helpers'; -import ApplicationAdapter from '../application'; - -export default class PkiUrlsAdapter extends ApplicationAdapter { - namespace = 'v1'; - - _url(backend) { - return `${this.buildURL()}/${encodePath(backend)}/config/urls`; - } - - updateRecord(store, type, snapshot) { - const data = snapshot.serialize(); - return this.ajax(this._url(snapshot.record.id), 'POST', { data }); - } - - urlForFindRecord(id) { - return this._url(id); - } -} diff --git a/ui/app/models/pki/config/cluster.js b/ui/app/models/pki/config/cluster.js new file mode 100644 index 000000000..74c614f49 --- /dev/null +++ b/ui/app/models/pki/config/cluster.js @@ -0,0 +1,40 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +import Model, { attr } from '@ember-data/model'; +import { withFormFields } from 'vault/decorators/model-form-fields'; +import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities'; + +@withFormFields() +export default class PkiConfigClusterModel extends Model { + // This model uses the backend value as the model ID + get useOpenAPI() { + return true; + } + + getHelpUrl(backendPath) { + return `/v1/${backendPath}/config/cluster?help=1`; + } + + @attr('string', { + label: "Mount's API path", + subText: + "Specifies the path to this performance replication cluster's API mount path, including any namespaces as path components. This address is used for the ACME directories, which must be served over a TLS-enabled listener.", + }) + path; + @attr('string', { + label: 'AIA path', + subText: + "Specifies the path to this performance replication cluster's AIA distribution point; may refer to an external, non-Vault responder.", + }) + aiaPath; + + // this is for pki-only cluster config, not the universal vault cluster + @lazyCapabilities(apiPath`${'id'}/config/cluster`, 'id') clusterPath; + + get canSet() { + return this.clusterPath.get('canCreate') !== false; + } +} diff --git a/ui/app/models/pki/crl.js b/ui/app/models/pki/config/crl.js similarity index 98% rename from ui/app/models/pki/crl.js rename to ui/app/models/pki/config/crl.js index 55030c3d5..6d7490e3b 100644 --- a/ui/app/models/pki/crl.js +++ b/ui/app/models/pki/config/crl.js @@ -17,7 +17,7 @@ const formFieldGroups = [ { 'Unified Revocation': ['crossClusterRevocation', 'unifiedCrl', 'unifiedCrlOnExistingPaths'] }, ]; @withFormFields(null, formFieldGroups) -export default class PkiCrlModel extends Model { +export default class PkiConfigCrlModel extends Model { // This model uses the backend value as the model ID @attr('boolean') autoRebuild; diff --git a/ui/app/models/pki/urls.js b/ui/app/models/pki/config/urls.js similarity index 95% rename from ui/app/models/pki/urls.js rename to ui/app/models/pki/config/urls.js index 76bfa7e22..ade9b8450 100644 --- a/ui/app/models/pki/urls.js +++ b/ui/app/models/pki/config/urls.js @@ -8,7 +8,7 @@ import { withFormFields } from 'vault/decorators/model-form-fields'; import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities'; @withFormFields() -export default class PkiUrlsModel extends Model { +export default class PkiConfigUrlsModel extends Model { // This model uses the backend value as the model ID get useOpenAPI() { return true; diff --git a/ui/lib/pki/addon/components/page/pki-configuration-details.hbs b/ui/lib/pki/addon/components/page/pki-configuration-details.hbs index aa047999e..d6920bdfd 100644 --- a/ui/lib/pki/addon/components/page/pki-configuration-details.hbs +++ b/ui/lib/pki/addon/components/page/pki-configuration-details.hbs @@ -23,8 +23,20 @@ + {{#if (not (eq @cluster 403))}} +