Skip to content

Commit

Permalink
remove context timeouts for okta
Browse files Browse the repository at this point in the history
  • Loading branch information
ssoroka committed Oct 9, 2021
1 parent 4ef6cfe commit cb0daa6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions internal/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func login(registry string, useCurrentConfig bool) error {

defer func() {
if err := lock.Unlock(); err != nil {
fmt.Fprintln(os.Stderr, "Failed to unlock login.")
fmt.Fprintf(os.Stderr, "Failed to unlock login. (%s)\n", lock.Path())
}
}()

Expand Down Expand Up @@ -300,7 +300,7 @@ func promptShouldSkipTLSVerify(host string, skipTLSVerify bool) (shouldSkipTLSVe

proceed := false

fmt.Fprintf(os.Stderr, "Could not verify certificate for host %s\n", termenv.String(host).Bold())
fmt.Fprintf(os.Stderr, "Could not verify certificate for host %q: %s\n", host, err)

prompt := &survey.Confirm{
Message: "Are you sure you want to continue?",
Expand Down
12 changes: 6 additions & 6 deletions internal/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ func Run(options Options) error {
timer.Start(5*time.Second, func() {
endpoint, err := k8s.Endpoint()
if err != nil {
logging.L.Error(err.Error())
logging.L.Error("endpoint: " + err.Error())
return
}

url, err := urlx.Parse(endpoint)
if err != nil {
logging.L.Error(err.Error())
logging.L.Error("url parse: " + err.Error())
return
}

Expand All @@ -319,7 +319,7 @@ func Run(options Options) error {
}
}

logging.L.Error(err.Error())
logging.L.Error("cache get: " + err.Error())
return
}

Expand All @@ -331,17 +331,17 @@ func Run(options Options) error {
},
}).Execute()
if err != nil {
logging.L.Error(err.Error())
logging.L.Error("Couldn't create destination: " + err.Error())
return
}

roles, _, err := client.RolesApi.ListRoles(ctx).DestinationId(destination.Id).Execute()
if err != nil {
logging.L.Error(err.Error())
logging.L.Error("couldn't list roles: " + err.Error())
}
err = k8s.UpdateRoles(roles)
if err != nil {
logging.L.Error(err.Error())
logging.L.Error("couldn't update roles: " + err.Error())
return
}
})
Expand Down
8 changes: 5 additions & 3 deletions internal/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,14 @@ func (k *Kubernetes) UpdateRoles(roles []api.Role) error {

err := k.updateRoleBindings(rbSubjects)
if err != nil {
return err
return fmt.Errorf("update role bindings: %w", err)
}

err = k.updateClusterRoleBindings(crbSubjects)
if err = k.updateClusterRoleBindings(crbSubjects); err != nil {
return fmt.Errorf("update cluster role bindings: %w", err)
}

return err
return nil
}

func (k *Kubernetes) ec2ClusterName() (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/registry/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,12 @@ func (s *Source) SyncUsers(db *gorm.DB, k8s *kubernetes.Kubernetes, okta Okta) e
case "okta":
apiToken, err := k8s.GetSecret(s.ApiToken)
if err != nil {
return err
return fmt.Errorf("fetching k8s secret: %w", err)
}

emails, err = okta.Emails(s.Domain, s.ClientId, apiToken)
if err != nil {
return err
return fmt.Errorf("fetching okta emails: %w", err)
}
default:
return nil
Expand Down
6 changes: 3 additions & 3 deletions internal/registry/okta.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ func NewOkta() Okta {

// ValidateOktaConnection requests the client from Okta to check for errors on the response
func (o *oktaImplementation) ValidateOktaConnection(domain string, clientID string, apiToken string) error {
_, _, err := okta.NewClient(context.TODO(), okta.WithOrgUrl("https://"+domain), okta.WithRequestTimeout(30), okta.WithRateLimitMaxRetries(3), okta.WithToken(apiToken))
_, _, err := okta.NewClient(context.TODO(), okta.WithOrgUrl("https://"+domain), okta.WithRequestTimeout(30), okta.WithRateLimitMaxRetries(1), okta.WithToken(apiToken))
return err
}

func (o *oktaImplementation) Emails(domain string, clientID string, apiToken string) ([]string, error) {
ctx, client, err := okta.NewClient(context.TODO(), okta.WithOrgUrl("https://"+domain), okta.WithRequestTimeout(30), okta.WithRateLimitMaxRetries(3), okta.WithToken(apiToken))
ctx, client, err := okta.NewClient(context.TODO(), okta.WithOrgUrl("https://"+domain), okta.WithToken(apiToken))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -71,7 +71,7 @@ func (o *oktaImplementation) Emails(domain string, clientID string, apiToken str

// Groups retrieves groups that exist in Okta for the configured InfraHQ group-role mappings and returns a map of group names to user lists
func (o *oktaImplementation) Groups(domain string, clientID string, apiToken string) (map[string][]string, error) {
ctx, client, err := okta.NewClient(context.TODO(), okta.WithOrgUrl("https://"+domain), okta.WithRequestTimeout(30), okta.WithRateLimitMaxRetries(3), okta.WithToken(apiToken))
ctx, client, err := okta.NewClient(context.TODO(), okta.WithOrgUrl("https://"+domain), okta.WithToken(apiToken))
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions internal/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func Run(options Options) error {
}

// schedule the user and group sync jobs
interval := 30 * time.Second
interval := 60 * time.Second
if options.SyncInterval > 0 {
interval = time.Duration(options.SyncInterval) * time.Second
} else {
Expand All @@ -124,11 +124,11 @@ func Run(options Options) error {
for _, s := range sources {
err = s.SyncUsers(db, k8s, okta)
if err != nil {
zapLogger.Error(err.Error())
zapLogger.Error("could not sync users: " + err.Error())
}
err = s.SyncGroups(db, k8s, okta)
if err != nil {
zapLogger.Error(err.Error())
zapLogger.Error("could not sync groups: " + err.Error())
}
}
})
Expand Down
4 changes: 4 additions & 0 deletions internal/timer/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ func NewTimer() *Timer {
}
}

// Start calls sync() every interval. if sync() runs long,
// the next interval will not be started until it completes.
// if intervals are missed they will be skipped, so sync() is
// free to run as long as it needs to
func (t *Timer) Start(interval time.Duration, sync func()) {
ticker := time.NewTicker(interval)

Expand Down

0 comments on commit cb0daa6

Please sign in to comment.