Skip to content

Commit

Permalink
adding logging of the errors
Browse files Browse the repository at this point in the history
Signed-off-by: Rasmi V. Mahmoud <[email protected]>
  • Loading branch information
rasmim committed Aug 16, 2021
1 parent 33dbeff commit 92d3290
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/aau-network-security/gwireguard
go 1.13

require (
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/rs/zerolog v1.19.0
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand All @@ -19,6 +17,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.m
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down
10 changes: 9 additions & 1 deletion vpn/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (w *wireguard) InitializeI(ctx context.Context, r *pb.IReq) (*pb.IResp, err
log.Info().Msgf("Initializing interface for %s ", r.IName)
privKey, err := generatePrivateKey(w.config.WgConfig.Dir + r.IName + "_priv")
if err != nil {
log.Error().Err(err).Str("privatekey: ", privKey).Msg("Problem in generating the privatekey")
return &pb.IResp{}, err
}
log.Info().Msgf("Private key is generated %s with name %s", w.config.WgConfig.Dir, r.IName)
Expand All @@ -52,11 +53,16 @@ func (w *wireguard) InitializeI(ctx context.Context, r *pb.IReq) (*pb.IResp, err

out, err := genInterfaceConf(wgI, w.config.WgConfig.Dir)
if err != nil {
log.Error().Err(err).Str("interface:%s ", wgI.iName).Msg("Problem in configuration of the interface")

return &pb.IResp{Message: out}, fmt.Errorf("Problem in configuration of the interface -- %v", err)
}

out, err = upDown(r.IName, "up")

if err != nil {

log.Error().Err(err).Str("interface: ", out).Msg("Problem in making the interface UP")
return &pb.IResp{Message: out}, fmt.Errorf("PROBLEM IN THE FUNCTION upDown -- %v", err)
}
log.Debug().Str("Address: ", r.Address).
Expand Down Expand Up @@ -149,9 +155,11 @@ func (w *wireguard) GenPublicKey(ctx context.Context, r *pb.PubKeyReq) (*pb.PubK
// check whether private key exists or not, if not generate one
if _, err := os.Stat(w.config.WgConfig.Dir + r.PrivKeyName + "_pub"); os.IsNotExist(err) {
fmt.Printf("PrivateKeyFile is not exists, creating one ... %s\n", r.PrivKeyName)
_, err := generatePrivateKey(w.config.WgConfig.Dir + r.PrivKeyName + "_priv")
privKey, err := generatePrivateKey(w.config.WgConfig.Dir + r.PrivKeyName + "_priv")
if err != nil {
log.Error().Err(err).Str("Privatekey: %s ", privKey).Msg("Problem in generation of private key")
return &pb.PubKeyResp{Message: "Error"}, fmt.Errorf("error in generation of private key %v", err)

}
}

Expand Down
12 changes: 9 additions & 3 deletions vpn/vpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ const (
var (
// todo: fix configuration variables
//variablesvariablesΩos.Setenv("FOO", "1")
configPath = getConfigPath()
configuration, _ = config.NewConfig(configPath)
configuration, _ = config.NewConfig(os.Getenv("CONFIG_PATH"))
//configPath = getConfigPath()
//configuration, _ = config.NewConfig(configPath)
)

type Interface struct {
Expand Down Expand Up @@ -185,6 +186,7 @@ func upDown(nic, cmd string) (string, error) {

return "", fmt.Errorf("failed to execute command: %s error: %v", command, err)
}

return "Interface " + nic + " is " + cmd, nil
}

Expand Down Expand Up @@ -300,4 +302,8 @@ func getConfigPath() string {
fullPathToconfig := fmt.Sprintf("%s%s", dir, "/config/config.yml")

return fullPathToconfig
}
}

func init() {
getConfigPath()
}

0 comments on commit 92d3290

Please sign in to comment.