Skip to content

Commit 2fe51a1

Browse files
authored
fix: don't update private key after updating license key (#355)
1 parent 0fa9ee3 commit 2fe51a1

File tree

2 files changed

+5
-27
lines changed

2 files changed

+5
-27
lines changed

cloudflare/api.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,16 @@ func GetAccount(ctx *config.Context) (*Account, error) {
102102
return &castResult, err
103103
}
104104

105-
func UpdateLicenseKey(ctx *config.Context, newPublicKey string) (*openapi.UpdateAccount200Response, *Device, error) {
105+
func UpdateLicenseKey(ctx *config.Context) (*openapi.UpdateAccount200Response, error) {
106106
result, _, err := globalClientAuth(ctx.AccessToken).DefaultApi.
107107
UpdateAccount(nil, ctx.DeviceId, ApiVersion).
108108
UpdateAccountRequest(openapi.UpdateAccountRequest{License: ctx.LicenseKey}).
109109
Execute()
110110
if err != nil {
111-
return nil, nil, err
112-
}
113-
// change public key as per official client
114-
result2, _, err := globalClientAuth(ctx.AccessToken).DefaultApi.
115-
UpdateSourceDevice(nil, ApiVersion, ctx.DeviceId).
116-
UpdateSourceDeviceRequest(openapi.UpdateSourceDeviceRequest{Key: newPublicKey}).
117-
Execute()
118-
castResult := Device(result2)
119-
if err != nil {
120-
return nil, nil, err
111+
return nil, err
121112
}
122-
return &result, &castResult, nil
113+
114+
return &result, nil
123115
}
124116

125117
type BoundDevice openapi.GetBoundDevices200Response

cmd/update/update.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ import (
77
. "github.com/ViRb3/wgcf/cmd/shared"
88
"github.com/ViRb3/wgcf/config"
99
"github.com/ViRb3/wgcf/util"
10-
"github.com/ViRb3/wgcf/wireguard"
1110
"github.com/pkg/errors"
1211
"github.com/spf13/cobra"
13-
"github.com/spf13/viper"
1412
)
1513

1614
var deviceName string
@@ -82,17 +80,8 @@ func ensureLicenseKeyUpToDate(ctx *config.Context, thisDevice *cloudflare.Device
8280
}
8381

8482
func updateLicenseKey(ctx *config.Context) (*cloudflare.Account, *cloudflare.Device, error) {
85-
newPrivateKey, err := wireguard.NewPrivateKey()
86-
if err != nil {
87-
return nil, nil, err
88-
}
89-
newPublicKey := newPrivateKey.Public()
90-
if _, _, err := cloudflare.UpdateLicenseKey(ctx, newPublicKey.String()); err != nil {
91-
return nil, nil, err
92-
}
9383

94-
viper.Set(config.PrivateKey, newPrivateKey.String())
95-
if err := viper.WriteConfig(); err != nil {
84+
if _, err := cloudflare.UpdateLicenseKey(ctx); err != nil {
9685
return nil, nil, err
9786
}
9887

@@ -108,9 +97,6 @@ func updateLicenseKey(ctx *config.Context) (*cloudflare.Account, *cloudflare.Dev
10897
if account.License != ctx.LicenseKey {
10998
return nil, nil, errors.New("failed to update license key")
11099
}
111-
if thisDevice.Key != newPublicKey.String() {
112-
return nil, nil, errors.New("failed to update public key")
113-
}
114100

115101
return account, thisDevice, nil
116102
}

0 commit comments

Comments
 (0)