diff --git a/cloudflare/api.go b/cloudflare/api.go index d0d7a2c4..6a042bc9 100644 --- a/cloudflare/api.go +++ b/cloudflare/api.go @@ -102,24 +102,16 @@ func GetAccount(ctx *config.Context) (*Account, error) { return &castResult, err } -func UpdateLicenseKey(ctx *config.Context, newPublicKey string) (*openapi.UpdateAccount200Response, *Device, error) { +func UpdateLicenseKey(ctx *config.Context) (*openapi.UpdateAccount200Response, error) { result, _, err := globalClientAuth(ctx.AccessToken).DefaultApi. UpdateAccount(nil, ctx.DeviceId, ApiVersion). UpdateAccountRequest(openapi.UpdateAccountRequest{License: ctx.LicenseKey}). Execute() if err != nil { - return nil, nil, err - } - // change public key as per official client - result2, _, err := globalClientAuth(ctx.AccessToken).DefaultApi. - UpdateSourceDevice(nil, ApiVersion, ctx.DeviceId). - UpdateSourceDeviceRequest(openapi.UpdateSourceDeviceRequest{Key: newPublicKey}). - Execute() - castResult := Device(result2) - if err != nil { - return nil, nil, err + return nil, err } - return &result, &castResult, nil + + return &result, nil } type BoundDevice openapi.GetBoundDevices200Response diff --git a/cmd/update/update.go b/cmd/update/update.go index 8bea5fe0..4157e986 100644 --- a/cmd/update/update.go +++ b/cmd/update/update.go @@ -7,10 +7,8 @@ import ( . "github.com/ViRb3/wgcf/cmd/shared" "github.com/ViRb3/wgcf/config" "github.com/ViRb3/wgcf/util" - "github.com/ViRb3/wgcf/wireguard" "github.com/pkg/errors" "github.com/spf13/cobra" - "github.com/spf13/viper" ) var deviceName string @@ -82,17 +80,8 @@ func ensureLicenseKeyUpToDate(ctx *config.Context, thisDevice *cloudflare.Device } func updateLicenseKey(ctx *config.Context) (*cloudflare.Account, *cloudflare.Device, error) { - newPrivateKey, err := wireguard.NewPrivateKey() - if err != nil { - return nil, nil, err - } - newPublicKey := newPrivateKey.Public() - if _, _, err := cloudflare.UpdateLicenseKey(ctx, newPublicKey.String()); err != nil { - return nil, nil, err - } - viper.Set(config.PrivateKey, newPrivateKey.String()) - if err := viper.WriteConfig(); err != nil { + if _, err := cloudflare.UpdateLicenseKey(ctx); err != nil { return nil, nil, err } @@ -108,9 +97,6 @@ func updateLicenseKey(ctx *config.Context) (*cloudflare.Account, *cloudflare.Dev if account.License != ctx.LicenseKey { return nil, nil, errors.New("failed to update license key") } - if thisDevice.Key != newPublicKey.String() { - return nil, nil, errors.New("failed to update public key") - } return account, thisDevice, nil }