Skip to content

Commit

Permalink
fix: dump device.json on login
Browse files Browse the repository at this point in the history
  • Loading branch information
anatolio-deb committed Apr 3, 2023
1 parent 2962434 commit 451f9d8
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions src/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"errors"
"fmt"
"log"
Expand Down Expand Up @@ -98,6 +99,33 @@ func main() {
return err
}

device, err := auth.LoadDevice(profile.ID)

if err != nil {
logger.WithError(err).Debugf("failed to %+v", err)
// return err
}

if len(device.GetId()) == 0 {
device, err = profile.ApiClient(utils.ApiHost).CreateDevice()

if err != nil {
return err
}

j, err := json.MarshalIndent(device, "", " ")

if err != nil {
return err
}

err = auth.JsonDump(j, auth.ProfilesDir+string(profile.ID)+auth.DeviceFile)

if err != nil {
return err
}
}

authClientWrapper, err := actions.GetAuthClientWrapper(profile, utils.ApiHost)
if err != nil {
logger.WithError(err).Debugf("failed to %+v", err)
Expand Down Expand Up @@ -159,17 +187,29 @@ func main() {

device, err := auth.LoadDevice(profile.ID)

if err != nil {
logger.WithError(err).Debugf("failed to %+v", err)
// return err
}

if len(device.GetId()) == 0 {
device, err = profile.ApiClient(utils.ApiHost).CreateDevice()

if err != nil {
return err
}
}

if err != nil {
logger.WithError(err).Debugf("failed to %+v", err)
return err
j, err := json.MarshalIndent(device, "", " ")

if err != nil {
return err
}

err = auth.JsonDump(j, auth.ProfilesDir+string(profile.ID)+auth.DeviceFile)

if err != nil {
return err
}
}

if err = profile.CreateLocalWireguardConfigurationFile(device); err != nil {
Expand Down

0 comments on commit 451f9d8

Please sign in to comment.