2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 18:39:22 +00:00
|
|
|
|
2020-09-23 11:37:33 +00:00
|
|
|
package uiserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/config"
|
|
|
|
)
|
|
|
|
|
2020-10-09 13:32:39 +00:00
|
|
|
// uiTemplateDataFromConfig returns the base set of variables that should be
|
|
|
|
// injected into the UI's Env based on the given runtime UI config.
|
2020-09-23 11:37:33 +00:00
|
|
|
func uiTemplateDataFromConfig(cfg *config.RuntimeConfig) (map[string]interface{}, error) {
|
|
|
|
|
|
|
|
uiCfg := map[string]interface{}{
|
|
|
|
"metrics_provider": cfg.UIConfig.MetricsProvider,
|
|
|
|
// We explicitly MUST NOT pass the metrics_proxy object since it might
|
|
|
|
// contain add_headers with secrets that the UI shouldn't know e.g. API
|
|
|
|
// tokens for the backend. The provider should either require the proxy to
|
|
|
|
// be configured and then use that or hit the backend directly from the
|
|
|
|
// browser.
|
|
|
|
"metrics_proxy_enabled": cfg.UIConfig.MetricsProxy.BaseURL != "",
|
|
|
|
"dashboard_url_templates": cfg.UIConfig.DashboardURLTemplates,
|
2022-04-15 16:55:52 +00:00
|
|
|
"hcp_enabled": cfg.UIConfig.HCPEnabled,
|
2020-09-23 11:37:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Only set this if there is some actual JSON or we'll cause a JSON
|
|
|
|
// marshalling error later during serving which ends up being silent.
|
|
|
|
if cfg.UIConfig.MetricsProviderOptionsJSON != "" {
|
|
|
|
uiCfg["metrics_provider_options"] = json.RawMessage(cfg.UIConfig.MetricsProviderOptionsJSON)
|
|
|
|
}
|
|
|
|
|
2024-01-26 21:38:51 +00:00
|
|
|
v2CatalogEnabled := false
|
|
|
|
for _, experiment := range cfg.Experiments {
|
|
|
|
if experiment == "resource-apis" {
|
|
|
|
v2CatalogEnabled = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-23 11:37:33 +00:00
|
|
|
d := map[string]interface{}{
|
2021-10-26 14:30:17 +00:00
|
|
|
"ContentPath": cfg.UIConfig.ContentPath,
|
|
|
|
"ACLsEnabled": cfg.ACLsEnabled,
|
2022-05-26 16:23:56 +00:00
|
|
|
"HCPEnabled": cfg.UIConfig.HCPEnabled,
|
2021-10-26 14:30:17 +00:00
|
|
|
"UIConfig": uiCfg,
|
|
|
|
"LocalDatacenter": cfg.Datacenter,
|
|
|
|
"PrimaryDatacenter": cfg.PrimaryDatacenter,
|
2022-07-25 15:50:11 +00:00
|
|
|
"PeeringEnabled": cfg.PeeringEnabled,
|
2024-01-26 21:38:51 +00:00
|
|
|
"V2CatalogEnabled": v2CatalogEnabled,
|
2020-09-23 11:37:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 17:03:13 +00:00
|
|
|
// Also inject additional provider scripts if needed, otherwise strip the
|
|
|
|
// comment.
|
|
|
|
if len(cfg.UIConfig.MetricsProviderFiles) > 0 {
|
|
|
|
d["ExtraScripts"] = []string{
|
|
|
|
cfg.UIConfig.ContentPath + compiledProviderJSPath,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-09 13:32:39 +00:00
|
|
|
return d, nil
|
2020-09-23 11:37:33 +00:00
|
|
|
}
|