Class: PactBroker::Configuration
- Inherits:
-
Object
- Object
- PactBroker::Configuration
- Extended by:
- Forwardable
- Defined in:
- lib/pact_broker/configuration.rb
Instance Attribute Summary collapse
-
#api_error_reporters ⇒ Object
Returns the value of attribute api_error_reporters.
-
#content_security_policy ⇒ Object
Returns the value of attribute content_security_policy.
-
#custom_logger ⇒ Object
readonly
Returns the value of attribute custom_logger.
-
#database_connection ⇒ Object
Returns the value of attribute database_connection.
-
#example_data_seeder ⇒ Object
Returns the value of attribute example_data_seeder.
-
#hal_browser_content_security_policy_overrides ⇒ Object
Returns the value of attribute hal_browser_content_security_policy_overrides.
-
#html_pact_renderer ⇒ Object
Returns the value of attribute html_pact_renderer.
-
#policy_builder ⇒ Object
Returns the value of attribute policy_builder.
-
#policy_scope_builder ⇒ Object
Returns the value of attribute policy_scope_builder.
-
#runtime_configuration ⇒ Object
Returns the value of attribute runtime_configuration.
-
#sha_generator ⇒ Object
Returns the value of attribute sha_generator.
-
#version_parser ⇒ Object
Returns the value of attribute version_parser.
Class Method Summary collapse
Instance Method Summary collapse
- #add_api_error_reporter(&block) ⇒ Object
- #after_resource(&block) ⇒ Object
- #authenticate(&block) ⇒ Object
- #authenticate_with_basic_auth(&block) ⇒ Object
- #authentication_configured? ⇒ Boolean
- #authorization_configured? ⇒ Boolean
- #authorize(&block) ⇒ Object
- #before_resource(&block) ⇒ Object
-
#default_wip_window_days ⇒ Object
Default WIP window (days) used when dynamic calculation fails or no unverified pacts exist.
- #dynamic_wip_window_enabled? ⇒ Boolean
- #enable_badge_resources=(enable_badge_resources) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #load_from_database! ⇒ Object
- #log_configuration ⇒ Object
- #logger ⇒ Object
- #logger=(logger) ⇒ Object
- #logger_from_runtime_configuration ⇒ Object
-
#max_wip_lookback_days ⇒ Object
Maximum lookback window (days) to query for unverified pacts.
-
#min_wip_window_days ⇒ Object
Minimum WIP window (days) to ensure recent pacts are always included, even if P80 is very low.
- #override_runtime_configuration!(overrides) ⇒ Object
- #show_backtrace_in_error_response? ⇒ Boolean
- #show_webhook_response? ⇒ Boolean
-
#verified_by_other_branch_before_this_branch_look_back ⇒ Object
Lookback window (days) for checking if a pact was verified by another branch before this branch was created.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
42 43 44 45 46 47 48 49 |
# File 'lib/pact_broker/configuration.rb', line 42 def initialize @runtime_configuration = PactBroker::Config::RuntimeConfiguration.new @before_resource_hook = ->(resource){} @after_resource_hook = ->(resource){} @authenticate_with_basic_auth = nil @authorize = nil @api_error_reporters = [] end |
Instance Attribute Details
#api_error_reporters ⇒ Object
Returns the value of attribute api_error_reporters.
34 35 36 |
# File 'lib/pact_broker/configuration.rb', line 34 def api_error_reporters @api_error_reporters end |
#content_security_policy ⇒ Object
Returns the value of attribute content_security_policy.
33 34 35 |
# File 'lib/pact_broker/configuration.rb', line 33 def content_security_policy @content_security_policy end |
#custom_logger ⇒ Object (readonly)
Returns the value of attribute custom_logger.
35 36 37 |
# File 'lib/pact_broker/configuration.rb', line 35 def custom_logger @custom_logger end |
#database_connection ⇒ Object
Returns the value of attribute database_connection.
30 31 32 |
# File 'lib/pact_broker/configuration.rb', line 30 def database_connection @database_connection end |
#example_data_seeder ⇒ Object
Returns the value of attribute example_data_seeder.
31 32 33 |
# File 'lib/pact_broker/configuration.rb', line 31 def example_data_seeder @example_data_seeder end |
#hal_browser_content_security_policy_overrides ⇒ Object
Returns the value of attribute hal_browser_content_security_policy_overrides.
33 34 35 |
# File 'lib/pact_broker/configuration.rb', line 33 def hal_browser_content_security_policy_overrides @hal_browser_content_security_policy_overrides end |
#html_pact_renderer ⇒ Object
Returns the value of attribute html_pact_renderer.
32 33 34 |
# File 'lib/pact_broker/configuration.rb', line 32 def html_pact_renderer @html_pact_renderer end |
#policy_builder ⇒ Object
Returns the value of attribute policy_builder.
36 37 38 |
# File 'lib/pact_broker/configuration.rb', line 36 def policy_builder @policy_builder end |
#policy_scope_builder ⇒ Object
Returns the value of attribute policy_scope_builder.
36 37 38 |
# File 'lib/pact_broker/configuration.rb', line 36 def policy_scope_builder @policy_scope_builder end |
#runtime_configuration ⇒ Object
Returns the value of attribute runtime_configuration.
40 41 42 |
# File 'lib/pact_broker/configuration.rb', line 40 def runtime_configuration @runtime_configuration end |
#sha_generator ⇒ Object
Returns the value of attribute sha_generator.
32 33 34 |
# File 'lib/pact_broker/configuration.rb', line 32 def sha_generator @sha_generator end |
#version_parser ⇒ Object
Returns the value of attribute version_parser.
32 33 34 |
# File 'lib/pact_broker/configuration.rb', line 32 def version_parser @version_parser end |
Class Method Details
.default_configuration ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/pact_broker/configuration.rb', line 51 def self.default_configuration require "pact_broker/versions/parse_semantic_version" require "pact_broker/pacts/generate_sha" config = Configuration.new config.html_pact_renderer = default_html_pact_render config.version_parser = PactBroker::Versions::ParseSemanticVersion config.sha_generator = PactBroker::Pacts::GenerateSha config.example_data_seeder = lambda do # Do the require in the lambda, not at the top of the file, because we need # the database connection to be made before loading any Sequel::Model classes. require "pact_broker/db/seed_example_data" PactBroker::DB::SeedExampleData.call end # TODO get rid of unsafe-inline config.content_security_policy = { script_src: "'self' 'unsafe-inline'", style_src: "'self' 'unsafe-inline'", img_src: "'self' data: #{URI(config.shields_io_base_url).host}", font_src: "'self' data:", base_uri: "'self'", frame_src: "'self'", frame_ancestors: "'self'" } config.hal_browser_content_security_policy_overrides = { script_src: "'self' 'unsafe-inline' 'unsafe-eval'", frame_ancestors: "'self'" } config.policy_builder = -> (object) { DefaultPolicy.new(nil, object) } config.policy_scope_builder = -> (scope) { scope } config end |
.default_html_pact_render ⇒ Object
144 145 146 147 148 149 |
# File 'lib/pact_broker/configuration.rb', line 144 def self.default_html_pact_render lambda { |pact, | require "pact_broker/api/renderers/html_pact_renderer" PactBroker::Api::Renderers::HtmlPactRenderer.call pact, } end |
Instance Method Details
#add_api_error_reporter(&block) ⇒ Object
203 204 205 206 207 208 209 210 211 |
# File 'lib/pact_broker/configuration.rb', line 203 def add_api_error_reporter &block if block_given? unless block.arity == 2 raise ConfigurationError.new("api_error_notfifier block must accept two arguments, 'error' and 'options'") end @api_error_reporters << block nil end end |
#after_resource(&block) ⇒ Object
195 196 197 198 199 200 201 |
# File 'lib/pact_broker/configuration.rb', line 195 def after_resource &block if block_given? @after_resource_hook = block else @after_resource_hook end end |
#authenticate(&block) ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/pact_broker/configuration.rb', line 159 def authenticate &block if block_given? @authenticate = block else @authenticate end end |
#authenticate_with_basic_auth(&block) ⇒ Object
167 168 169 170 171 172 173 |
# File 'lib/pact_broker/configuration.rb', line 167 def authenticate_with_basic_auth &block if block_given? @authenticate_with_basic_auth = block else @authenticate_with_basic_auth end end |
#authentication_configured? ⇒ Boolean
155 156 157 |
# File 'lib/pact_broker/configuration.rb', line 155 def authentication_configured? !!authenticate || !!authenticate_with_basic_auth end |
#authorization_configured? ⇒ Boolean
175 176 177 |
# File 'lib/pact_broker/configuration.rb', line 175 def !! end |
#authorize(&block) ⇒ Object
179 180 181 182 183 184 185 |
# File 'lib/pact_broker/configuration.rb', line 179 def &block if block_given? @authorize = block else @authorize end end |
#before_resource(&block) ⇒ Object
187 188 189 190 191 192 193 |
# File 'lib/pact_broker/configuration.rb', line 187 def before_resource &block if block_given? @before_resource_hook = block else @before_resource_hook end end |
#default_wip_window_days ⇒ Object
Default WIP window (days) used when dynamic calculation fails or no unverified pacts exist.
239 240 241 |
# File 'lib/pact_broker/configuration.rb', line 239 def default_wip_window_days ENV["PACT_BROKER_DEFAULT_WIP_WINDOW_DAYS"]&.to_i || 7 end |
#dynamic_wip_window_enabled? ⇒ Boolean
217 218 219 |
# File 'lib/pact_broker/configuration.rb', line 217 def dynamic_wip_window_enabled? ENV["PACT_BROKER_DYNAMIC_WIP_WINDOW"]&.downcase == "true" end |
#enable_badge_resources=(enable_badge_resources) ⇒ Object
243 244 245 246 |
# File 'lib/pact_broker/configuration.rb', line 243 def enable_badge_resources= enable_badge_resources puts "Pact Broker configuration property `enable_badge_resources` is deprecated. Please use `enable_public_badge_access`" self.enable_public_badge_access = enable_badge_resources end |
#load_from_database! ⇒ Object
248 249 250 251 252 |
# File 'lib/pact_broker/configuration.rb', line 248 def load_from_database! # Can't require a Sequel::Model class before the connection has been set require "pact_broker/config/load" PactBroker::Config::Load.call(runtime_configuration) end |
#log_configuration ⇒ Object
137 138 139 140 141 142 |
# File 'lib/pact_broker/configuration.rb', line 137 def log_configuration logger.info "------------------------------------------------------------------------" logger.info "PACT BROKER CONFIGURATION:" runtime_configuration.log_configuration(logger) logger.info "------------------------------------------------------------------------" end |
#logger ⇒ Object
125 126 127 |
# File 'lib/pact_broker/configuration.rb', line 125 def logger custom_logger || logger_from_runtime_configuration end |
#logger=(logger) ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/pact_broker/configuration.rb', line 129 def logger= logger if @default_appender && SemanticLogger.appenders.include?(@default_appender) SemanticLogger.remove_appender(@default_appender) @default_appender = nil end @custom_logger = logger end |
#logger_from_runtime_configuration ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/pact_broker/configuration.rb', line 100 def logger_from_runtime_configuration @logger_from_runtime_configuration ||= begin SemanticLogger.default_level = runtime_configuration.log_level formatter = resolve_log_formatter(runtime_configuration.log_format) if runtime_configuration.log_stream == :file path = runtime_configuration.log_dir + "/pact_broker.log" FileUtils.mkdir_p(runtime_configuration.log_dir) @default_appender = SemanticLogger.add_appender(file_name: path, formatter: formatter) else @default_appender = SemanticLogger.add_appender(io: $stdout, formatter: formatter) end PactBroker::Logging::OpenTelemetryAppenderSetup.call(runtime_configuration) @logger_from_runtime_configuration = SemanticLogger["pact-broker"] end end |
#max_wip_lookback_days ⇒ Object
Maximum lookback window (days) to query for unverified pacts. Prevents timeout on large datasets.
222 223 224 |
# File 'lib/pact_broker/configuration.rb', line 222 def max_wip_lookback_days ENV["PACT_BROKER_MAX_WIP_LOOKBACK_DAYS"]&.to_i || 14 end |
#min_wip_window_days ⇒ Object
Minimum WIP window (days) to ensure recent pacts are always included, even if P80 is very low.
227 228 229 |
# File 'lib/pact_broker/configuration.rb', line 227 def min_wip_window_days ENV["PACT_BROKER_MIN_WIP_WINDOW_DAYS"]&.to_i || 7 end |
#override_runtime_configuration!(overrides) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/pact_broker/configuration.rb', line 85 def override_runtime_configuration!(overrides) new_runtime_configuration = runtime_configuration.dup valid_overrides, invalid_overrides = identify_valid_and_invalid_configuration_overrides(new_runtime_configuration, overrides) if logger.debug? logger.debug("Overriding runtime configuration", overrides: valid_overrides, ignoring: invalid_overrides) end valid_overrides.each do | key, value | override_or_merge_value(new_runtime_configuration, key, value) end self.runtime_configuration = new_runtime_configuration end |
#show_backtrace_in_error_response? ⇒ Boolean
151 152 153 |
# File 'lib/pact_broker/configuration.rb', line 151 def show_backtrace_in_error_response? !!(ENV["RACK_ENV"] && ENV["RACK_ENV"].downcase != "production") end |
#show_webhook_response? ⇒ Boolean
213 214 215 |
# File 'lib/pact_broker/configuration.rb', line 213 def show_webhook_response? webhook_host_whitelist&.any? end |
#verified_by_other_branch_before_this_branch_look_back ⇒ Object
Lookback window (days) for checking if a pact was verified by another branch before this branch was created. Uses verification execution_date to find recent branch activity, avoiding false negatives when old version numbers are reused across branches.
234 235 236 |
# File 'lib/pact_broker/configuration.rb', line 234 def verified_by_other_branch_before_this_branch_look_back ENV["PACT_BROKER_VERIFIED_BY_OTHER_BRANCH_LOOKBACK_DAYS"]&.to_i || 30 end |