Skip to content

Commit

Permalink
Add response cache options to okta connector. Default to on. (#41)
Browse files Browse the repository at this point in the history
* Add response cache options to okta connector. Default to on.

* Fix lint
  • Loading branch information
ggreer authored Sep 3, 2024
1 parent 2955b98 commit 58f30b9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
17 changes: 15 additions & 2 deletions cmd/baton-okta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ var (
ciam = field.BoolField("ciam", field.WithDescription("Whether to run in CIAM mode or not. In CIAM mode, only roles and the users assigned to roles are synced"))
ciamEmailDomains = field.StringSliceField("ciam-email-domains",
field.WithDescription("The email domains to use for CIAM mode. Any users that don't have an email address with one of the provided domains will be ignored, unless explicitly granted a role"))
cache = field.BoolField("cache", field.WithDescription("Enable response cache"), field.WithDefaultValue(true))
cacheTTI = field.IntField("cache-tti", field.WithDescription("Response cache cleanup interval in seconds"), field.WithDefaultValue(60))
cacheTTL = field.IntField("cache-ttl", field.WithDescription("Response cache time to live in seconds"), field.WithDefaultValue(300))
)

var relationships = []field.SchemaFieldRelationship{
Expand All @@ -24,6 +27,16 @@ var relationships = []field.SchemaFieldRelationship{
}

var configuration = field.NewConfiguration([]field.SchemaField{
domain, apiToken, oktaClientId, oktaPrivateKey, oktaPrivateKeyId,
syncInactivateApps, oktaProvisioning, ciam, ciamEmailDomains,
domain,
apiToken,
oktaClientId,
oktaPrivateKey,
oktaPrivateKeyId,
syncInactivateApps,
oktaProvisioning,
ciam,
ciamEmailDomains,
cache,
cacheTTI,
cacheTTL,
}, relationships...)
3 changes: 3 additions & 0 deletions cmd/baton-okta/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, e
OktaProvisioning: v.GetBool("okta-provisioning"),
Ciam: v.GetBool("ciam"),
CiamEmailDomains: v.GetStringSlice("ciam-email-domains"),
Cache: v.GetBool("cache"),
CacheTTI: v.GetInt32("cache-tti"),
CacheTTL: v.GetInt32("cache-ttl"),
}

cb, err := connector.New(ctx, ccfg)
Expand Down
11 changes: 9 additions & 2 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type Config struct {
OktaProvisioning bool
Ciam bool
CiamEmailDomains []string
Cache bool
CacheTTI int32
CacheTTL int32
}

func v1AnnotationsForResourceType(resourceTypeID string, skipEntitlementsAndGrants bool) annotations.Annotations {
Expand Down Expand Up @@ -177,7 +180,9 @@ func New(ctx context.Context, cfg *Config) (*Okta, error) {
okta.WithOrgUrl(fmt.Sprintf("https://%s", cfg.Domain)),
okta.WithToken(cfg.ApiToken),
okta.WithHttpClientPtr(client),
okta.WithCache(false),
okta.WithCache(cfg.Cache),
okta.WithCacheTti(cfg.CacheTTI),
okta.WithCacheTtl(cfg.CacheTTL),
)
if err != nil {
return nil, err
Expand All @@ -195,7 +200,9 @@ func New(ctx context.Context, cfg *Config) (*Okta, error) {
okta.WithScopes(scopes),
okta.WithPrivateKey(cfg.OktaPrivateKey),
okta.WithPrivateKeyId(cfg.OktaPrivateKeyId),
okta.WithCache(false),
okta.WithCache(cfg.Cache),
okta.WithCacheTti(cfg.CacheTTI),
okta.WithCacheTtl(cfg.CacheTTL),
)
if err != nil {
return nil, err
Expand Down

0 comments on commit 58f30b9

Please sign in to comment.