-
-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
77 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,58 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/pion/ice/v2" | ||
"github.com/wiretrustee/wiretrustee/connection" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
type Config struct { | ||
// Wireguard private key of local peer | ||
PrivateKey string | ||
// configured remote peers (Wireguard public keys) | ||
Peers string | ||
StunURL string | ||
TurnURL string | ||
TurnUser string | ||
TurnPwd string | ||
Peers []connection.Peer | ||
StunTurnURLs []*ice.URL | ||
// host:port of the signal server | ||
SignalAddr string | ||
WgAddr string | ||
WgIface string | ||
} | ||
|
||
//Write writes configPath to a file | ||
func (cfg *Config) Write(path string) error { | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters