ui: Pass primary dc through to uiserver (#11317)

Co-authored-by: John Cowen <johncowen@users.noreply.github.com>
This commit is contained in:
Chris S. Kim 2021-10-26 10:30:17 -04:00 committed by GitHub
parent f24bad2a52
commit 3f736467e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 8 deletions

View File

@ -32,6 +32,7 @@ func uiTemplateDataFromConfig(cfg *config.RuntimeConfig) (map[string]interface{}
"ACLsEnabled": cfg.ACLsEnabled,
"UIConfig": uiCfg,
"LocalDatacenter": cfg.Datacenter,
"PrimaryDatacenter": cfg.PrimaryDatacenter,
}
// Also inject additional provider scripts if needed, otherwise strip the

View File

@ -40,6 +40,7 @@ func TestUIServerIndex(t *testing.T) {
wantUICfgJSON: `{
"ACLsEnabled": false,
"LocalDatacenter": "dc1",
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"UIConfig": {
"metrics_provider": "",
@ -72,6 +73,7 @@ func TestUIServerIndex(t *testing.T) {
wantUICfgJSON: `{
"ACLsEnabled": false,
"LocalDatacenter": "dc1",
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"UIConfig": {
"metrics_provider": "foo",
@ -92,6 +94,7 @@ func TestUIServerIndex(t *testing.T) {
wantUICfgJSON: `{
"ACLsEnabled": true,
"LocalDatacenter": "dc1",
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"UIConfig": {
"metrics_provider": "",
@ -120,6 +123,7 @@ func TestUIServerIndex(t *testing.T) {
"ACLsEnabled": false,
"SSOEnabled": true,
"LocalDatacenter": "dc1",
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"UIConfig": {
"metrics_provider": "bar",
@ -217,6 +221,7 @@ func basicUIEnabledConfig(opts ...cfgFunc) *config.RuntimeConfig {
ContentPath: "/ui/",
},
Datacenter: "dc1",
PrimaryDatacenter: "dc1",
}
for _, f := range opts {
f(cfg)
@ -380,6 +385,7 @@ func TestHandler_ServeHTTP_TransformIsEvaluatedOnEachRequest(t *testing.T) {
expected := `{
"ACLsEnabled": false,
"LocalDatacenter": "dc1",
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"UIConfig": {
"metrics_provider": "",
@ -402,6 +408,7 @@ func TestHandler_ServeHTTP_TransformIsEvaluatedOnEachRequest(t *testing.T) {
expected := `{
"ACLsEnabled": false,
"LocalDatacenter": "dc1",
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"UIConfig": {
"metrics_provider": "",

View File

@ -68,9 +68,12 @@ export default function(config = {}, win = window, doc = document) {
return {};
}
};
const operatorConfig = JSON.parse(
const operatorConfig = {
...config.operatorConfig,
...JSON.parse(
doc.querySelector(`[data-${config.modulePrefix}-config]`).textContent
);
)
};
const ui_config = operatorConfig.UIConfig || {};
const scripts = doc.getElementsByTagName('script');
// we use the currently executing script as a reference
@ -101,6 +104,8 @@ export default function(config = {}, win = window, doc = document) {
: operatorConfig.PartitionsEnabled;
case 'CONSUL_DATACENTER_LOCAL':
return operatorConfig.LocalDatacenter;
case 'CONSUL_DATACENTER_PRIMARY':
return operatorConfig.PrimaryDatacenter;
case 'CONSUL_UI_CONFIG':
dashboards = {};
provider = env('CONSUL_METRICS_PROVIDER');
@ -209,6 +214,7 @@ export default function(config = {}, win = window, doc = document) {
return user(str) || ui(str);
case 'CONSUL_UI_CONFIG':
case 'CONSUL_DATACENTER_LOCAL':
case 'CONSUL_DATACENTER_PRIMARY':
case 'CONSUL_ACLS_ENABLED':
case 'CONSUL_NSPACES_ENABLED':
case 'CONSUL_SSO_ENABLED':

View File

@ -84,6 +84,7 @@ module.exports = function(environment, $ = process.env) {
SSOEnabled: false,
PartitionsEnabled: false,
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
},
// Static variables used in multiple places throughout the UI
@ -106,6 +107,7 @@ module.exports = function(environment, $ = process.env) {
SSOEnabled: env('CONSUL_SSO_ENABLED', false),
PartitionsEnabled: env('CONSUL_PARTITIONS_ENABLED', false),
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
},
'@hashicorp/ember-cli-api-double': {
@ -154,6 +156,7 @@ module.exports = function(environment, $ = process.env) {
SSOEnabled: env('CONSUL_SSO_ENABLED', true),
PartitionsEnabled: env('CONSUL_PARTITIONS_ENABLED', true),
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
},
'@hashicorp/ember-cli-api-double': {

View File

@ -22,6 +22,7 @@ test(
SSOEnabled: false,
PartitionsEnabled: false,
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
}
},
{
@ -36,6 +37,7 @@ test(
SSOEnabled: false,
PartitionsEnabled: false,
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
}
},
{
@ -50,6 +52,7 @@ test(
SSOEnabled: true,
PartitionsEnabled: false,
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
}
},
{
@ -61,6 +64,7 @@ test(
SSOEnabled: true,
PartitionsEnabled: true,
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
}
}
].forEach(