Sponsor: wait for network to settle during startup check [0.313 backport] (#32557)
Some checks failed
Some checks failed
This commit is contained in:
parent
4ca64eaf49
commit
5b4b4a333c
2 changed files with 9 additions and 5 deletions
|
|
@ -30,6 +30,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/util/cloud"
|
"github.com/evcc-io/evcc/util/cloud"
|
||||||
"github.com/evcc-io/evcc/util/machine"
|
"github.com/evcc-io/evcc/util/machine"
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
|
@ -46,6 +47,9 @@ func machineID() string {
|
||||||
|
|
||||||
const unavailable = "sponsorship unavailable"
|
const unavailable = "sponsorship unavailable"
|
||||||
|
|
||||||
|
// startupTimeout leaves the network time to settle at boot; grpc retries dialing with backoff until deadline
|
||||||
|
const startupTimeout = 30 * time.Second
|
||||||
|
|
||||||
func IsAuthorized() bool {
|
func IsAuthorized() bool {
|
||||||
mu.RLock()
|
mu.RLock()
|
||||||
defer mu.RUnlock()
|
defer mu.RUnlock()
|
||||||
|
|
@ -98,10 +102,10 @@ func ConfigureSponsorship(token string) error {
|
||||||
|
|
||||||
client := pb.NewAuthClient(conn)
|
client := pb.NewAuthClient(conn)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), startupTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
res, err := client.IsAuthorized(ctx, &pb.AuthRequest{Token: token, MachineId: machineID()})
|
res, err := client.IsAuthorized(ctx, &pb.AuthRequest{Token: token, MachineId: machineID()}, grpc.WaitForReady(true))
|
||||||
if err == nil && res.Authorized {
|
if err == nil && res.Authorized {
|
||||||
Subject = res.Subject
|
Subject = res.Subject
|
||||||
ExpiresAt = res.ExpiresAt.AsTime()
|
ExpiresAt = res.ExpiresAt.AsTime()
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api/proto/pb"
|
"github.com/evcc-io/evcc/api/proto/pb"
|
||||||
"github.com/evcc-io/evcc/util/cloud"
|
"github.com/evcc-io/evcc/util/cloud"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
|
@ -34,7 +34,7 @@ func checkHardware(vendor string, metadata map[string]string) string {
|
||||||
return unavailable
|
return unavailable
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), request.Timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), startupTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
client := pb.NewAuthClient(conn)
|
client := pb.NewAuthClient(conn)
|
||||||
|
|
@ -42,7 +42,7 @@ func checkHardware(vendor string, metadata map[string]string) string {
|
||||||
MachineId: machineID(),
|
MachineId: machineID(),
|
||||||
Vendor: vendor,
|
Vendor: vendor,
|
||||||
Metadata: metadata,
|
Metadata: metadata,
|
||||||
})
|
}, grpc.WaitForReady(true))
|
||||||
|
|
||||||
if err == nil && res.Authorized {
|
if err == nil && res.Authorized {
|
||||||
return res.Subject
|
return res.Subject
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue