chore: upgrade Go to 1.27 (#30601)
This commit is contained in:
parent
748d36d130
commit
e63bae0c8b
37 changed files with 135 additions and 154 deletions
|
|
@ -14,10 +14,10 @@ import (
|
|||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
"uuid"
|
||||
|
||||
"github.com/evcc-io/evcc/server/db/settings"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
|
|
@ -92,7 +92,7 @@ func (v *Identity) loginCCI(password string) (*oauth2.Token, error) {
|
|||
// fetch RSA cert, signin, exchange the auth code for CCI and then CCS tokens
|
||||
func (v *Identity) loginCCIPassword(password string) (*oauth2.Token, error) {
|
||||
c := v.config.CCI
|
||||
deviceID := uuid.NewString()
|
||||
deviceID := uuid.New().String()
|
||||
|
||||
v.log.DEBUG.Println("cci: logging in via OneApp/CCI password login")
|
||||
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"uuid"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/oauth"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/google/uuid"
|
||||
"github.com/samber/lo"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
|
@ -79,11 +79,11 @@ func (v *Identity) getDeviceID() (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
uuid := uuid.NewString()
|
||||
id := uuid.New().String()
|
||||
data := map[string]any{
|
||||
"pushRegId": lo.RandomString(64, []rune("0123456789ABCDEF")),
|
||||
"pushType": v.config.PushType,
|
||||
"uuid": uuid,
|
||||
"uuid": id,
|
||||
}
|
||||
|
||||
headers := map[string]string{
|
||||
|
|
|
|||
|
|
@ -150,8 +150,8 @@ func TestLoginUsesCCIAndWiresRefreshCCI(t *testing.T) {
|
|||
loginSrv := httptest.NewServer(loginMux)
|
||||
defer loginSrv.Close()
|
||||
|
||||
var refreshCalls int32
|
||||
var exchangeCalls int32
|
||||
var refreshCalls atomic.Int32
|
||||
var exchangeCalls atomic.Int32
|
||||
cciMux := http.NewServeMux()
|
||||
cciMux.HandleFunc("/domain/api/v1/auth/token", func(w http.ResponseWriter, _ *http.Request) {
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
|
|
@ -165,14 +165,14 @@ func TestLoginUsesCCIAndWiresRefreshCCI(t *testing.T) {
|
|||
// the first (login) exchange returns a token expiring inside oauth2's
|
||||
// 10s buffer, so the next Token() call triggers exactly one refresh
|
||||
resp := map[string]any{"accessToken": "ccs-token-2", "expiresTime": time.Now().Add(time.Hour).Unix()}
|
||||
if atomic.AddInt32(&exchangeCalls, 1) == 1 {
|
||||
if exchangeCalls.Add(1) == 1 {
|
||||
resp["accessToken"] = "ccs-token-1"
|
||||
resp["expiresTime"] = time.Now().Add(5 * time.Second).Unix()
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(resp)
|
||||
})
|
||||
cciMux.HandleFunc("/domain/api/v2/auth/token-refresh", func(w http.ResponseWriter, _ *http.Request) {
|
||||
atomic.AddInt32(&refreshCalls, 1)
|
||||
refreshCalls.Add(1)
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"accessToken": "cci-access-2", "refreshToken": "cci-refresh-2",
|
||||
})
|
||||
|
|
@ -192,12 +192,12 @@ func TestLoginUsesCCIAndWiresRefreshCCI(t *testing.T) {
|
|||
token, err := identity.Token()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "ccs-token-2", token.AccessToken)
|
||||
assert.EqualValues(t, 1, atomic.LoadInt32(&refreshCalls), "expected TokenSource to be wired to refreshCCI")
|
||||
assert.EqualValues(t, 1, refreshCalls.Load(), "expected TokenSource to be wired to refreshCCI")
|
||||
|
||||
// the now long-lived token must not trigger a further refresh
|
||||
_, err = identity.Token()
|
||||
require.NoError(t, err)
|
||||
assert.EqualValues(t, 1, atomic.LoadInt32(&refreshCalls), "unexpected additional refresh")
|
||||
assert.EqualValues(t, 1, refreshCalls.Load(), "unexpected additional refresh")
|
||||
}
|
||||
|
||||
// TestLoginPropagatesLegacyError covers the legacy path: a failure there must
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
"uuid"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/evcc-io/evcc/vehicle/jlr"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// https://github.com/ardevd/jlrpy
|
||||
|
|
@ -54,7 +54,7 @@ func NewJLRFromConfig(other map[string]any) (api.Vehicle, error) {
|
|||
log := util.NewLogger("jlr").Redact(cc.User, cc.Password, cc.VIN, cc.DeviceID)
|
||||
|
||||
if cc.DeviceID == "" {
|
||||
cc.DeviceID = uuid.NewString()
|
||||
cc.DeviceID = uuid.New().String()
|
||||
log.WARN.Println("new device id generated, add `deviceid` to config:", cc.DeviceID)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"uuid"
|
||||
)
|
||||
|
||||
// Helper provides utility primitives
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ import (
|
|||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
"uuid"
|
||||
|
||||
"github.com/evcc-io/evcc/server/db/settings"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/oauth"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/evcc-io/evcc/util/transport"
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"uuid"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/evcc-io/evcc/vehicle/polestar/pb"
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/oauth2"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
|
|
@ -119,7 +119,7 @@ func (v *GrpcAPI) Battery(ctx context.Context, vin string) (*pb.Battery, error)
|
|||
ctx = metadata.AppendToOutgoingContext(ctx, "vin", vin)
|
||||
|
||||
res, err := v.client.GetLatestBattery(ctx, &pb.GetBatteryRequest{
|
||||
Id: uuid.NewString(),
|
||||
Id: uuid.New().String(),
|
||||
Vin: vin,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ func (v *API) doRepeatedRequest(path string, event_id string) error {
|
|||
event_id)
|
||||
|
||||
var res requests.Answer[requests.ChargeStatus]
|
||||
if _, err = doRequest(v, req, &res); err == nil {
|
||||
if _, err = v.doRequest(req, &res); err == nil {
|
||||
v.store(res.Data)
|
||||
}
|
||||
return err
|
||||
|
|
@ -120,7 +120,7 @@ func (v *API) repeatRequest(path string, event_id string) {
|
|||
v.mu.Unlock()
|
||||
}
|
||||
|
||||
func doRequest[T any](v *API, req *http.Request, result *requests.Answer[T]) (string, error) {
|
||||
func (v *API) doRequest[T any](req *http.Request, result *requests.Answer[T]) (string, error) {
|
||||
resp, err := v.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -183,7 +183,7 @@ func (v *API) Wakeup(vin string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
doRequest[any](v, req, nil)
|
||||
v.doRequest[any](req, nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -214,7 +214,7 @@ func (v *API) Status(vin string) (requests.ChargeStatus, error) {
|
|||
"")
|
||||
|
||||
var res requests.Answer[requests.ChargeStatus]
|
||||
event_id, err := doRequest(v, req, &res)
|
||||
event_id, err := v.doRequest(req, &res)
|
||||
if err != nil {
|
||||
return zero, err
|
||||
}
|
||||
|
|
@ -234,7 +234,7 @@ func (v *API) Status(vin string) (requests.ChargeStatus, error) {
|
|||
event_id)
|
||||
|
||||
// answer not yet available, keep polling in the background
|
||||
if _, err = doRequest(v, req, &res); err == api.ErrMustRetry {
|
||||
if _, err = v.doRequest(req, &res); err == api.ErrMustRetry {
|
||||
v.mu.Lock()
|
||||
v.state = stateRunning
|
||||
v.mu.Unlock()
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import (
|
|||
func TestCommandResponse(t *testing.T) {
|
||||
sponsor.Subject = "any"
|
||||
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
srv := httptest.NewTestServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println(r.URL.Path)
|
||||
|
||||
switch r.URL.Path {
|
||||
|
|
@ -29,7 +29,7 @@ func TestCommandResponse(t *testing.T) {
|
|||
w.Write([]byte(`{"response": null, "error": "vehicle unavailable: vehicle is offline or asleep"}`))
|
||||
}
|
||||
}))
|
||||
defer srv.Close()
|
||||
srv.Start()
|
||||
|
||||
ts := oauth2.StaticTokenSource(new(oauth2.Token))
|
||||
client, err := tesla.NewClient(t.Context(), tesla.WithTokenSource(ts))
|
||||
|
|
|
|||
|
|
@ -9,15 +9,14 @@ import (
|
|||
"net/http/cookiejar"
|
||||
"net/url"
|
||||
"strings"
|
||||
"uuid"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/coreos/go-oidc/v3/oidc"
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/evcc-io/evcc/util/urlvalues"
|
||||
"github.com/evcc-io/evcc/vehicle/vag"
|
||||
"github.com/google/uuid"
|
||||
"github.com/samber/lo"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
)
|
||||
|
|
@ -42,7 +41,7 @@ func LoginWithAuthURL(log *util.Logger, uri string, q url.Values, user, password
|
|||
var verify func(url.Values)
|
||||
|
||||
// add code challenge
|
||||
q = urlvalues.Copy(q)
|
||||
q = q.Clone()
|
||||
if rt := q.Get("response_type"); strings.Contains(rt, "code") {
|
||||
verify = vag.ChallengeAndVerifier(q)
|
||||
}
|
||||
|
|
@ -92,7 +91,7 @@ func (v *Service) Login(uri, user, password string) (url.Values, error) {
|
|||
// add nonce and state
|
||||
query := url.Values{
|
||||
"nonce": {lo.RandomString(43, lo.LettersCharset)},
|
||||
"state": {uuid.NewString()},
|
||||
"state": {uuid.New().String()},
|
||||
}
|
||||
|
||||
uri = uri + "&" + query.Encode()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue