Skip to content

Commit

Permalink
update settings to use the new env_var and deprecated_env_var
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoCaso committed Jul 3, 2023
1 parent 64307d0 commit 611ccb6
Show file tree
Hide file tree
Showing 60 changed files with 1,000 additions and 513 deletions.
53 changes: 25 additions & 28 deletions lib/datadog/appsec/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def self.add_settings!(base)
base.class_eval do
settings :appsec do
option :enabled do |o|
o.default { env_to_bool('DD_APPSEC_ENABLED', DEFAULT_APPSEC_ENABLED) }
o.setter do |v|
v ? true : false
o.env_var 'DD_APPSEC_ENABLED'
o.default DEFAULT_APPSEC_ENABLED
o.setter do |value|
val_to_bool(value)
end
o.lazy
end

define_method(:instrument) do |integration_name|
Expand All @@ -54,7 +54,8 @@ def self.add_settings!(base)
end

option :ruleset do |o|
o.default { ENV.fetch('DD_APPSEC_RULES', DEFAULT_APPSEC_RULESET) }
o.env_var 'DD_APPSEC_RULES'
o.default { DEFAULT_APPSEC_RULESET }
o.lazy
end

Expand All @@ -69,49 +70,46 @@ def self.add_settings!(base)
end

option :waf_timeout do |o|
o.default { ENV.fetch('DD_APPSEC_WAF_TIMEOUT', DEFAULT_APPSEC_WAF_TIMEOUT) } # us
o.env_var 'DD_APPSEC_WAF_TIMEOUT'
o.default { DEFAULT_APPSEC_WAF_TIMEOUT } # us
o.setter do |v|
Datadog::Core::Utils::Duration.call(v.to_s, base: :us)
end
o.lazy
end

option :waf_debug do |o|
o.default { env_to_bool('DD_APPSEC_WAF_DEBUG', DEFAULT_APPSEC_WAF_DEBUG) }
o.setter do |v|
v ? true : false
o.env_var 'DD_APPSEC_WAF_DEBUG'
o.default DEFAULT_APPSEC_WAF_DEBUG
o.setter do |value|
val_to_bool(value)
end
o.lazy
end

option :trace_rate_limit do |o|
o.default { env_to_int('DD_APPSEC_TRACE_RATE_LIMIT', DEFAULT_APPSEC_TRACE_RATE_LIMIT) } # trace/s
o.lazy
o.env_var 'DD_APPSEC_TRACE_RATE_LIMIT'
o.default DEFAULT_APPSEC_TRACE_RATE_LIMIT
o.setter do |value|
val_to_int(value)
end
end

option :obfuscator_key_regex do |o|
o.default { ENV.fetch('DD_APPSEC_OBFUSCATION_PARAMETER_KEY_REGEXP', DEFAULT_OBFUSCATOR_KEY_REGEX) }
o.env_var 'DD_APPSEC_OBFUSCATION_PARAMETER_KEY_REGEXP'
o.default { DEFAULT_OBFUSCATOR_KEY_REGEX }
o.lazy
end

option :obfuscator_value_regex do |o|
o.default do
ENV.fetch(
'DD_APPSEC_OBFUSCATION_PARAMETER_VALUE_REGEXP',
DEFAULT_OBFUSCATOR_VALUE_REGEX
)
end
o.env_var 'DD_APPSEC_OBFUSCATION_PARAMETER_VALUE_REGEXP'
o.default { DEFAULT_OBFUSCATOR_VALUE_REGEX }
o.lazy
end

settings :track_user_events do
option :enabled do |o|
o.default do
ENV.fetch(
'DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING',
DEFAULT_APPSEC_AUTOMATED_TRACK_USER_EVENTS_ENABLED
)
end
o.env_var 'DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING'
o.default { DEFAULT_APPSEC_AUTOMATED_TRACK_USER_EVENTS_ENABLED }
o.setter do |v|
if v
v.to_s != 'disabled'
Expand All @@ -123,9 +121,8 @@ def self.add_settings!(base)
end

option :mode do |o|
o.default do
ENV.fetch('DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING', DEFAULT_APPSEC_AUTOMATED_TRACK_USER_EVENTS_MODE)
end
o.env_var 'DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING'
o.default { DEFAULT_APPSEC_AUTOMATED_TRACK_USER_EVENTS_MODE }
o.setter do |v|
string_value = v.to_s
if APPSEC_VALID_TRACK_USER_EVENTS_MODE.include?(string_value)
Expand Down
7 changes: 5 additions & 2 deletions lib/datadog/ci/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ def self.add_settings!(base)
base.class_eval do
settings :ci do
option :enabled do |o|
o.default { env_to_bool(CI::Ext::Settings::ENV_MODE_ENABLED, false) }
o.lazy
o.env_var CI::Ext::Settings::ENV_MODE_ENABLED
o.default false
o.setter do |value|
val_to_bool(value)
end
end

# DEV: Alias to Datadog::Tracing::Contrib::Extensions::Configuration::Settings#instrument.
Expand Down
11 changes: 7 additions & 4 deletions lib/datadog/ci/contrib/cucumber/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ module Configuration
# TODO: mark as `@public_api` when GA
class Settings < Datadog::Tracing::Contrib::Configuration::Settings
option :enabled do |o|
o.default { env_to_bool(Ext::ENV_ENABLED, true) }
o.lazy
o.env_var Ext::ENV_ENABLED
o.default true
o.setter do |value|
val_to_bool(value)
end
end

option :service_name do |o|
Expand All @@ -22,8 +25,8 @@ class Settings < Datadog::Tracing::Contrib::Configuration::Settings
end

option :operation_name do |o|
o.default { ENV.key?(Ext::ENV_OPERATION_NAME) ? ENV[Ext::ENV_OPERATION_NAME] : Ext::OPERATION_NAME }
o.lazy
o.env_var Ext::ENV_OPERATION_NAME
o.default Ext::OPERATION_NAME
end
end
end
Expand Down
11 changes: 7 additions & 4 deletions lib/datadog/ci/contrib/rspec/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ module Configuration
# TODO: mark as `@public_api` when GA
class Settings < Datadog::Tracing::Contrib::Configuration::Settings
option :enabled do |o|
o.default { env_to_bool(Ext::ENV_ENABLED, true) }
o.lazy
o.env_var Ext::ENV_ENABLED
o.default true
o.setter do |value|
val_to_bool(value)
end
end

option :service_name do |o|
Expand All @@ -22,8 +25,8 @@ class Settings < Datadog::Tracing::Contrib::Configuration::Settings
end

option :operation_name do |o|
o.default { ENV.key?(Ext::ENV_OPERATION_NAME) ? ENV[Ext::ENV_OPERATION_NAME] : Ext::OPERATION_NAME }
o.lazy
o.env_var Ext::ENV_OPERATION_NAME
o.default ENV[Ext::OPERATION_NAME]
end
end
end
Expand Down
Loading

0 comments on commit 611ccb6

Please sign in to comment.