Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warp: fix duplicate device bug #143

Merged
merged 1 commit into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}