ui: Disable licensing tab if the UI is running via HCP (#12771)

Co-authored-by: Evan Rowe <ev.rowe@gmail.com>
This commit is contained in:
John Cowen 2022-06-09 18:15:52 +01:00 committed by GitHub
parent bba3eb8cdd
commit 147476c10d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 73 additions and 19 deletions

View File

@ -30,7 +30,7 @@ references:
ember: &EMBER_IMAGE docker.mirror.hashicorp.services/circleci/node:14-browsers ember: &EMBER_IMAGE docker.mirror.hashicorp.services/circleci/node:14-browsers
ubuntu: &UBUNTU_CI_IMAGE ubuntu-2004:202201-02 ubuntu: &UBUNTU_CI_IMAGE ubuntu-2004:202201-02
cache: cache:
yarn: &YARN_CACHE_KEY consul-ui-v7-{{ checksum "ui/yarn.lock" }} yarn: &YARN_CACHE_KEY consul-ui-v8-{{ checksum "ui/yarn.lock" }}
steps: steps:
install-gotestsum: &install-gotestsum install-gotestsum: &install-gotestsum

View File

@ -11,7 +11,7 @@
"scripts": { "scripts": {
"doc:toc": "doctoc README.md", "doc:toc": "doctoc README.md",
"compliance": "npm-run-all compliance:*", "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": { "devDependencies": {

View File

@ -0,0 +1,5 @@
{
"name": "consul-hcp",
"version": "0.1.0",
"private": true
}

View File

@ -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);
}
);

View File

@ -0,0 +1,7 @@
(services => services({
}))(
(json, data = (typeof document !== 'undefined' ? document.currentScript.dataset : module.exports)) => {
data[`services`] = JSON.stringify(json);
}
);

View File

@ -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');
}
}

View File

@ -0,0 +1,6 @@
import BaseAbility from './base';
export default class ServerAbility extends BaseAbility {
resource = 'operator';
segmented = false;
}

View File

@ -7,6 +7,7 @@
refresh=this.refresh refresh=this.refresh
t=this.t t=this.t
exists=this.exists
Title=(component "route/title") Title=(component "route/title")
Announcer=(component "route/announcer") Announcer=(component "route/announcer")

View File

@ -31,6 +31,12 @@ export default class RouteComponent extends Component {
} }
return undefined; return undefined;
} }
@action
exists(str) {
return this.routlet.exists(`${this.args.name}.${str}`);
}
@action @action
t(str, options) { t(str, options) {
if (str.includes('${')) { if (str.includes('${')) {

View File

@ -1,5 +1,6 @@
import Service, { inject as service } from '@ember/service'; import Service, { inject as service } from '@ember/service';
import { schedule } from '@ember/runloop'; import { schedule } from '@ember/runloop';
import { get } from '@ember/object';
import wildcard from 'consul-ui/utils/routing/wildcard'; import wildcard from 'consul-ui/utils/routing/wildcard';
import { routes } from 'consul-ui/router'; import { routes } from 'consul-ui/router';
@ -57,10 +58,29 @@ export default class RoutletService extends Service {
@service('env') env; @service('env') env;
@service('router') router; @service('router') router;
@service('repository/permission') permissions;
ready() { ready() {
return this._transition; 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() { transition() {
let endTransition; let endTransition;
this._transition = new Promise(resolve => { this._transition = new Promise(resolve => {

View File

@ -13,9 +13,9 @@ as |route|>
{{#let {{#let
(from-entries (array (from-entries (array
(array 'serverstatus' true) (array 'serverstatus' (compute (fn route.exists 'serverstatus')))
(array 'cataloghealth' false) (array 'cataloghealth' false)
(array 'license' (can 'read license')) (array 'license' (compute (fn route.exists 'license')))
)) ))
as |tabs|}} as |tabs|}}

View File

@ -6,6 +6,9 @@ export const walk = function(routes) {
if (item === '_options') { if (item === '_options') {
return; return;
} }
if(routes[item] === null) {
return;
}
const options = routes[item]._options; const options = routes[item]._options;
let cb; let cb;
if (Object.keys(routes[item]).length > 1) { if (Object.keys(routes[item]).length > 1) {

View File

@ -31,7 +31,8 @@ module.exports = function(defaults, $ = process.env) {
'consul-acls', 'consul-acls',
'consul-lock-sessions', 'consul-lock-sessions',
'consul-partitions', 'consul-partitions',
'consul-nspaces' 'consul-nspaces',
'consul-hcp'
].map(item => { ].map(item => {
return { return {
name: item, name: item,

View File

@ -66,6 +66,9 @@ ${
{{if .NamespacesEnabled}} {{if .NamespacesEnabled}}
<script src="${rootURL}assets/consul-nspaces/routes.js"></script> <script src="${rootURL}assets/consul-nspaces/routes.js"></script>
{{end}} {{end}}
{{if .HCPEnabled}}
<script src="${rootURL}assets/consul-hcp/routes.js"></script>
{{end}}
` `
: ` : `
<script> <script>
@ -85,7 +88,8 @@ ${
{ {
'CONSUL_ACLS_ENABLE': 'consul-acls', 'CONSUL_ACLS_ENABLE': 'consul-acls',
'CONSUL_PARTITIONS_ENABLE': 'consul-partitions', 'CONSUL_PARTITIONS_ENABLE': 'consul-partitions',
'CONSUL_NSPACES_ENABLE': 'consul-nspaces' 'CONSUL_NSPACES_ENABLE': 'consul-nspaces',
'CONSUL_HCP_ENABLE': 'consul-hcp'
} }
); );
</script> </script>

View File

@ -79,6 +79,7 @@
"chalk": "^4.1.0", "chalk": "^4.1.0",
"clipboard": "^2.0.4", "clipboard": "^2.0.4",
"consul-acls": "*", "consul-acls": "*",
"consul-hcp": "*",
"consul-lock-sessions": "*", "consul-lock-sessions": "*",
"consul-nspaces": "*", "consul-nspaces": "*",
"consul-partitions": "*", "consul-partitions": "*",

View File

@ -18,7 +18,7 @@
serverstatus: { serverstatus: {
_options: { _options: {
path: '/server-status', path: '/server-status',
abilities: ['access overview', 'read zones'], abilities: ['read servers']
}, },
}, },
cataloghealth: { cataloghealth: {
@ -30,7 +30,7 @@
license: { license: {
_options: { _options: {
path: '/license', path: '/license',
abilities: ['access overview', 'read licence'], abilities: ['read license']
}, },
}, },
}, },