From 1e26c1fe11c41ffa484a07036a36051a245b48de Mon Sep 17 00:00:00 2001 From: John Cowen Date: Mon, 14 Mar 2022 16:54:49 +0000 Subject: [PATCH] ui: App-ify Lock Sessions (#12482) This commit moves our in-app LockSessions code into an external 'app', which can theoretically be side-loaded but for now it just makes for good isolation/code hygiene. Functionally, there is kind of one change here, and that is we only show the 'Lock Session' tab if you have permissions to see them. Currently as our UI authorization endpoint needs to be changed slightly to suit our usecase, you will always have permissions to see Lock Sessions as we hardcode the session:read to true (obvs this is a frontend thing, not a backend thing), so it doesn't really change anything from a user perspective. Also added very bare docs while I was here. Small note here, ideally we need to add the each individual tab depending on whether an 'app' is enabled or not instead of just permissions, ideally it would be done totally from The Outside rather than a can based conditional on the inside, just something else to be thinking about for the future. --- .circleci/config.yml | 2 +- ui/package.json | 2 +- .../consul/lock-session/form/README.mdx | 0 .../consul/lock-session/form/index.hbs | 0 .../consul/lock-session/form/index.scss | 0 .../consul/lock-session/list/README.mdx | 0 .../consul/lock-session/list/index.hbs | 0 .../consul/lock-session/list/index.scss | 0 .../lock-session/notifications/README.mdx | 52 +++++++++++++++++++ .../lock-session/notifications/index.hbs | 13 ++++- .../app/templates/dc/nodes/show/sessions.hbs | 0 ui/packages/consul-lock-sessions/package.json | 5 ++ .../vendor/consul-lock-sessions/routes.js | 15 ++++++ .../vendor/consul-lock-sessions/services.js | 7 +++ ui/packages/consul-ui/.docfy-config.js | 6 +++ .../consul-ui/app/templates/dc/kv/edit.hbs | 11 +--- .../consul-ui/app/templates/dc/nodes/show.hbs | 44 ++++++++++++---- ui/packages/consul-ui/ember-cli-build.js | 1 + .../lib/startup/templates/body.html.js | 1 + ui/packages/consul-ui/package.json | 1 + .../consul-ui/translations/routes/en-us.yaml | 9 ++++ .../consul-ui/vendor/consul-ui/routes.js | 3 -- 22 files changed, 146 insertions(+), 26 deletions(-) rename ui/packages/{consul-ui => consul-lock-sessions}/app/components/consul/lock-session/form/README.mdx (100%) rename ui/packages/{consul-ui => consul-lock-sessions}/app/components/consul/lock-session/form/index.hbs (100%) rename ui/packages/{consul-ui => consul-lock-sessions}/app/components/consul/lock-session/form/index.scss (100%) rename ui/packages/{consul-ui => consul-lock-sessions}/app/components/consul/lock-session/list/README.mdx (100%) rename ui/packages/{consul-ui => consul-lock-sessions}/app/components/consul/lock-session/list/index.hbs (100%) rename ui/packages/{consul-ui => consul-lock-sessions}/app/components/consul/lock-session/list/index.scss (100%) create mode 100644 ui/packages/consul-lock-sessions/app/components/consul/lock-session/notifications/README.mdx rename ui/packages/{consul-ui => consul-lock-sessions}/app/components/consul/lock-session/notifications/index.hbs (57%) rename ui/packages/{consul-ui => consul-lock-sessions}/app/templates/dc/nodes/show/sessions.hbs (100%) create mode 100644 ui/packages/consul-lock-sessions/package.json create mode 100644 ui/packages/consul-lock-sessions/vendor/consul-lock-sessions/routes.js create mode 100644 ui/packages/consul-lock-sessions/vendor/consul-lock-sessions/services.js diff --git a/.circleci/config.yml b/.circleci/config.yml index eba2a629f..64395e67b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,7 +22,7 @@ references: test-results: &TEST_RESULTS_DIR /tmp/test-results cache: - yarn: &YARN_CACHE_KEY consul-ui-v6-{{ checksum "ui/yarn.lock" }} + yarn: &YARN_CACHE_KEY consul-ui-v7-{{ checksum "ui/yarn.lock" }} environment: &ENVIRONMENT TEST_RESULTS_DIR: *TEST_RESULTS_DIR diff --git a/ui/package.json b/ui/package.json index 3707970b1..a474ecf73 100644 --- a/ui/package.json +++ b/ui/package.json @@ -11,7 +11,7 @@ "scripts": { "doc:toc": "doctoc README.md", "compliance": "npm-run-all compliance:*", - "compliance:licenses": "license-checker --summary --onlyAllow 'Python-2.0;Apache*;Apache License, Version 2.0;Apache-2.0;Apache 2.0;Artistic-2.0;BSD;BSD-3-Clause;CC-BY-3.0;CC-BY-4.0;CC0-1.0;ISC;MIT;MPL-2.0;Public Domain;Unicode-TOU;Unlicense;WTFPL' --excludePackages 'consul-ui@2.2.0;consul-acls@0.1.0;consul-partitions@0.1.0;consul-nspaces@0.1.0'" + "compliance:licenses": "license-checker --summary --onlyAllow 'Python-2.0;Apache*;Apache License, Version 2.0;Apache-2.0;Apache 2.0;Artistic-2.0;BSD;BSD-3-Clause;CC-BY-3.0;CC-BY-4.0;CC0-1.0;ISC;MIT;MPL-2.0;Public Domain;Unicode-TOU;Unlicense;WTFPL' --excludePackages 'consul-ui@2.2.0;consul-acls@0.1.0;consul-lock-sessions@0.1.0;consul-partitions@0.1.0;consul-nspaces@0.1.0'" }, "devDependencies": { diff --git a/ui/packages/consul-ui/app/components/consul/lock-session/form/README.mdx b/ui/packages/consul-lock-sessions/app/components/consul/lock-session/form/README.mdx similarity index 100% rename from ui/packages/consul-ui/app/components/consul/lock-session/form/README.mdx rename to ui/packages/consul-lock-sessions/app/components/consul/lock-session/form/README.mdx diff --git a/ui/packages/consul-ui/app/components/consul/lock-session/form/index.hbs b/ui/packages/consul-lock-sessions/app/components/consul/lock-session/form/index.hbs similarity index 100% rename from ui/packages/consul-ui/app/components/consul/lock-session/form/index.hbs rename to ui/packages/consul-lock-sessions/app/components/consul/lock-session/form/index.hbs diff --git a/ui/packages/consul-ui/app/components/consul/lock-session/form/index.scss b/ui/packages/consul-lock-sessions/app/components/consul/lock-session/form/index.scss similarity index 100% rename from ui/packages/consul-ui/app/components/consul/lock-session/form/index.scss rename to ui/packages/consul-lock-sessions/app/components/consul/lock-session/form/index.scss diff --git a/ui/packages/consul-ui/app/components/consul/lock-session/list/README.mdx b/ui/packages/consul-lock-sessions/app/components/consul/lock-session/list/README.mdx similarity index 100% rename from ui/packages/consul-ui/app/components/consul/lock-session/list/README.mdx rename to ui/packages/consul-lock-sessions/app/components/consul/lock-session/list/README.mdx diff --git a/ui/packages/consul-ui/app/components/consul/lock-session/list/index.hbs b/ui/packages/consul-lock-sessions/app/components/consul/lock-session/list/index.hbs similarity index 100% rename from ui/packages/consul-ui/app/components/consul/lock-session/list/index.hbs rename to ui/packages/consul-lock-sessions/app/components/consul/lock-session/list/index.hbs diff --git a/ui/packages/consul-ui/app/components/consul/lock-session/list/index.scss b/ui/packages/consul-lock-sessions/app/components/consul/lock-session/list/index.scss similarity index 100% rename from ui/packages/consul-ui/app/components/consul/lock-session/list/index.scss rename to ui/packages/consul-lock-sessions/app/components/consul/lock-session/list/index.scss diff --git a/ui/packages/consul-lock-sessions/app/components/consul/lock-session/notifications/README.mdx b/ui/packages/consul-lock-sessions/app/components/consul/lock-session/notifications/README.mdx new file mode 100644 index 000000000..6d90f0fff --- /dev/null +++ b/ui/packages/consul-lock-sessions/app/components/consul/lock-session/notifications/README.mdx @@ -0,0 +1,52 @@ + +# Consul::LockSession::Notifications + + + +A Notification component specifically for LockSessions. + + + +```hbs preview-template +
+ +
+ Provide a widget for to change the @type +
+ + +
+ +
+ +
+ Use the component +
+ + + +
+``` + +## Arguments + + +| Argument | Type | Default | Description | +| :-------- | :--------------- | :------ | :------------------------------------------------- | +| type | "remove" \| "kv" | | The type of Notification to use | +| error | error | | Consul UI shaped error only used for `remove` type | + + + diff --git a/ui/packages/consul-ui/app/components/consul/lock-session/notifications/index.hbs b/ui/packages/consul-lock-sessions/app/components/consul/lock-session/notifications/index.hbs similarity index 57% rename from ui/packages/consul-ui/app/components/consul/lock-session/notifications/index.hbs rename to ui/packages/consul-lock-sessions/app/components/consul/lock-session/notifications/index.hbs index 865342932..8cf81c45e 100644 --- a/ui/packages/consul-ui/app/components/consul/lock-session/notifications/index.hbs +++ b/ui/packages/consul-lock-sessions/app/components/consul/lock-session/notifications/index.hbs @@ -33,4 +33,15 @@ {{/if}} -{{/if}} \ No newline at end of file +{{else if (eq @type 'kv')}} + + +

+ Warning. This KV has a lock session. You can edit KV's with lock sessions, but we recommend doing so with care, or not doing so at all. It may negatively impact the active node it's associated with. See below for more details on the Lock Session and see our documentation for more information. +

+
+
+{{/if}} diff --git a/ui/packages/consul-ui/app/templates/dc/nodes/show/sessions.hbs b/ui/packages/consul-lock-sessions/app/templates/dc/nodes/show/sessions.hbs similarity index 100% rename from ui/packages/consul-ui/app/templates/dc/nodes/show/sessions.hbs rename to ui/packages/consul-lock-sessions/app/templates/dc/nodes/show/sessions.hbs diff --git a/ui/packages/consul-lock-sessions/package.json b/ui/packages/consul-lock-sessions/package.json new file mode 100644 index 000000000..835990215 --- /dev/null +++ b/ui/packages/consul-lock-sessions/package.json @@ -0,0 +1,5 @@ +{ + "name": "consul-lock-sessions", + "version": "0.1.0", + "private": true +} diff --git a/ui/packages/consul-lock-sessions/vendor/consul-lock-sessions/routes.js b/ui/packages/consul-lock-sessions/vendor/consul-lock-sessions/routes.js new file mode 100644 index 000000000..6b7cb8a58 --- /dev/null +++ b/ui/packages/consul-lock-sessions/vendor/consul-lock-sessions/routes.js @@ -0,0 +1,15 @@ +(routes => routes({ + dc: { + nodes: { + show: { + sessions: { + _options: { path: '/lock-sessions' }, + }, + }, + }, + }, +}))( + (json, data = (typeof document !== 'undefined' ? document.currentScript.dataset : module.exports)) => { + data[`routes`] = JSON.stringify(json); + } +); diff --git a/ui/packages/consul-lock-sessions/vendor/consul-lock-sessions/services.js b/ui/packages/consul-lock-sessions/vendor/consul-lock-sessions/services.js new file mode 100644 index 000000000..159a7a96e --- /dev/null +++ b/ui/packages/consul-lock-sessions/vendor/consul-lock-sessions/services.js @@ -0,0 +1,7 @@ +(services => services({ + +}))( + (json, data = (typeof document !== 'undefined' ? document.currentScript.dataset : module.exports)) => { + data[`services`] = JSON.stringify(json); + } +); diff --git a/ui/packages/consul-ui/.docfy-config.js b/ui/packages/consul-ui/.docfy-config.js index d55ba88b9..323469c84 100644 --- a/ui/packages/consul-ui/.docfy-config.js +++ b/ui/packages/consul-ui/.docfy-config.js @@ -106,6 +106,12 @@ module.exports = { urlSchema: 'auto', urlPrefix: 'docs/consul-acls', }, + { + root: `${path.dirname(require.resolve('consul-lock-sessions/package.json'))}/app/components`, + pattern: '**/README.mdx', + urlSchema: 'auto', + urlPrefix: 'docs/consul-lock-sessions', + }, { root: `${path.dirname(require.resolve('consul-partitions/package.json'))}/app/components`, pattern: '**/README.mdx', diff --git a/ui/packages/consul-ui/app/templates/dc/kv/edit.hbs b/ui/packages/consul-ui/app/templates/dc/kv/edit.hbs index 04bea5263..2bdd511f5 100644 --- a/ui/packages/consul-ui/app/templates/dc/kv/edit.hbs +++ b/ui/packages/consul-ui/app/templates/dc/kv/edit.hbs @@ -97,16 +97,7 @@ as |parts|}} {{! if a KV has a session `Session` will always be populated despite any specific session permissions }} {{#if item.Session}} - - -

- Warning. This KV has a lock session. You can edit KV's with lock sessions, but we recommend doing so with care, or not doing so at all. It may negatively impact the active node it's associated with. See below for more details on the Lock Session and see our documentation for more information. -

-
-
+ {{/if}} - + {{item.Address}} diff --git a/ui/packages/consul-ui/ember-cli-build.js b/ui/packages/consul-ui/ember-cli-build.js index ec8397f89..65c72fe9b 100644 --- a/ui/packages/consul-ui/ember-cli-build.js +++ b/ui/packages/consul-ui/ember-cli-build.js @@ -29,6 +29,7 @@ module.exports = function(defaults, $ = process.env) { const apps = [ 'consul-ui', 'consul-acls', + 'consul-lock-sessions', 'consul-partitions', 'consul-nspaces' ].map(item => { diff --git a/ui/packages/consul-ui/lib/startup/templates/body.html.js b/ui/packages/consul-ui/lib/startup/templates/body.html.js index 9a2b3fe09..6956c24b9 100644 --- a/ui/packages/consul-ui/lib/startup/templates/body.html.js +++ b/ui/packages/consul-ui/lib/startup/templates/body.html.js @@ -44,6 +44,7 @@ ${environment === 'production' ? `{{jsonEncode .}}` : JSON.stringify(config.oper + ${ environment === 'development' || environment === 'staging' ? ` diff --git a/ui/packages/consul-ui/package.json b/ui/packages/consul-ui/package.json index 4b1282596..eb4f2c92d 100644 --- a/ui/packages/consul-ui/package.json +++ b/ui/packages/consul-ui/package.json @@ -79,6 +79,7 @@ "chalk": "^4.1.0", "clipboard": "^2.0.4", "consul-acls": "*", + "consul-lock-sessions": "*", "consul-nspaces": "*", "consul-partitions": "*", "css.escape": "^1.5.1", diff --git a/ui/packages/consul-ui/translations/routes/en-us.yaml b/ui/packages/consul-ui/translations/routes/en-us.yaml index ffa2a2c94..d529b7ee2 100644 --- a/ui/packages/consul-ui/translations/routes/en-us.yaml +++ b/ui/packages/consul-ui/translations/routes/en-us.yaml @@ -2,6 +2,7 @@ dc: nodes: show: healthchecks: + title: Health Checks empty: |

This node has no health checks{items, select, @@ -15,6 +16,14 @@ dc:

This node has a failing serf node check. The health statuses shown on this page are the statuses as they were known before the node became unreachable.

+ services: + title: Service Instances + rtt: + title: Round Trip Time + sessions: + title: Lock Sessions + metadata: + title: Metadata services: show: topology: diff --git a/ui/packages/consul-ui/vendor/consul-ui/routes.js b/ui/packages/consul-ui/vendor/consul-ui/routes.js index 01cb9b67e..026f80086 100644 --- a/ui/packages/consul-ui/vendor/consul-ui/routes.js +++ b/ui/packages/consul-ui/vendor/consul-ui/routes.js @@ -240,9 +240,6 @@ rtt: { _options: { path: '/round-trip-time' }, }, - sessions: { - _options: { path: '/lock-sessions' }, - }, metadata: { _options: { path: '/metadata' }, },