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"
|
|
|
|
"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")
|
|
|
|
if len(env) == 0 {
|
|
|
|
return "dev"
|
|
|
|
}
|
|
|
|
return env
|
2021-03-26 00:17:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Config : application config stored as global variable
|
2022-03-23 05:22:34 +08:00
|
|
|
var Config *EnvironmentConfig = &EnvironmentConfig{}
|
2022-03-19 03:06:48 +08:00
|
|
|
var SetupErr error
|
2021-03-26 00:17:52 +08:00
|
|
|
|
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"`
|
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"`
|
|
|
|
DisableRemoteIPCheck string `yaml:"disableremoteipcheck"`
|
|
|
|
Version string `yaml:"version"`
|
|
|
|
SQLConn string `yaml:"sqlconn"`
|
|
|
|
Platform string `yaml:"platform"`
|
2022-01-04 00:30:02 +08:00
|
|
|
Database string `yaml:"database"`
|
2021-10-21 02:17:31 +08:00
|
|
|
DefaultNodeLimit int32 `yaml:"defaultnodelimit"`
|
2022-04-22 05:48:36 +08:00
|
|
|
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 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"`
|
2022-02-19 04:18:50 +08:00
|
|
|
MQPort string `yaml:"mqport"`
|
2022-05-25 22:31:44 +08:00
|
|
|
MQServerPort string `yaml:"mqserverport"`
|
2022-04-12 22:43:02 +08:00
|
|
|
Server string `yaml:"server"`
|
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
|
2022-03-23 05:22:34 +08:00
|
|
|
func ReadConfig(absolutePath string) (*EnvironmentConfig, error) {
|
|
|
|
if len(absolutePath) == 0 {
|
|
|
|
absolutePath = fmt.Sprintf("environments/%s.yaml", getEnv())
|
|
|
|
}
|
|
|
|
f, err := os.Open(absolutePath)
|
2021-07-15 04:47:05 +08:00
|
|
|
var cfg EnvironmentConfig
|
|
|
|
if err != nil {
|
2022-03-19 03:06:48 +08:00
|
|
|
return &cfg, err
|
2021-07-15 04:47:05 +08:00
|
|
|
}
|
|
|
|
defer f.Close()
|
2021-03-26 00:17:52 +08:00
|
|
|
|
2021-07-15 04:47:05 +08:00
|
|
|
decoder := yaml.NewDecoder(f)
|
2022-03-19 03:06:48 +08:00
|
|
|
if decoder.Decode(&cfg) != nil {
|
|
|
|
return &cfg, err
|
2021-07-15 04:47:05 +08:00
|
|
|
}
|
2022-03-19 03:06:48 +08:00
|
|
|
return &cfg, err
|
2021-03-26 00:17:52 +08:00
|
|
|
}
|