Skip to content

Commit

Permalink
feat(errors): Process errors from Okta API (#11161)
Browse files Browse the repository at this point in the history
Closes #11149

BEGIN_COMMIT_OVERRIDE
feat(errors): Process errors from Okta API (#11161)

fix(backoff): Use 2 retries with minimum 30s of backoff interval (#11161)
END_COMMIT_OVERRIDE
  • Loading branch information
candiduslynx committed Jun 1, 2023
1 parent cf10659 commit 1f4fa5a
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 8 deletions.
17 changes: 17 additions & 0 deletions plugins/source/okta/client/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package client

import (
"errors"
"fmt"

"github.com/okta/okta-sdk-golang/v3/okta"
)

func ProcessOktaAPIError(err error) error {
var genericOpenAPIErr *okta.GenericOpenAPIError
if errors.As(err, &genericOpenAPIErr) {
return fmt.Errorf(`received error from Okta API: err: %s, body: %q model: %v`, genericOpenAPIErr.Error(), genericOpenAPIErr.Body(), genericOpenAPIErr.Model())
}

return err
}
4 changes: 2 additions & 2 deletions plugins/source/okta/client/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const (

func (s *Spec) setDefaults(logger *zerolog.Logger) {
const (
minRetries = int32(3)
minBackOff = 5 * time.Second
minRetries = int32(2)
minBackOff = 30 * time.Second
)

if s.RateLimit == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ func Applications() *schema.Table {
}
}

func fetchApplications(ctx context.Context, meta schema.ClientMeta, _ *schema.Resource, res chan<- any) error {
func fetchApplications(ctx context.Context, meta schema.ClientMeta, _ *schema.Resource, res chan<- any) (err error) {
defer func() {
err = client.ProcessOktaAPIError(err)
}()

cl := meta.(*client.Client)

req := cl.ApplicationApi.ListApplications(ctx).Limit(200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ func groupAssignments() *schema.Table {
}
}

func fetchGroupAssignments(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
func fetchGroupAssignments(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) (err error) {
defer func() {
err = client.ProcessOktaAPIError(err)
}()

cl := meta.(*client.Client)
app := parent.Item.(*okta.Application)

Expand Down
6 changes: 5 additions & 1 deletion plugins/source/okta/resources/services/applications/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ func users() *schema.Table {
}
}

func fetchUsers(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
func fetchUsers(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) (err error) {
defer func() {
err = client.ProcessOktaAPIError(err)
}()

cl := meta.(*client.Client)
app := parent.Item.(*okta.Application)

Expand Down
6 changes: 5 additions & 1 deletion plugins/source/okta/resources/services/groups/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ func Groups() *schema.Table {
}
}

func fetchGroups(ctx context.Context, meta schema.ClientMeta, _ *schema.Resource, res chan<- any) error {
func fetchGroups(ctx context.Context, meta schema.ClientMeta, _ *schema.Resource, res chan<- any) (err error) {
defer func() {
err = client.ProcessOktaAPIError(err)
}()

cl := meta.(*client.Client)

req := cl.GroupApi.ListGroups(ctx).Limit(200)
Expand Down
6 changes: 5 additions & 1 deletion plugins/source/okta/resources/services/groups/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ func users() *schema.Table {
}
}

func fetchUsers(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
func fetchUsers(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) (err error) {
defer func() {
err = client.ProcessOktaAPIError(err)
}()

cl := meta.(*client.Client)
grp := parent.Item.(okta.Group)

Expand Down
6 changes: 5 additions & 1 deletion plugins/source/okta/resources/services/users/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ func Users() *schema.Table {
}
}

func fetchUsers(ctx context.Context, meta schema.ClientMeta, _ *schema.Resource, res chan<- any) error {
func fetchUsers(ctx context.Context, meta schema.ClientMeta, _ *schema.Resource, res chan<- any) (err error) {
defer func() {
err = client.ProcessOktaAPIError(err)
}()

cl := meta.(*client.Client)

req := cl.UserApi.ListUsers(ctx).Limit(200)
Expand Down

0 comments on commit 1f4fa5a

Please sign in to comment.