depenv: ntppool configuration for deployment environments
This commit is contained in:
40
config/depenv/monitor_names.go
Normal file
40
config/depenv/monitor_names.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package depenv
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var monitorApiServers = map[DeploymentEnvironment]string{
|
||||
DeployDevel: "https://api.devel.mon.ntppool.dev",
|
||||
DeployTest: "https://api.test.mon.ntppool.dev",
|
||||
DeployProd: "https://api.mon.ntppool.dev",
|
||||
}
|
||||
|
||||
func (d DeploymentEnvironment) MonitorAPIHost() string {
|
||||
return monitorApiServers[d]
|
||||
}
|
||||
|
||||
func GetDeploymentEnvironmentFromName(clientName string) (DeploymentEnvironment, error) {
|
||||
clientName = strings.ToLower(clientName)
|
||||
|
||||
if !strings.HasSuffix(clientName, ".mon.ntppool.dev") {
|
||||
return DeployUndefined, fmt.Errorf("invalid client name %s", clientName)
|
||||
}
|
||||
|
||||
if clientName == "api.mon.ntppool.dev" {
|
||||
return DeployProd, nil
|
||||
}
|
||||
|
||||
prefix := clientName[:strings.Index(clientName, ".mon.ntppool.dev")]
|
||||
parts := strings.Split(prefix, ".")
|
||||
if len(parts) != 2 {
|
||||
return DeployUndefined, fmt.Errorf("invalid client name %s", clientName)
|
||||
}
|
||||
|
||||
if d := DeploymentEnvironmentFromString(parts[1]); d != DeployUndefined {
|
||||
return d, nil
|
||||
}
|
||||
|
||||
return DeployUndefined, fmt.Errorf("invalid client name %s (unknown environment %s)", clientName, parts[1])
|
||||
}
|
Reference in New Issue
Block a user