From 89ff51c30b9fa63304b4d047eb134f976a60ae52 Mon Sep 17 00:00:00 2001 From: Edoardo Rosa <6991986+notdodo@users.noreply.github.com> Date: Sat, 10 Feb 2024 14:19:31 +0100 Subject: [PATCH] fix: ListUsers (#39) --- pkg/infra/okta/okta_client.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/infra/okta/okta_client.go b/pkg/infra/okta/okta_client.go index bad1e90..8875644 100644 --- a/pkg/infra/okta/okta_client.go +++ b/pkg/infra/okta/okta_client.go @@ -22,11 +22,12 @@ type OktaClient interface { type oktaClient struct { oktaClient *okta.Client log logging.LogManager + ctx context.Context } func NewOktaClient(orgUrl, apiKey string) OktaClient { logger := logging.GetLogManager() - _, client, err := okta.NewClient(context.TODO(), okta.WithOrgUrl(fmt.Sprintf("https://%s", orgUrl)), okta.WithToken(apiKey)) + ctx, client, err := okta.NewClient(context.TODO(), okta.WithOrgUrl(fmt.Sprintf("https://%s", orgUrl)), okta.WithToken(apiKey)) if err != nil { logger.Error("Invalid Okta login", "err", err) } @@ -34,31 +35,30 @@ func NewOktaClient(orgUrl, apiKey string) OktaClient { return &oktaClient{ oktaClient: client, log: logger, + ctx: ctx, } } func (c *oktaClient) Users() ([]*okta.User, error) { c.log.Info("Getting Okta users") var users []*okta.User - appendUsers := func(oktaUsers []*okta.User) { - users = append(users, oktaUsers...) - } oktaUsers, response, err := c.oktaClient.User.ListUsers(context.TODO(), nil) if err != nil { return nil, err } - appendUsers(oktaUsers) + users = append(users, oktaUsers...) for response.HasNextPage() { + var oktaUsers []*okta.User response, err = response.Next(context.TODO(), &oktaUsers) if err != nil { return nil, err } - appendUsers(oktaUsers) + users = append(users, oktaUsers...) } c.log.Info(fmt.Sprintf("Found %d users", len(users))) - c.log.Debug(fmt.Sprintf("Found %d users", len(users)), "users", response.Body) + c.log.Debug(fmt.Sprintf("Found %d users", len(users)), "users", users) return users, nil }