From e8d88f7e71fc1ca3fd1ac60c58a41e82cd690cc7 Mon Sep 17 00:00:00 2001 From: James Batt Date: Thu, 20 Feb 2020 21:12:30 +1100 Subject: [PATCH] wip --- .gitignore | 1 + internal/config/config.go | 5 +++++ internal/devices/devices.go | 3 ++- main.go | 3 ++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5b6b0720..f979fd1c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ config.yaml +data/ diff --git a/internal/config/config.go b/internal/config/config.go index ce944230..1cfcba8b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -148,6 +148,11 @@ func Read() *AppConfig { if config.Storage.Directory == "" { logrus.Warn("storage directory not configured - using in-memory storage backend! wireguard devices will be lost when the process exits!") + } else { + config.Storage.Directory, err = filepath.Abs(config.Storage.Directory) + if err != nil { + logrus.Fatal(errors.Wrap(err, "failed to get absolute path to storage directory")) + } } return &config diff --git a/internal/devices/devices.go b/internal/devices/devices.go index 4c5b9edd..3abce552 100644 --- a/internal/devices/devices.go +++ b/internal/devices/devices.go @@ -4,6 +4,7 @@ import ( "fmt" "net" "os" + "path/filepath" "sync" "time" @@ -89,7 +90,7 @@ func (d *DeviceManager) DeleteDevice(user string, name string) error { } func key(user string, device string) string { - return fmt.Sprintf("%s/%s", user, device) + return filepath.Join(user, device) } var nextIPLock = sync.Mutex{} diff --git a/main.go b/main.go index 2fcd15bd..b0afa703 100644 --- a/main.go +++ b/main.go @@ -73,6 +73,7 @@ func main() { // Storage var storageDriver storage.Storage if conf.Storage.Directory != "" { + logrus.Infof("storing data in %s", conf.Storage.Directory) storageDriver = storage.NewDiskStorage(conf.Storage.Directory) } else { storageDriver = storage.NewMemoryStorage() @@ -128,7 +129,7 @@ func main() { handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { base.ServeHTTP(w, r.WithContext(authsession.SetIdentityCtx(r.Context(), &authsession.AuthSession{ Identity: &authsession.Identity{ - Subject: "default", + Subject: "", }, }))) })