Skip to content

Commit

Permalink
after timeout, return any actionable errors to the user
Browse files Browse the repository at this point in the history
  • Loading branch information
cadenmarchese committed Oct 24, 2023
1 parent 20a2f25 commit 22dd349
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion pkg/util/steps/refreshing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"context"
"errors"
"fmt"
"net/http"
"time"

"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/util/azureerrors"
"github.com/Azure/ARO-RP/pkg/util/refreshable"
)
Expand Down Expand Up @@ -84,7 +86,23 @@ func (s *authorizationRefreshingActionStep) run(ctx context.Context, log *logrus
return true, err
}, timeoutCtx.Done())

return err
// After timeout, return any actionable errors to the user
switch err != nil {
case azureerrors.IsUnauthorizedClientError(err):
return s.servicePrincipalCloudError(
"The provided service principal application ID was not found in the tenant. Please ensure that the provided clientID and client secret are correct.",
)
case azureerrors.HasAuthorizationFailedError(err):
return s.servicePrincipalCloudError(
"Authorization using provided credentials failed. Please ensure that the provided clientID and client secret are correct.",
)
case azureerrors.IsInvalidSecretError(err):
return s.servicePrincipalCloudError(
"Invalid client secret provided. Please ensure that the provided clientID and client secret are correct.",
)
}

return nil
}

func (s *authorizationRefreshingActionStep) String() string {
Expand All @@ -94,3 +112,11 @@ func (s *authorizationRefreshingActionStep) String() string {
func (s *authorizationRefreshingActionStep) metricsName() string {
return fmt.Sprintf("authorizationretryingaction.%s", shortName(FriendlyName(s.f)))
}

func (s *authorizationRefreshingActionStep) servicePrincipalCloudError(message string) error {
return api.NewCloudError(
http.StatusBadRequest,
api.CloudErrorCodeInvalidServicePrincipalCredentials,
"properties.servicePrincipalProfile",
message)
}

0 comments on commit 22dd349

Please sign in to comment.