feat: first project flow

This commit is contained in:
braginini
2021-04-14 14:20:25 +02:00
commit 6b3ba0feaf
23 changed files with 2288 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
package wiretrustee
import (
"context"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/wiretrustee/wiretrustee/signal"
"github.com/wiretrustee/wiretrustee/signal/proto"
"os"
)
const (
ExitSetupFailed = 1
)
func init() {
runCmd := &cobra.Command{
Use: "start",
Short: "start wiretrustee",
Run: func(cmd *cobra.Command, args []string) {
config, err := ReadConfig("config.yml")
if err != nil {
log.Fatal("failed to load config")
os.Exit(ExitSetupFailed)
}
//todo print config
//todo connect to signal
ctx := context.Background()
signalClient, err := signal.NewClient(config.SignalAddr, ctx)
if err != nil {
log.Errorf("error while connecting to the Signal Exchange Service %s: %s", config.SignalAddr, err)
os.Exit(ExitSetupFailed)
}
//todo proper close handling
defer func() { signalClient.Close() }()
signalClient.WaitConnected()
select {}
},
}
rootCmd.AddCommand(runCmd)
}
func ReadConfig(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 = yaml.Unmarshal(bs, &cfg)
if err != nil {
return nil, err
}
return &cfg, nil*/
return &Config{}, nil
}

12
cmd/wiretrustee/config.go Normal file
View File

@@ -0,0 +1,12 @@
package wiretrustee
import "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
type Config struct {
// Wireguard private key of local peer
PrivateKey wgtypes.Key
// configured remote peers (Wireguard public keys)
Peers string
// host:port of the signal server
SignalAddr string
}