diff --git a/agent/uiserver/ui_template_data.go b/agent/uiserver/ui_template_data.go index 008377b4d..bb722f798 100644 --- a/agent/uiserver/ui_template_data.go +++ b/agent/uiserver/ui_template_data.go @@ -28,10 +28,11 @@ func uiTemplateDataFromConfig(cfg *config.RuntimeConfig) (map[string]interface{} } d := map[string]interface{}{ - "ContentPath": cfg.UIConfig.ContentPath, - "ACLsEnabled": cfg.ACLsEnabled, - "UIConfig": uiCfg, - "LocalDatacenter": cfg.Datacenter, + "ContentPath": cfg.UIConfig.ContentPath, + "ACLsEnabled": cfg.ACLsEnabled, + "UIConfig": uiCfg, + "LocalDatacenter": cfg.Datacenter, + "PrimaryDatacenter": cfg.PrimaryDatacenter, } // Also inject additional provider scripts if needed, otherwise strip the diff --git a/agent/uiserver/uiserver_test.go b/agent/uiserver/uiserver_test.go index ff4000981..f72514bac 100644 --- a/agent/uiserver/uiserver_test.go +++ b/agent/uiserver/uiserver_test.go @@ -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", @@ -216,7 +220,8 @@ func basicUIEnabledConfig(opts ...cfgFunc) *config.RuntimeConfig { Enabled: true, ContentPath: "/ui/", }, - Datacenter: "dc1", + 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": "", diff --git a/ui/packages/consul-ui/app/utils/get-environment.js b/ui/packages/consul-ui/app/utils/get-environment.js index e21a5cfb9..3967395b1 100644 --- a/ui/packages/consul-ui/app/utils/get-environment.js +++ b/ui/packages/consul-ui/app/utils/get-environment.js @@ -68,9 +68,12 @@ export default function(config = {}, win = window, doc = document) { return {}; } }; - const operatorConfig = JSON.parse( - doc.querySelector(`[data-${config.modulePrefix}-config]`).textContent - ); + 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': diff --git a/ui/packages/consul-ui/config/environment.js b/ui/packages/consul-ui/config/environment.js index 73b7041c5..530fbe7a1 100644 --- a/ui/packages/consul-ui/config/environment.js +++ b/ui/packages/consul-ui/config/environment.js @@ -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': { diff --git a/ui/packages/consul-ui/node-tests/config/environment.js b/ui/packages/consul-ui/node-tests/config/environment.js index c956847e4..0a88fa02a 100644 --- a/ui/packages/consul-ui/node-tests/config/environment.js +++ b/ui/packages/consul-ui/node-tests/config/environment.js @@ -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(