github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/structs/config/ui.go (about)

     1  package config
     2  
     3  // UIConfig contains the operator configuration of the web UI
     4  // Note:
     5  // before extending this configuration, consider reviewing NMD-125
     6  type UIConfig struct {
     7  
     8  	// Enabled is used to enable the web UI
     9  	Enabled bool `hcl:"enabled"`
    10  
    11  	// Consul configures deep links for Consul UI
    12  	Consul *ConsulUIConfig `hcl:"consul"`
    13  
    14  	// Vault configures deep links for Vault UI
    15  	Vault *VaultUIConfig `hcl:"vault"`
    16  }
    17  
    18  // ConsulUIConfig configures deep links to this cluster's Consul
    19  type ConsulUIConfig struct {
    20  
    21  	// BaseUIURL provides the full base URL to the UI, ex:
    22  	// https://consul.example.com:8500/ui/
    23  	BaseUIURL string `hcl:"ui_url"`
    24  }
    25  
    26  // VaultUIConfig configures deep links to this cluster's Vault
    27  type VaultUIConfig struct {
    28  	// BaseUIURL provides the full base URL to the UI, ex:
    29  	// https://vault.example.com:8200/ui/
    30  	BaseUIURL string `hcl:"ui_url"`
    31  }
    32  
    33  // DefaultUIConfig returns the canonical defaults for the Nomad
    34  // `ui` configuration.
    35  func DefaultUIConfig() *UIConfig {
    36  	return &UIConfig{
    37  		Enabled: true,
    38  		Consul:  &ConsulUIConfig{},
    39  		Vault:   &VaultUIConfig{},
    40  	}
    41  }
    42  
    43  // Copy returns a copy of this UI config.
    44  func (old *UIConfig) Copy() *UIConfig {
    45  	if old == nil {
    46  		return nil
    47  	}
    48  
    49  	nc := new(UIConfig)
    50  	*nc = *old
    51  
    52  	if old.Consul != nil {
    53  		nc.Consul = old.Consul.Copy()
    54  	}
    55  	if old.Vault != nil {
    56  		nc.Vault = old.Vault.Copy()
    57  	}
    58  	return nc
    59  }
    60  
    61  // Merge returns a new UI configuration by merging another UI
    62  // configuration into this one
    63  func (old *UIConfig) Merge(other *UIConfig) *UIConfig {
    64  	result := old.Copy()
    65  	if other == nil {
    66  		return result
    67  	}
    68  
    69  	result.Enabled = other.Enabled
    70  	result.Consul = result.Consul.Merge(other.Consul)
    71  	result.Vault = result.Vault.Merge(other.Vault)
    72  
    73  	return result
    74  }
    75  
    76  // Copy returns a copy of this Consul UI config.
    77  func (old *ConsulUIConfig) Copy() *ConsulUIConfig {
    78  	if old == nil {
    79  		return nil
    80  	}
    81  
    82  	nc := new(ConsulUIConfig)
    83  	*nc = *old
    84  	return nc
    85  }
    86  
    87  // Merge returns a new Consul UI configuration by merging another Consul UI
    88  // configuration into this one
    89  func (old *ConsulUIConfig) Merge(other *ConsulUIConfig) *ConsulUIConfig {
    90  	result := old.Copy()
    91  	if result == nil {
    92  		result = &ConsulUIConfig{}
    93  	}
    94  	if other == nil {
    95  		return result
    96  	}
    97  
    98  	if other.BaseUIURL != "" {
    99  		result.BaseUIURL = other.BaseUIURL
   100  	}
   101  	return result
   102  }
   103  
   104  // Copy returns a copy of this Vault UI config.
   105  func (old *VaultUIConfig) Copy() *VaultUIConfig {
   106  	if old == nil {
   107  		return nil
   108  	}
   109  
   110  	nc := new(VaultUIConfig)
   111  	*nc = *old
   112  	return nc
   113  }
   114  
   115  // Merge returns a new Vault UI configuration by merging another Vault UI
   116  // configuration into this one
   117  func (old *VaultUIConfig) Merge(other *VaultUIConfig) *VaultUIConfig {
   118  	result := old.Copy()
   119  	if result == nil {
   120  		result = &VaultUIConfig{}
   121  	}
   122  	if other == nil {
   123  		return result
   124  	}
   125  
   126  	if other.BaseUIURL != "" {
   127  		result.BaseUIURL = other.BaseUIURL
   128  	}
   129  	return result
   130  }