ui: use environment variable for feature flagging peers (#13703)

* ui: use environment variable for feature flagging peers

* Add documentation for `features`-service

* Allow setting feature flag for peers via bookmarklet

* don't use features service for flagging peers

* add ability for checking if peers feature is enabled

* Use abilities to conditionally use peers feature

* Remove unused features service
This commit is contained in:
Michael Klein 2022-07-12 13:02:45 +02:00 committed by GitHub
parent dadc18c294
commit 123047d5b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 28 additions and 43 deletions

View File

@ -1,6 +1,9 @@
import BaseAbility from 'consul-ui/abilities/base';
import { inject as service } from '@ember/service';
export default class PeerAbility extends BaseAbility {
@service('env') env;
resource = 'operator';
segmented = false;
@ -9,11 +12,10 @@ export default class PeerAbility extends BaseAbility {
}
get canDelete() {
// TODO: Need to confirm these states
return ![
'DELETING',
'TERMINATED',
'UNDEFINED'
].includes(this.item.State);
return !['DELETING', 'TERMINATED', 'UNDEFINED'].includes(this.item.State);
}
get canUse() {
return this.env.var('CONSUL_PEERING_ENABLED');
}
}

View File

@ -11,12 +11,12 @@ import { inject as service } from '@ember/service';
// to the node.
export default class NodeAdapter extends Adapter {
@service features;
@service abilities;
get peeringQuery() {
const query = {};
if (this.features.isEnabled('peering')) {
if (this.abilities.can('use peers')) {
query['with-peers'] = true;
}

View File

@ -2,12 +2,12 @@ import Adapter from './application';
import { inject as service } from '@ember/service';
export default class ServiceAdapter extends Adapter {
@service features;
@service abilities;
get peeringQuery() {
const query = {};
if (this.features.isEnabled('peering')) {
if (this.abilities.can('use peers')) {
query['with-peers'] = true;
}

View File

@ -146,7 +146,7 @@
@partition={{@partition}}
@nspace={{@nspace}}
/>
{{#if (feature-flag "peering")}}
{{#if (can "use peers")}}
<li role="separator">
Organization
</li>

View File

@ -1,10 +0,0 @@
import Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';
export default class extends Helper {
@service features;
compute([feature]) {
return this.features.isEnabled(feature);
}
}

View File

@ -2,10 +2,10 @@ import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
export default class PeersRoute extends Route {
@service features;
@service abilities;
beforeModel() {
if (!this.features.isEnabled('peering')) {
if (!this.abilities.can('use peers')) {
this.transitionTo('dc.services.index');
}
}

View File

@ -1,13 +0,0 @@
import Service, { inject as service } from '@ember/service';
export default class FeatureService extends Service {
@service env;
get features() {
return this.env.var('features');
}
isEnabled(featureName) {
return !!this.features?.[featureName];
}
}

View File

@ -124,13 +124,17 @@ export default function(config = {}, win = window, doc = document) {
return typeof operatorConfig.PartitionsEnabled === 'undefined'
? false
: operatorConfig.PartitionsEnabled;
case 'CONSUL_PEERING_ENABLED':
return typeof operatorConfig.PeeringEnabled === 'undefined'
? false
: operatorConfig.PeeringEnabled;
case 'CONSUL_DATACENTER_LOCAL':
return operatorConfig.LocalDatacenter;
case 'CONSUL_DATACENTER_PRIMARY':
return operatorConfig.PrimaryDatacenter;
case 'CONSUL_UI_CONFIG':
dashboards = {
service: undefined
service: undefined,
};
provider = env('CONSUL_METRICS_PROVIDER');
proxy = env('CONSUL_METRICS_PROXY_ENABLED');
@ -209,6 +213,9 @@ export default function(config = {}, win = window, doc = document) {
case 'CONSUL_METRICS_PROXY_ENABLE':
prev['CONSUL_METRICS_PROXY_ENABLED'] = !!JSON.parse(String(value).toLowerCase());
break;
case 'CONSUL_PEERING_ENABLE':
prev['CONSUL_PEERING_ENABLED'] = !!JSON.parse(String(value).toLowerCase());
break;
case 'CONSUL_UI_CONFIG':
prev['CONSUL_UI_CONFIG'] = JSON.parse(value);
break;
@ -241,6 +248,7 @@ export default function(config = {}, win = window, doc = document) {
case 'CONSUL_DATACENTER_PRIMARY':
case 'CONSUL_ACLS_ENABLED':
case 'CONSUL_NSPACES_ENABLED':
case 'CONSUL_PEERING_ENABLED':
case 'CONSUL_SSO_ENABLED':
case 'CONSUL_PARTITIONS_ENABLED':
case 'CONSUL_METRICS_PROVIDER':

View File

@ -82,6 +82,7 @@ module.exports = function(environment, $ = process.env) {
ACLsEnabled: false,
NamespacesEnabled: false,
SSOEnabled: false,
PeeringEnabled: env('CONSUL_PEERING_ENABLED', false),
PartitionsEnabled: false,
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
@ -105,15 +106,13 @@ module.exports = function(environment, $ = process.env) {
ACLsEnabled: env('CONSUL_ACLS_ENABLED', true),
NamespacesEnabled: env('CONSUL_NSPACES_ENABLED', false),
SSOEnabled: env('CONSUL_SSO_ENABLED', false),
// in testing peering feature is on by default
PeeringEnabled: env('CONSUL_PEERING_ENABLED', true),
PartitionsEnabled: env('CONSUL_PARTITIONS_ENABLED', false),
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
},
features: {
peering: true,
},
'@hashicorp/ember-cli-api-double': {
'auto-import': false,
enabled: true,
@ -134,15 +133,13 @@ module.exports = function(environment, $ = process.env) {
autoboot: false,
}),
});
break;
case environment === 'development':
ENV = Object.assign({}, ENV, {
torii: {
disableRedirectInitializer: true,
},
features: {
peering: true,
},
});
break;
case environment === 'staging':

View File

@ -12,6 +12,7 @@ Below is a list of the most commonly used functions as bookmarklets followed by
| [Enable ACLs](javascript:Scenario('CONSUL_ACLS_ENABLE=1')) | Enable ACLs |
| [Enable TProxy](javascript:Scenario('CONSUL_TPROXY_ENABLE=1')) | Enable TProxy |
| [Enable Nspaces](javascript:Scenario('CONSUL_NSPACES_ENABLE=1')) | Enable Namespace Support |
| [Enable Peers](javascript:Scenario('CONSUL_PEERING_ENABLE=1')) | Enable Peers Support |
| [Enable Partitions](javascript:Scenario('CONSUL_PARTITIONS_ENABLE=1')) | Enable Admin Partition Support |
| [Enable SSO](javascript:Scenario('CONSUL_SSO_ENABLE=1')) | Enable SSO Support |
| [Enable Metrics](javascript:Scenario('CONSUL_METRICS_PROXY_ENABLE=1;CONSUL_METRICS_PROVIDER=prometheus')) | Enable all configuration required for viewing the full Metrics Visualization |