diff --git a/.circleci/config.yml b/.circleci/config.yml index 0286ec367..7edc711e5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -30,7 +30,7 @@ references: ember: &EMBER_IMAGE docker.mirror.hashicorp.services/circleci/node:14-browsers ubuntu: &UBUNTU_CI_IMAGE ubuntu-2004:202201-02 cache: - yarn: &YARN_CACHE_KEY consul-ui-v7-{{ checksum "ui/yarn.lock" }} + yarn: &YARN_CACHE_KEY consul-ui-v8-{{ checksum "ui/yarn.lock" }} steps: install-gotestsum: &install-gotestsum diff --git a/ui/package.json b/ui/package.json index a474ecf73..edfb47355 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-lock-sessions@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;consul-hcp@0.1.0'" }, "devDependencies": { diff --git a/ui/packages/consul-hcp/package.json b/ui/packages/consul-hcp/package.json new file mode 100644 index 000000000..bb35cc6f6 --- /dev/null +++ b/ui/packages/consul-hcp/package.json @@ -0,0 +1,5 @@ +{ + "name": "consul-hcp", + "version": "0.1.0", + "private": true +} diff --git a/ui/packages/consul-hcp/vendor/consul-hcp/routes.js b/ui/packages/consul-hcp/vendor/consul-hcp/routes.js new file mode 100644 index 000000000..1b58d87ef --- /dev/null +++ b/ui/packages/consul-hcp/vendor/consul-hcp/routes.js @@ -0,0 +1,11 @@ +(routes => routes({ + dc: { + show: { + license: null, + }, + }, +}))( + (json, data = (typeof document !== 'undefined' ? document.currentScript.dataset : module.exports)) => { + data[`routes`] = JSON.stringify(json); + } +); diff --git a/ui/packages/consul-hcp/vendor/consul-hcp/services.js b/ui/packages/consul-hcp/vendor/consul-hcp/services.js new file mode 100644 index 000000000..159a7a96e --- /dev/null +++ b/ui/packages/consul-hcp/vendor/consul-hcp/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/app/abilities/hcp.js b/ui/packages/consul-ui/app/abilities/hcp.js deleted file mode 100644 index 80f364cad..000000000 --- a/ui/packages/consul-ui/app/abilities/hcp.js +++ /dev/null @@ -1,11 +0,0 @@ -import BaseAbility from './base'; -import { inject as service } from '@ember/service'; - -export default class HcpAbility extends BaseAbility { - @service('env') env; - - get is() { - return false; - // return this.env.var('CONSUL_HCP'); - } -} diff --git a/ui/packages/consul-ui/app/abilities/server.js b/ui/packages/consul-ui/app/abilities/server.js new file mode 100644 index 000000000..8952fe65f --- /dev/null +++ b/ui/packages/consul-ui/app/abilities/server.js @@ -0,0 +1,6 @@ +import BaseAbility from './base'; + +export default class ServerAbility extends BaseAbility { + resource = 'operator'; + segmented = false; +} diff --git a/ui/packages/consul-ui/app/components/route/index.hbs b/ui/packages/consul-ui/app/components/route/index.hbs index 7af35e58f..4e8f485e7 100644 --- a/ui/packages/consul-ui/app/components/route/index.hbs +++ b/ui/packages/consul-ui/app/components/route/index.hbs @@ -7,6 +7,7 @@ refresh=this.refresh t=this.t + exists=this.exists Title=(component "route/title") Announcer=(component "route/announcer") diff --git a/ui/packages/consul-ui/app/components/route/index.js b/ui/packages/consul-ui/app/components/route/index.js index 999ae7fd6..32065ca47 100644 --- a/ui/packages/consul-ui/app/components/route/index.js +++ b/ui/packages/consul-ui/app/components/route/index.js @@ -31,6 +31,12 @@ export default class RouteComponent extends Component { } return undefined; } + + @action + exists(str) { + return this.routlet.exists(`${this.args.name}.${str}`); + } + @action t(str, options) { if (str.includes('${')) { diff --git a/ui/packages/consul-ui/app/services/routlet.js b/ui/packages/consul-ui/app/services/routlet.js index 4ff011158..2fb805b54 100644 --- a/ui/packages/consul-ui/app/services/routlet.js +++ b/ui/packages/consul-ui/app/services/routlet.js @@ -1,5 +1,6 @@ import Service, { inject as service } from '@ember/service'; import { schedule } from '@ember/runloop'; +import { get } from '@ember/object'; import wildcard from 'consul-ui/utils/routing/wildcard'; import { routes } from 'consul-ui/router'; @@ -57,10 +58,29 @@ export default class RoutletService extends Service { @service('env') env; @service('router') router; + @service('repository/permission') permissions; + ready() { return this._transition; } + exists(routeName) { + if(get(routes, routeName)) { + return this.allowed(routeName); + } + return false; + } + + allowed(routeName) { + const abilities = get(routes, `${routeName}._options.abilities`) || []; + if (abilities.length > 0) { + if (!abilities.every(ability => this.permissions.can(ability))) { + return false; + } + } + return true; + } + transition() { let endTransition; this._transition = new Promise(resolve => { diff --git a/ui/packages/consul-ui/app/templates/dc/show.hbs b/ui/packages/consul-ui/app/templates/dc/show.hbs index 1391997da..497c2a100 100644 --- a/ui/packages/consul-ui/app/templates/dc/show.hbs +++ b/ui/packages/consul-ui/app/templates/dc/show.hbs @@ -13,9 +13,9 @@ as |route|> {{#let (from-entries (array - (array 'serverstatus' true) + (array 'serverstatus' (compute (fn route.exists 'serverstatus'))) (array 'cataloghealth' false) - (array 'license' (can 'read license')) + (array 'license' (compute (fn route.exists 'license'))) )) as |tabs|}} diff --git a/ui/packages/consul-ui/app/utils/routing/walk.js b/ui/packages/consul-ui/app/utils/routing/walk.js index 0eef8a71c..388f4ce21 100644 --- a/ui/packages/consul-ui/app/utils/routing/walk.js +++ b/ui/packages/consul-ui/app/utils/routing/walk.js @@ -6,6 +6,9 @@ export const walk = function(routes) { if (item === '_options') { return; } + if(routes[item] === null) { + return; + } const options = routes[item]._options; let cb; if (Object.keys(routes[item]).length > 1) { diff --git a/ui/packages/consul-ui/ember-cli-build.js b/ui/packages/consul-ui/ember-cli-build.js index 65c72fe9b..8f2a92e15 100644 --- a/ui/packages/consul-ui/ember-cli-build.js +++ b/ui/packages/consul-ui/ember-cli-build.js @@ -31,7 +31,8 @@ module.exports = function(defaults, $ = process.env) { 'consul-acls', 'consul-lock-sessions', 'consul-partitions', - 'consul-nspaces' + 'consul-nspaces', + 'consul-hcp' ].map(item => { return { name: 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 6956c24b9..0722a60d6 100644 --- a/ui/packages/consul-ui/lib/startup/templates/body.html.js +++ b/ui/packages/consul-ui/lib/startup/templates/body.html.js @@ -66,6 +66,9 @@ ${ {{if .NamespacesEnabled}} {{end}} +{{if .HCPEnabled}} + +{{end}} ` : ` diff --git a/ui/packages/consul-ui/package.json b/ui/packages/consul-ui/package.json index 515398314..e40b6fe28 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-hcp": "*", "consul-lock-sessions": "*", "consul-nspaces": "*", "consul-partitions": "*", diff --git a/ui/packages/consul-ui/vendor/consul-ui/routes.js b/ui/packages/consul-ui/vendor/consul-ui/routes.js index b5bec8a60..9191b8726 100644 --- a/ui/packages/consul-ui/vendor/consul-ui/routes.js +++ b/ui/packages/consul-ui/vendor/consul-ui/routes.js @@ -18,7 +18,7 @@ serverstatus: { _options: { path: '/server-status', - abilities: ['access overview', 'read zones'], + abilities: ['read servers'] }, }, cataloghealth: { @@ -30,7 +30,7 @@ license: { _options: { path: '/license', - abilities: ['access overview', 'read licence'], + abilities: ['read license'] }, }, },