2021-11-24 16:20:02 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
// UIConfig contains the operator configuration of the web UI
|
|
|
|
// Note:
|
|
|
|
// before extending this configuration, consider reviewing NMD-125
|
|
|
|
type UIConfig struct {
|
|
|
|
|
|
|
|
// Enabled is used to enable the web UI
|
|
|
|
Enabled bool `hcl:"enabled"`
|
|
|
|
|
|
|
|
// Consul configures deep links for Consul UI
|
|
|
|
Consul *ConsulUIConfig `hcl:"consul"`
|
|
|
|
|
|
|
|
// Vault configures deep links for Vault UI
|
|
|
|
Vault *VaultUIConfig `hcl:"vault"`
|
2023-02-02 21:29:04 +00:00
|
|
|
|
|
|
|
// Label configures UI label styles
|
|
|
|
Label *LabelUIConfig `hcl:"label"`
|
2021-11-24 16:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 18:20:29 +00:00
|
|
|
// ConsulUIConfig configures deep links to this cluster's Consul
|
2021-11-24 16:20:02 +00:00
|
|
|
type ConsulUIConfig struct {
|
|
|
|
|
2021-11-30 18:20:29 +00:00
|
|
|
// BaseUIURL provides the full base URL to the UI, ex:
|
2021-11-24 16:20:02 +00:00
|
|
|
// https://consul.example.com:8500/ui/
|
2021-11-30 18:20:29 +00:00
|
|
|
BaseUIURL string `hcl:"ui_url"`
|
2021-11-24 16:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 18:20:29 +00:00
|
|
|
// VaultUIConfig configures deep links to this cluster's Vault
|
2021-11-24 16:20:02 +00:00
|
|
|
type VaultUIConfig struct {
|
2021-11-30 18:20:29 +00:00
|
|
|
// BaseUIURL provides the full base URL to the UI, ex:
|
2021-11-24 16:20:02 +00:00
|
|
|
// https://vault.example.com:8200/ui/
|
2021-11-30 18:20:29 +00:00
|
|
|
BaseUIURL string `hcl:"ui_url"`
|
2021-11-24 16:20:02 +00:00
|
|
|
}
|
|
|
|
|
2023-02-02 21:29:04 +00:00
|
|
|
// Label configures UI label styles
|
|
|
|
type LabelUIConfig struct {
|
|
|
|
Text string `hcl:"text"`
|
|
|
|
BackgroundColor string `hcl:"background_color"`
|
|
|
|
TextColor string `hcl:"text_color"`
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:20:02 +00:00
|
|
|
// DefaultUIConfig returns the canonical defaults for the Nomad
|
|
|
|
// `ui` configuration.
|
|
|
|
func DefaultUIConfig() *UIConfig {
|
|
|
|
return &UIConfig{
|
|
|
|
Enabled: true,
|
|
|
|
Consul: &ConsulUIConfig{},
|
|
|
|
Vault: &VaultUIConfig{},
|
2023-02-02 21:29:04 +00:00
|
|
|
Label: &LabelUIConfig{},
|
2021-11-24 16:20:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy returns a copy of this UI config.
|
|
|
|
func (old *UIConfig) Copy() *UIConfig {
|
|
|
|
if old == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
nc := new(UIConfig)
|
|
|
|
*nc = *old
|
|
|
|
|
|
|
|
if old.Consul != nil {
|
|
|
|
nc.Consul = old.Consul.Copy()
|
|
|
|
}
|
|
|
|
if old.Vault != nil {
|
|
|
|
nc.Vault = old.Vault.Copy()
|
|
|
|
}
|
|
|
|
return nc
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge returns a new UI configuration by merging another UI
|
|
|
|
// configuration into this one
|
2021-12-20 10:44:21 +00:00
|
|
|
func (old *UIConfig) Merge(other *UIConfig) *UIConfig {
|
|
|
|
result := old.Copy()
|
2021-11-24 16:20:02 +00:00
|
|
|
if other == nil {
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
result.Enabled = other.Enabled
|
|
|
|
result.Consul = result.Consul.Merge(other.Consul)
|
|
|
|
result.Vault = result.Vault.Merge(other.Vault)
|
2023-02-02 21:29:04 +00:00
|
|
|
result.Label = result.Label.Merge(other.Label)
|
2021-11-24 16:20:02 +00:00
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy returns a copy of this Consul UI config.
|
|
|
|
func (old *ConsulUIConfig) Copy() *ConsulUIConfig {
|
|
|
|
if old == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
nc := new(ConsulUIConfig)
|
|
|
|
*nc = *old
|
|
|
|
return nc
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge returns a new Consul UI configuration by merging another Consul UI
|
|
|
|
// configuration into this one
|
2021-12-20 10:44:21 +00:00
|
|
|
func (old *ConsulUIConfig) Merge(other *ConsulUIConfig) *ConsulUIConfig {
|
|
|
|
result := old.Copy()
|
2021-11-24 16:20:02 +00:00
|
|
|
if result == nil {
|
|
|
|
result = &ConsulUIConfig{}
|
|
|
|
}
|
|
|
|
if other == nil {
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-11-30 18:20:29 +00:00
|
|
|
if other.BaseUIURL != "" {
|
|
|
|
result.BaseUIURL = other.BaseUIURL
|
2021-11-24 16:20:02 +00:00
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy returns a copy of this Vault UI config.
|
|
|
|
func (old *VaultUIConfig) Copy() *VaultUIConfig {
|
|
|
|
if old == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
nc := new(VaultUIConfig)
|
|
|
|
*nc = *old
|
|
|
|
return nc
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge returns a new Vault UI configuration by merging another Vault UI
|
|
|
|
// configuration into this one
|
2021-12-20 10:44:21 +00:00
|
|
|
func (old *VaultUIConfig) Merge(other *VaultUIConfig) *VaultUIConfig {
|
|
|
|
result := old.Copy()
|
2021-11-24 16:20:02 +00:00
|
|
|
if result == nil {
|
|
|
|
result = &VaultUIConfig{}
|
|
|
|
}
|
|
|
|
if other == nil {
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-11-30 18:20:29 +00:00
|
|
|
if other.BaseUIURL != "" {
|
|
|
|
result.BaseUIURL = other.BaseUIURL
|
2021-11-24 16:20:02 +00:00
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
2023-02-02 21:29:04 +00:00
|
|
|
|
|
|
|
// Copy returns a copy of this Label UI config.
|
|
|
|
func (old *LabelUIConfig) Copy() *LabelUIConfig {
|
|
|
|
if old == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
nc := new(LabelUIConfig)
|
|
|
|
*nc = *old
|
|
|
|
return nc
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge returns a new Label UI configuration by merging another Label UI
|
|
|
|
// configuration into this one
|
|
|
|
func (old *LabelUIConfig) Merge(other *LabelUIConfig) *LabelUIConfig {
|
|
|
|
result := old.Copy()
|
|
|
|
if result == nil {
|
|
|
|
result = &LabelUIConfig{}
|
|
|
|
}
|
|
|
|
if other == nil {
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
if other.Text != "" {
|
|
|
|
result.Text = other.Text
|
|
|
|
}
|
|
|
|
if other.BackgroundColor != "" {
|
|
|
|
result.BackgroundColor = other.BackgroundColor
|
|
|
|
}
|
|
|
|
if other.TextColor != "" {
|
|
|
|
result.TextColor = other.TextColor
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|