2022-11-02 23:22:40 +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
|
2021-03-26 00:17:52 +08:00
|
|
|
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 {
|
2023-03-02 06:10:36 +08:00
|
|
|
CoreDNSAddr string `yaml:"corednsaddr"`
|
|
|
|
APIConnString string `yaml:"apiconn"`
|
|
|
|
APIHost string `yaml:"apihost"`
|
|
|
|
APIPort string `yaml:"apiport"`
|
|
|
|
Broker string `yam:"broker"`
|
|
|
|
ServerBrokerEndpoint string `yaml:"serverbrokerendpoint"`
|
|
|
|
BrokerType string `yaml:"brokertype"`
|
|
|
|
EmqxRestEndpoint string `yaml:"emqxrestendpoint"`
|
|
|
|
MasterKey string `yaml:"masterkey"`
|
|
|
|
DNSKey string `yaml:"dnskey"`
|
|
|
|
AllowedOrigin string `yaml:"allowedorigin"`
|
|
|
|
NodeID string `yaml:"nodeid"`
|
|
|
|
RestBackend string `yaml:"restbackend"`
|
|
|
|
MessageQueueBackend string `yaml:"messagequeuebackend"`
|
|
|
|
DNSMode string `yaml:"dnsmode"`
|
|
|
|
DisableRemoteIPCheck string `yaml:"disableremoteipcheck"`
|
|
|
|
Version string `yaml:"version"`
|
|
|
|
SQLConn string `yaml:"sqlconn"`
|
|
|
|
Platform string `yaml:"platform"`
|
|
|
|
Database string `yaml:"database"`
|
|
|
|
Verbosity int32 `yaml:"verbosity"`
|
|
|
|
AuthProvider string `yaml:"authprovider"`
|
|
|
|
OIDCIssuer string `yaml:"oidcissuer"`
|
|
|
|
ClientID string `yaml:"clientid"`
|
|
|
|
ClientSecret string `yaml:"clientsecret"`
|
|
|
|
FrontendURL string `yaml:"frontendurl"`
|
|
|
|
DisplayKeys string `yaml:"displaykeys"`
|
|
|
|
AzureTenant string `yaml:"azuretenant"`
|
|
|
|
Telemetry string `yaml:"telemetry"`
|
|
|
|
HostNetwork string `yaml:"hostnetwork"`
|
|
|
|
Server string `yaml:"server"`
|
|
|
|
PublicIPService string `yaml:"publicipservice"`
|
|
|
|
MQPassword string `yaml:"mqpassword"`
|
|
|
|
MQUserName string `yaml:"mqusername"`
|
|
|
|
MetricsExporter string `yaml:"metrics_exporter"`
|
|
|
|
BasicAuth string `yaml:"basic_auth"`
|
|
|
|
LicenseValue string `yaml:"license_value"`
|
|
|
|
NetmakerAccountID string `yaml:"netmaker_account_id"`
|
|
|
|
IsEE string `yaml:"is_ee"`
|
|
|
|
StunPort int `yaml:"stun_port"`
|
2023-03-03 23:37:04 +08:00
|
|
|
StunList string `yaml:"stun_list"`
|
2023-03-02 06:10:36 +08:00
|
|
|
Proxy string `yaml:"proxy"`
|
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
|
|
|
}
|