2021-03-26 00:17:52 +08:00
|
|
|
//Environment file for getting variables
|
|
|
|
//Currently the only thing it does is set the master password
|
|
|
|
//Should probably have it take over functions from OS such as port and mongodb connection details
|
|
|
|
//Reads from the config/environments/dev.yaml file by default
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2021-07-15 04:47:05 +08:00
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v3"
|
2021-03-26 00:17:52 +08:00
|
|
|
)
|
|
|
|
|
2022-01-04 00:30:02 +08:00
|
|
|
// setting dev by default
|
2021-03-26 00:17:52 +08:00
|
|
|
func getEnv() string {
|
|
|
|
|
2021-07-15 04:47:05 +08:00
|
|
|
env := os.Getenv("NETMAKER_ENV")
|
2021-03-26 00:17:52 +08:00
|
|
|
|
2021-07-15 04:47:05 +08:00
|
|
|
if len(env) == 0 {
|
|
|
|
return "dev"
|
|
|
|
}
|
2021-03-26 00:17:52 +08:00
|
|
|
|
2021-07-15 04:47:05 +08:00
|
|
|
return env
|
2021-03-26 00:17:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Config : application config stored as global variable
|
|
|
|
var Config *EnvironmentConfig
|
|
|
|
|
2022-01-04 00:30:02 +08:00
|
|
|
// EnvironmentConfig - environment conf struct
|
2021-03-26 00:17:52 +08:00
|
|
|
type EnvironmentConfig struct {
|
2021-07-22 06:55:19 +08:00
|
|
|
Server ServerConfig `yaml:"server"`
|
2021-10-21 02:17:31 +08:00
|
|
|
SQL SQLConfig `yaml:"sql"`
|
2021-03-26 00:17:52 +08:00
|
|
|
}
|
|
|
|
|
2022-01-04 00:30:02 +08:00
|
|
|
// ServerConfig - server conf struct
|
2021-03-26 00:17:52 +08:00
|
|
|
type ServerConfig struct {
|
2021-10-21 02:17:31 +08:00
|
|
|
CoreDNSAddr string `yaml:"corednsaddr"`
|
|
|
|
APIConnString string `yaml:"apiconn"`
|
|
|
|
APIHost string `yaml:"apihost"`
|
|
|
|
APIPort string `yaml:"apiport"`
|
|
|
|
GRPCConnString string `yaml:"grpcconn"`
|
|
|
|
GRPCHost string `yaml:"grpchost"`
|
|
|
|
GRPCPort string `yaml:"grpcport"`
|
|
|
|
GRPCSecure string `yaml:"grpcsecure"`
|
2022-01-13 05:23:34 +08:00
|
|
|
MQHOST string `yaml:"mqhost"`
|
2021-10-21 02:17:31 +08:00
|
|
|
MasterKey string `yaml:"masterkey"`
|
2021-11-16 00:42:52 +08:00
|
|
|
DNSKey string `yaml:"dnskey"`
|
2021-10-21 02:17:31 +08:00
|
|
|
AllowedOrigin string `yaml:"allowedorigin"`
|
|
|
|
NodeID string `yaml:"nodeid"`
|
|
|
|
RestBackend string `yaml:"restbackend"`
|
|
|
|
AgentBackend string `yaml:"agentbackend"`
|
2022-01-13 05:23:34 +08:00
|
|
|
MessageQueueBackend string `yaml:"messagequeuebackend"`
|
2021-10-21 02:17:31 +08:00
|
|
|
ClientMode string `yaml:"clientmode"`
|
|
|
|
DNSMode string `yaml:"dnsmode"`
|
|
|
|
SplitDNS string `yaml:"splitdns"`
|
|
|
|
DisableRemoteIPCheck string `yaml:"disableremoteipcheck"`
|
|
|
|
DisableDefaultNet string `yaml:"disabledefaultnet"`
|
|
|
|
GRPCSSL string `yaml:"grpcssl"`
|
|
|
|
Version string `yaml:"version"`
|
|
|
|
SQLConn string `yaml:"sqlconn"`
|
|
|
|
Platform string `yaml:"platform"`
|
2022-01-04 00:30:02 +08:00
|
|
|
Database string `yaml:"database"`
|
|
|
|
CheckinInterval string `yaml:"checkininterval"`
|
2021-10-21 02:17:31 +08:00
|
|
|
DefaultNodeLimit int32 `yaml:"defaultnodelimit"`
|
|
|
|
Verbosity int32 `yaml:"verbosity"`
|
2021-10-18 21:28:46 +08:00
|
|
|
ServerCheckinInterval int64 `yaml:"servercheckininterval"`
|
2021-10-21 02:17:31 +08:00
|
|
|
AuthProvider string `yaml:"authprovider"`
|
|
|
|
ClientID string `yaml:"clientid"`
|
|
|
|
ClientSecret string `yaml:"clientsecret"`
|
2021-10-22 03:28:58 +08:00
|
|
|
FrontendURL string `yaml:"frontendurl"`
|
2021-11-15 05:50:20 +08:00
|
|
|
DisplayKeys string `yaml:"displaykeys"`
|
2022-01-03 23:01:37 +08:00
|
|
|
AzureTenant string `yaml:"azuretenant"`
|
2022-01-06 02:13:03 +08:00
|
|
|
RCE string `yaml:"rce"`
|
2022-01-21 18:19:17 +08:00
|
|
|
Debug bool `yaml:"debug"`
|
2022-01-21 06:50:42 +08:00
|
|
|
Telemetry string `yaml:"telemetry"`
|
2022-01-26 00:58:51 +08:00
|
|
|
ManageIPTables string `yaml:"manageiptables"`
|
|
|
|
PortForwardServices string `yaml:"portforwardservices"`
|
2022-01-26 13:46:12 +08:00
|
|
|
HostNetwork string `yaml:"hostnetwork"`
|
2021-03-26 00:17:52 +08:00
|
|
|
}
|
|
|
|
|
2022-01-04 00:30:02 +08:00
|
|
|
// SQLConfig - Generic SQL Config
|
2021-10-09 01:11:31 +08:00
|
|
|
type SQLConfig struct {
|
2021-10-21 02:17:31 +08:00
|
|
|
Host string `yaml:"host"`
|
|
|
|
Port int32 `yaml:"port"`
|
2021-10-09 01:11:31 +08:00
|
|
|
Username string `yaml:"username"`
|
|
|
|
Password string `yaml:"password"`
|
2021-10-21 02:17:31 +08:00
|
|
|
DB string `yaml:"db"`
|
|
|
|
SSLMode string `yaml:"sslmode"`
|
2021-10-09 01:11:31 +08:00
|
|
|
}
|
|
|
|
|
2022-01-04 00:30:02 +08:00
|
|
|
// reading in the env file
|
2021-03-26 00:17:52 +08:00
|
|
|
func readConfig() *EnvironmentConfig {
|
2021-07-15 04:47:05 +08:00
|
|
|
file := fmt.Sprintf("config/environments/%s.yaml", getEnv())
|
|
|
|
f, err := os.Open(file)
|
|
|
|
var cfg EnvironmentConfig
|
|
|
|
if err != nil {
|
|
|
|
return &cfg
|
|
|
|
}
|
|
|
|
defer f.Close()
|
2021-03-26 00:17:52 +08:00
|
|
|
|
2021-07-15 04:47:05 +08:00
|
|
|
decoder := yaml.NewDecoder(f)
|
|
|
|
err = decoder.Decode(&cfg)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
return &cfg
|
2021-03-26 00:17:52 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2021-07-15 04:47:05 +08:00
|
|
|
Config = readConfig()
|
2021-03-26 00:17:52 +08:00
|
|
|
}
|