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 10, 2023
1 parent e4ea049 commit f2dfac5
Show file tree
Hide file tree
Showing 60 changed files with 1,034 additions and 328 deletions.
58 changes: 33 additions & 25 deletions lib/datadog/appsec/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ 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
end

Expand All @@ -53,69 +54,75 @@ 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

option :ip_denylist do |o|
o.default { [] }
o.lazy
end

option :user_id_denylist do |o|
o.default { [] }
o.lazy
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
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.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'
else
false
end
end
o.lazy
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 All @@ -129,6 +136,7 @@ def self.add_settings!(base)
DEFAULT_APPSEC_AUTOMATED_TRACK_USER_EVENTS_MODE
end
end
o.lazy
end
end
end
Expand Down
8 changes: 7 additions & 1 deletion lib/datadog/ci/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +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.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 All @@ -36,10 +40,12 @@ def self.add_settings!(base)

option :trace_flush do |o|
o.default { nil }
o.lazy
end

option :writer_options do |o|
o.default { {} }
o.lazy
end
end
end
Expand Down
10 changes: 8 additions & 2 deletions lib/datadog/ci/contrib/cucumber/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ 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.env_var Ext::ENV_ENABLED
o.default true
o.setter do |value|
val_to_bool(value)
end
end

option :service_name do |o|
o.default { Datadog.configuration.service_without_fallback || Ext::SERVICE_NAME }
o.lazy
end

option :operation_name do |o|
o.default { ENV.fetch(Ext::ENV_OPERATION_NAME, Ext::OPERATION_NAME) }
o.env_var Ext::ENV_OPERATION_NAME
o.default Ext::OPERATION_NAME
end
end
end
Expand Down
10 changes: 8 additions & 2 deletions lib/datadog/ci/contrib/rspec/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ 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.env_var Ext::ENV_ENABLED
o.default true
o.setter do |value|
val_to_bool(value)
end
end

option :service_name do |o|
o.default { Datadog.configuration.service_without_fallback || Ext::SERVICE_NAME }
o.lazy
end

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

0 comments on commit f2dfac5

Please sign in to comment.