Telemetry: avoid errors when authorization failed for technical reasons (#9803)

This commit is contained in:
andig 2023-09-09 12:52:05 +02:00 • committed by GitHub
parent 68ec274c00
commit 422922940b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -17,10 +17,16 @@ var (
ExpiresAt time.Time
)
const unavailable = "sponsorship unavailable"
func IsAuthorized() bool {
return len(Subject) > 0
}
func IsAuthorizedForApi() bool {
return IsAuthorized() && Subject != unavailable
}
// check and set sponsorship token
func ConfigureSponsorship(token string) error {
host := util.Getenv("GRPC_URI", cloud.Host)
@ -43,7 +49,7 @@ func ConfigureSponsorship(token string) error {
if err != nil {
if s, ok := status.FromError(err); ok && s.Code() != codes.Unknown {
Subject = "sponsorship unavailable"
Subject = unavailable
err = nil
} else {
err = fmt.Errorf("sponsortoken: %w", err)

View file

@ -30,7 +30,7 @@ var (
func Enabled() bool {
enabled, _ := settings.Bool(enabledSetting)
return enabled && sponsor.IsAuthorized() && instanceID != ""
return enabled && sponsor.IsAuthorizedForApi() && instanceID != ""
}
func Enable(enable bool) error {