Skip to content

Commit

Permalink
fixup: Avoid redundant talk with the contracts server
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardGomezEscandell committed Nov 16, 2023
1 parent 7f07bf2 commit a1f5c15
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions windows-agent/internal/contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,24 @@ func ValidSubscription(args ...Option) (bool, error) {
}

expiration, err := opts.microsoftStore.GetSubscriptionExpirationDate()
if isErrNotSubscribed(err) {
return false, nil
}
if err != nil {
var target microsoftstore.StoreAPIError
if errors.As(err, &target) {
if target == microsoftstore.ErrNotSubscribed {
// ValidSubscription -> false because we are not subscribed
return false, nil
}
}

return false, fmt.Errorf("could not get subscription expiration date: %v", err)
}

if expiration.Before(time.Now()) {
// ValidSubscription -> false because the subscription is expired
return false, nil
}

// ValidSubscription -> true because the subscription is not yet expired
return true, nil
}

Expand Down Expand Up @@ -117,20 +124,3 @@ func NewProToken(ctx context.Context, args ...Option) (token string, err error)

return proToken, nil
}

func isErrNotSubscribed(err error) bool {
if err == nil {
return false
}

var target microsoftstore.StoreAPIError
if !errors.As(err, &target) {
return false
}

if target != microsoftstore.ErrNotSubscribed {
return false
}

return true
}

0 comments on commit a1f5c15

Please sign in to comment.