From 84c2c5826a25629bf9a912ecb80bc1c807d6feb1 Mon Sep 17 00:00:00 2001 From: Geoff Greer Date: Thu, 29 Aug 2024 14:16:55 -0700 Subject: [PATCH 1/2] Add response cache options to okta connector. Default to on. --- cmd/baton-okta/config.go | 17 +++++++++++++++-- cmd/baton-okta/main.go | 3 +++ pkg/connector/connector.go | 11 +++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/cmd/baton-okta/config.go b/cmd/baton-okta/config.go index b577cb6f..502ad7ed 100644 --- a/cmd/baton-okta/config.go +++ b/cmd/baton-okta/config.go @@ -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{ @@ -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...) diff --git a/cmd/baton-okta/main.go b/cmd/baton-okta/main.go index a19cc7ac..a86d4583 100644 --- a/cmd/baton-okta/main.go +++ b/cmd/baton-okta/main.go @@ -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) diff --git a/pkg/connector/connector.go b/pkg/connector/connector.go index 406f3415..e782ce78 100644 --- a/pkg/connector/connector.go +++ b/pkg/connector/connector.go @@ -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 { @@ -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 @@ -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 From cf72e94fd618c5144494f914d6613b6ec0e875df Mon Sep 17 00:00:00 2001 From: Geoff Greer Date: Thu, 29 Aug 2024 14:36:10 -0700 Subject: [PATCH 2/2] Fix lint --- cmd/baton-okta/config.go | 8 ++++---- cmd/baton-okta/main.go | 4 ++-- pkg/connector/connector.go | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/baton-okta/config.go b/cmd/baton-okta/config.go index 502ad7ed..23f2c11c 100644 --- a/cmd/baton-okta/config.go +++ b/cmd/baton-okta/config.go @@ -16,8 +16,8 @@ var ( 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)) + 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{ @@ -37,6 +37,6 @@ var configuration = field.NewConfiguration([]field.SchemaField{ ciam, ciamEmailDomains, cache, - cacheTti, - cacheTtl, + cacheTTI, + cacheTTL, }, relationships...) diff --git a/cmd/baton-okta/main.go b/cmd/baton-okta/main.go index a86d4583..17c3f537 100644 --- a/cmd/baton-okta/main.go +++ b/cmd/baton-okta/main.go @@ -49,8 +49,8 @@ func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, e Ciam: v.GetBool("ciam"), CiamEmailDomains: v.GetStringSlice("ciam-email-domains"), Cache: v.GetBool("cache"), - CacheTti: v.GetInt32("cache-tti"), - CacheTtl: v.GetInt32("cache-ttl"), + CacheTTI: v.GetInt32("cache-tti"), + CacheTTL: v.GetInt32("cache-ttl"), } cb, err := connector.New(ctx, ccfg) diff --git a/pkg/connector/connector.go b/pkg/connector/connector.go index e782ce78..32a70124 100644 --- a/pkg/connector/connector.go +++ b/pkg/connector/connector.go @@ -38,8 +38,8 @@ type Config struct { Ciam bool CiamEmailDomains []string Cache bool - CacheTti int32 - CacheTtl int32 + CacheTTI int32 + CacheTTL int32 } func v1AnnotationsForResourceType(resourceTypeID string, skipEntitlementsAndGrants bool) annotations.Annotations { @@ -181,8 +181,8 @@ func New(ctx context.Context, cfg *Config) (*Okta, error) { okta.WithToken(cfg.ApiToken), okta.WithHttpClientPtr(client), okta.WithCache(cfg.Cache), - okta.WithCacheTti(cfg.CacheTti), - okta.WithCacheTtl(cfg.CacheTtl), + okta.WithCacheTti(cfg.CacheTTI), + okta.WithCacheTtl(cfg.CacheTTL), ) if err != nil { return nil, err @@ -201,8 +201,8 @@ func New(ctx context.Context, cfg *Config) (*Okta, error) { okta.WithPrivateKey(cfg.OktaPrivateKey), okta.WithPrivateKeyId(cfg.OktaPrivateKeyId), okta.WithCache(cfg.Cache), - okta.WithCacheTti(cfg.CacheTti), - okta.WithCacheTtl(cfg.CacheTtl), + okta.WithCacheTti(cfg.CacheTTI), + okta.WithCacheTtl(cfg.CacheTTL), ) if err != nil { return nil, err