Add config option to enable (m)TLS between Poseidon and Nomad

This commit is contained in:
Jan-Eric Hellenberg
2021-07-27 13:45:46 +02:00
committed by Jan-Eric Hellenberg
parent e2d71a11ad
commit 6a60b6cd89
14 changed files with 134 additions and 98 deletions

View File

@ -19,19 +19,26 @@ import (
var (
Config = &configuration{
Server: server{
Address: "127.0.0.1",
Port: 7200,
Token: "",
TLS: false,
CertFile: "",
KeyFile: "",
Address: "127.0.0.1",
Port: 7200,
Token: "",
TLS: TLS{
Active: false,
CertFile: "",
KeyFile: "",
},
InteractiveStderr: true,
},
Nomad: nomad{
Address: "127.0.0.1",
Port: 4646,
Token: "",
TLS: false,
Nomad: Nomad{
Address: "127.0.0.1",
Port: 4646,
Token: "",
TLS: TLS{
Active: false,
CAFile: "",
CertFile: "",
KeyFile: "",
},
Namespace: "default",
},
Logger: logger{
@ -54,21 +61,37 @@ type server struct {
Address string
Port int
Token string
TLS bool
CertFile string
KeyFile string
TLS TLS
InteractiveStderr bool
}
// nomad configures the used Nomad cluster.
type nomad struct {
// URL returns the URL of the Poseidon webserver.
func (s *server) URL() *url.URL {
return parseURL(s.Address, s.Port, s.TLS.Active)
}
// Nomad configures the used Nomad cluster.
type Nomad struct {
Address string
Port int
Token string
TLS bool
TLS TLS
Namespace string
}
// URL returns the URL for the configured Nomad cluster.
func (n *Nomad) URL() *url.URL {
return parseURL(n.Address, n.Port, n.TLS.Active)
}
// TLS configures TLS on a connection.
type TLS struct {
Active bool
CAFile string
CertFile string
KeyFile string
}
// logger configures the used logger.
type logger struct {
Level string
@ -77,7 +100,7 @@ type logger struct {
// configuration contains the complete configuration of Poseidon.
type configuration struct {
Server server
Nomad nomad
Nomad Nomad
Logger logger
}
@ -96,16 +119,6 @@ func InitConfig() error {
return nil
}
// NomadAPIURL returns the URL for the configured Nomad cluster.
func (c *configuration) NomadAPIURL() *url.URL {
return parseURL(Config.Nomad.Address, Config.Nomad.Port, Config.Nomad.TLS)
}
// PoseidonAPIURL returns the URL of the Poseidon webserver.
func (c *configuration) PoseidonAPIURL() *url.URL {
return parseURL(Config.Server.Address, Config.Server.Port, false)
}
func parseURL(address string, port int, tlsEnabled bool) *url.URL {
scheme := "http"
if tlsEnabled {