mirror of
https://github.com/netbirdio/netbird.git
synced 2025-02-16 18:21:24 +01:00
* Add client's interaction with management service * Getting updates * Fixed key and nil ptr * Added setupKey param * Added managment address parameter * Fixed test * feature: use RemotePeers from the management server instead of deprecated Peers * merge: merge changes from main
72 lines
1.2 KiB
Go
72 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
ice "github.com/pion/ice/v2"
|
|
"github.com/wiretrustee/wiretrustee/connection"
|
|
)
|
|
|
|
// Config Configuration type
|
|
type Config struct {
|
|
// Wireguard private key of local peer
|
|
PrivateKey string
|
|
Peers []connection.Peer
|
|
StunTurnURLs []*ice.URL
|
|
// host:port of the signal server
|
|
SignalAddr string
|
|
ManagementAddr string
|
|
WgAddr string
|
|
WgIface string
|
|
IFaceBlackList []string
|
|
}
|
|
|
|
//Write writes configPath to a file
|
|
func (cfg *Config) Write(path string) error {
|
|
|
|
if path == defaultConfigPath {
|
|
configDir := filepath.Dir(path)
|
|
err := os.MkdirAll(configDir, 0750)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
bs, err := json.Marshal(cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = ioutil.WriteFile(path, bs, 0600)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
//Read reads configPath from a file
|
|
func Read(path string) (*Config, error) {
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
|
|
bs, err := ioutil.ReadAll(f)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var cfg Config
|
|
err = json.Unmarshal(bs, &cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|