Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .generator/templates/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,9 @@ func (c *APIClient) do(ctx context.Context, req *http.Request) (*http.Response,
c.rateLimitLock.Lock()
limit := c.rateLimit
c.rateLimitLock.Unlock()
if limit != nil && limit.Remaining <= 0 {
timer := time.NewTimer(time.Second * time.Duration(limit.Reset))
// If the remaining requests are less than the threshold percentage of the limit, wait for the max backoff
if limit != nil && limit.Remaining <= limit.Limit-int(c.cfg.Okta.Client.RateLimit.Threshold)*limit.Limit/100 { // less than threshold
timer := time.NewTimer(time.Second * time.Duration(c.cfg.Okta.Client.RateLimit.MaxBackoff))
select {
case <-ctx.Done():
if !timer.Stop() {
Expand Down
7 changes: 7 additions & 0 deletions .generator/templates/configuration.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ type Configuration struct {
MaxRetries int32 `yaml:"maxRetries" envconfig:"OKTA_CLIENT_RATE_LIMIT_MAX_RETRIES"`
MaxBackoff int64 `yaml:"maxBackoff" envconfig:"OKTA_CLIENT_RATE_LIMIT_MAX_BACKOFF"`
Enable bool `yaml:"enable" envconfig:"OKTA_CLIENT_RATE_LIMIT_ENABLE"`
Threshold int32 `yaml:"threshold" envconfig:"OKTA_CLIENT_RATE_LIMIT_THRESHOLD"`
} `yaml:"rateLimit"`
OrgUrl string `yaml:"orgUrl" envconfig:"OKTA_CLIENT_ORGURL"`
Token string `yaml:"token" envconfig:"OKTA_CLIENT_TOKEN"`
Expand Down Expand Up @@ -551,6 +552,12 @@ func WithRateLimitMaxBackOff(maxBackoff int64) ConfigSetter {
}
}

func WithRateLimitThreshold(threshold int32) ConfigSetter {
return func(c *Configuration) {
c.Okta.Client.RateLimit.Threshold = threshold
}
}

func WithAuthorizationMode(authzMode string) ConfigSetter {
return func(c *Configuration) {
c.Okta.Client.AuthorizationMode = authzMode
Expand Down
5 changes: 3 additions & 2 deletions okta/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1328,8 +1328,9 @@ func (c *APIClient) do(ctx context.Context, req *http.Request) (*http.Response,
c.rateLimitLock.Lock()
limit := c.rateLimit
c.rateLimitLock.Unlock()
if limit != nil && limit.Remaining <= 0 {
timer := time.NewTimer(time.Second * time.Duration(limit.Reset))
// If the remaining requests are less than the threshold percentage of the limit, wait for the MaxBackoff
if limit != nil && limit.Remaining <= limit.Limit-int(c.cfg.Okta.Client.RateLimit.Threshold)*limit.Limit/100 { // less than threshold
timer := time.NewTimer(time.Second * time.Duration(c.cfg.Okta.Client.RateLimit.MaxBackoff))
select {
case <-ctx.Done():
if !timer.Stop() {
Expand Down
7 changes: 7 additions & 0 deletions okta/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ type Configuration struct {
MaxRetries int32 `yaml:"maxRetries" envconfig:"OKTA_CLIENT_RATE_LIMIT_MAX_RETRIES"`
MaxBackoff int64 `yaml:"maxBackoff" envconfig:"OKTA_CLIENT_RATE_LIMIT_MAX_BACKOFF"`
Enable bool `yaml:"enable" envconfig:"OKTA_CLIENT_RATE_LIMIT_ENABLE"`
Threshold int32 `yaml:"threshold" envconfig:"OKTA_CLIENT_RATE_LIMIT_THRESHOLD"`
} `yaml:"rateLimit"`
OrgUrl string `yaml:"orgUrl" envconfig:"OKTA_CLIENT_ORGURL"`
Token string `yaml:"token" envconfig:"OKTA_CLIENT_TOKEN"`
Expand Down Expand Up @@ -485,6 +486,12 @@ func WithRateLimitMaxBackOff(maxBackoff int64) ConfigSetter {
}
}

func WithRateLimitThreshold(threshold int32) ConfigSetter {
return func(c *Configuration) {
c.Okta.Client.RateLimit.Threshold = threshold
}
}

func WithAuthorizationMode(authzMode string) ConfigSetter {
return func(c *Configuration) {
c.Okta.Client.AuthorizationMode = authzMode
Expand Down
26 changes: 17 additions & 9 deletions okta/model_policy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.