Skip to content

Commit

Permalink
warp: fix duplicate device bug
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Pashmfouroush <mark@markpash.me>
  • Loading branch information
markpash committed May 30, 2024
1 parent dc4f281 commit febfb47
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions warp/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,35 @@ func LoadOrCreateIdentity(l *slog.Logger, path, license string) (*Identity, erro
if err := os.RemoveAll(path); err != nil {
return nil, err
}

if err := os.MkdirAll(path, os.ModePerm); err != nil {
return nil, err
}
i, err = CreateIdentity(l, path, license)

i, err = CreateIdentity(l, license)
if err != nil {
return nil, err
}

if err = saveIdentity(i, path); err != nil {
return nil, err
}
}

if license != "" && i.Account.License != license {
l.Info("license recreating identity with new license")
if err := os.RemoveAll(path); err != nil {
l.Info("updating account license key")
_, err := UpdateAccount(i.Token, i.ID, license)
if err != nil {
return nil, err
}
if err := os.MkdirAll(path, os.ModePerm); err != nil {

iAcc, err := GetAccount(i.Token, i.ID)
if err != nil {
return nil, err
}
i, err = CreateIdentity(l, path, license)
if err != nil {
i.Account = iAcc

if err = saveIdentity(i, path); err != nil {
return nil, err
}
}
Expand Down Expand Up @@ -87,7 +97,7 @@ func LoadIdentity(path string) (Identity, error) {
return *i, nil
}

func CreateIdentity(l *slog.Logger, path, license string) (Identity, error) {
func CreateIdentity(l *slog.Logger, license string) (Identity, error) {
priv, err := GeneratePrivateKey()
if err != nil {
return Identity{}, err
Expand All @@ -103,7 +113,12 @@ func CreateIdentity(l *slog.Logger, path, license string) (Identity, error) {

if license != "" {
l.Info("updating account license key")
ac, err := UpdateAccount(i.Token, i.ID, license)
_, err := UpdateAccount(i.Token, i.ID, license)
if err != nil {
return Identity{}, err
}

ac, err := GetAccount(i.Token, i.ID)
if err != nil {
return Identity{}, err
}
Expand All @@ -112,10 +127,5 @@ func CreateIdentity(l *slog.Logger, path, license string) (Identity, error) {

i.PrivateKey = privateKey

err = saveIdentity(i, path)
if err != nil {
return Identity{}, err
}

return i, nil
}

0 comments on commit febfb47

Please sign in to comment.