Class: PactBroker::Configuration
- Inherits:
-
Object
- Object
- PactBroker::Configuration
- Defined in:
- lib/pact_broker/configuration.rb
Constant Summary collapse
- SAVABLE_SETTING_NAMES =
[ :order_versions_by_date, :use_case_sensitive_resource_names, :enable_public_badge_access, :shields_io_base_url, :check_for_potential_duplicate_pacticipant_names, :webhook_retry_schedule, :semver_formats, :disable_ssl_verification, :webhook_http_method_whitelist, :webhook_scheme_whitelist, :webhook_host_whitelist, :base_equality_only_on_content_that_affects_verification_results ]
Instance Attribute Summary collapse
-
#api_error_reporters ⇒ Object
readonly
Returns the value of attribute api_error_reporters.
-
#auto_migrate_db ⇒ Object
Returns the value of attribute auto_migrate_db.
-
#auto_migrate_db_data ⇒ Object
Returns the value of attribute auto_migrate_db_data.
-
#base_equality_only_on_content_that_affects_verification_results ⇒ Object
Returns the value of attribute base_equality_only_on_content_that_affects_verification_results.
-
#check_for_potential_duplicate_pacticipant_names ⇒ Object
Returns the value of attribute check_for_potential_duplicate_pacticipant_names.
-
#custom_logger ⇒ Object
readonly
Returns the value of attribute custom_logger.
-
#database_connection ⇒ Object
Returns the value of attribute database_connection.
-
#disable_ssl_verification ⇒ Object
Returns the value of attribute disable_ssl_verification.
-
#enable_diagnostic_endpoints ⇒ Object
Returns the value of attribute enable_diagnostic_endpoints.
-
#enable_public_badge_access ⇒ Object
Returns the value of attribute enable_public_badge_access.
-
#html_pact_renderer ⇒ Object
Returns the value of attribute html_pact_renderer.
-
#log_dir ⇒ Object
Returns the value of attribute log_dir.
-
#order_versions_by_date ⇒ Object
Returns the value of attribute order_versions_by_date.
-
#semver_formats ⇒ Object
Returns the value of attribute semver_formats.
-
#sha_generator ⇒ Object
Returns the value of attribute sha_generator.
-
#shields_io_base_url ⇒ Object
Returns the value of attribute shields_io_base_url.
-
#use_case_sensitive_resource_names ⇒ Object
Returns the value of attribute use_case_sensitive_resource_names.
-
#use_hal_browser ⇒ Object
Returns the value of attribute use_hal_browser.
-
#use_rack_protection ⇒ Object
Returns the value of attribute use_rack_protection.
-
#validate_database_connection_config ⇒ Object
Returns the value of attribute validate_database_connection_config.
-
#version_parser ⇒ Object
Returns the value of attribute version_parser.
-
#webhook_host_whitelist ⇒ Object
Returns the value of attribute webhook_host_whitelist.
-
#webhook_http_method_whitelist ⇒ Object
Returns the value of attribute webhook_http_method_whitelist.
-
#webhook_retry_schedule ⇒ Object
Returns the value of attribute webhook_retry_schedule.
-
#webhook_scheme_whitelist ⇒ Object
Returns the value of attribute webhook_scheme_whitelist.
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
- #base_url ⇒ Object
- #before_resource(&block) ⇒ Object
- #enable_badge_resources=(enable_badge_resources) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #load_from_database! ⇒ Object
- #logger ⇒ Object
- #logger=(logger) ⇒ Object
- #save_to_database ⇒ Object
- #show_backtrace_in_error_response? ⇒ Boolean
- #show_webhook_response? ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
48 49 50 51 52 53 54 55 |
# File 'lib/pact_broker/configuration.rb', line 48 def initialize @before_resource_hook = ->(resource){} @after_resource_hook = ->(resource){} @authenticate_with_basic_auth = nil @authorize = nil @api_error_reporters = [] @semantic_logger = SemanticLogger["root"] end |
Instance Attribute Details
#api_error_reporters ⇒ Object (readonly)
Returns the value of attribute api_error_reporters.
45 46 47 |
# File 'lib/pact_broker/configuration.rb', line 45 def api_error_reporters @api_error_reporters end |
#auto_migrate_db ⇒ Object
Returns the value of attribute auto_migrate_db.
35 36 37 |
# File 'lib/pact_broker/configuration.rb', line 35 def auto_migrate_db @auto_migrate_db end |
#auto_migrate_db_data ⇒ Object
Returns the value of attribute auto_migrate_db_data.
35 36 37 |
# File 'lib/pact_broker/configuration.rb', line 35 def auto_migrate_db_data @auto_migrate_db_data end |
#base_equality_only_on_content_that_affects_verification_results ⇒ Object
Returns the value of attribute base_equality_only_on_content_that_affects_verification_results.
44 45 46 |
# File 'lib/pact_broker/configuration.rb', line 44 def base_equality_only_on_content_that_affects_verification_results @base_equality_only_on_content_that_affects_verification_results end |
#check_for_potential_duplicate_pacticipant_names ⇒ Object
Returns the value of attribute check_for_potential_duplicate_pacticipant_names.
38 39 40 |
# File 'lib/pact_broker/configuration.rb', line 38 def check_for_potential_duplicate_pacticipant_names @check_for_potential_duplicate_pacticipant_names end |
#custom_logger ⇒ Object (readonly)
Returns the value of attribute custom_logger.
46 47 48 |
# File 'lib/pact_broker/configuration.rb', line 46 def custom_logger @custom_logger end |
#database_connection ⇒ Object
Returns the value of attribute database_connection.
35 36 37 |
# File 'lib/pact_broker/configuration.rb', line 35 def database_connection @database_connection end |
#disable_ssl_verification ⇒ Object
Returns the value of attribute disable_ssl_verification.
43 44 45 |
# File 'lib/pact_broker/configuration.rb', line 43 def disable_ssl_verification @disable_ssl_verification end |
#enable_diagnostic_endpoints ⇒ Object
Returns the value of attribute enable_diagnostic_endpoints.
36 37 38 |
# File 'lib/pact_broker/configuration.rb', line 36 def enable_diagnostic_endpoints @enable_diagnostic_endpoints end |
#enable_public_badge_access ⇒ Object
Returns the value of attribute enable_public_badge_access.
42 43 44 |
# File 'lib/pact_broker/configuration.rb', line 42 def enable_public_badge_access @enable_public_badge_access end |
#html_pact_renderer ⇒ Object
Returns the value of attribute html_pact_renderer.
35 36 37 |
# File 'lib/pact_broker/configuration.rb', line 35 def html_pact_renderer @html_pact_renderer end |
#log_dir ⇒ Object
Returns the value of attribute log_dir.
35 36 37 |
# File 'lib/pact_broker/configuration.rb', line 35 def log_dir @log_dir end |
#order_versions_by_date ⇒ Object
Returns the value of attribute order_versions_by_date.
37 38 39 |
# File 'lib/pact_broker/configuration.rb', line 37 def order_versions_by_date @order_versions_by_date end |
#semver_formats ⇒ Object
Returns the value of attribute semver_formats.
41 42 43 |
# File 'lib/pact_broker/configuration.rb', line 41 def semver_formats @semver_formats end |
#sha_generator ⇒ Object
Returns the value of attribute sha_generator.
36 37 38 |
# File 'lib/pact_broker/configuration.rb', line 36 def sha_generator @sha_generator end |
#shields_io_base_url ⇒ Object
Returns the value of attribute shields_io_base_url.
42 43 44 |
# File 'lib/pact_broker/configuration.rb', line 42 def shields_io_base_url @shields_io_base_url end |
#use_case_sensitive_resource_names ⇒ Object
Returns the value of attribute use_case_sensitive_resource_names.
37 38 39 |
# File 'lib/pact_broker/configuration.rb', line 37 def use_case_sensitive_resource_names @use_case_sensitive_resource_names end |
#use_hal_browser ⇒ Object
Returns the value of attribute use_hal_browser.
35 36 37 |
# File 'lib/pact_broker/configuration.rb', line 35 def use_hal_browser @use_hal_browser end |
#use_rack_protection ⇒ Object
Returns the value of attribute use_rack_protection.
35 36 37 |
# File 'lib/pact_broker/configuration.rb', line 35 def use_rack_protection @use_rack_protection end |
#validate_database_connection_config ⇒ Object
Returns the value of attribute validate_database_connection_config.
36 37 38 |
# File 'lib/pact_broker/configuration.rb', line 36 def validate_database_connection_config @validate_database_connection_config end |
#version_parser ⇒ Object
Returns the value of attribute version_parser.
36 37 38 |
# File 'lib/pact_broker/configuration.rb', line 36 def version_parser @version_parser end |
#webhook_host_whitelist ⇒ Object
Returns the value of attribute webhook_host_whitelist.
40 41 42 |
# File 'lib/pact_broker/configuration.rb', line 40 def webhook_host_whitelist @webhook_host_whitelist end |
#webhook_http_method_whitelist ⇒ Object
Returns the value of attribute webhook_http_method_whitelist.
40 41 42 |
# File 'lib/pact_broker/configuration.rb', line 40 def webhook_http_method_whitelist @webhook_http_method_whitelist end |
#webhook_retry_schedule ⇒ Object
Returns the value of attribute webhook_retry_schedule.
39 40 41 |
# File 'lib/pact_broker/configuration.rb', line 39 def webhook_retry_schedule @webhook_retry_schedule end |
#webhook_scheme_whitelist ⇒ Object
Returns the value of attribute webhook_scheme_whitelist.
40 41 42 |
# File 'lib/pact_broker/configuration.rb', line 40 def webhook_scheme_whitelist @webhook_scheme_whitelist end |
Class Method Details
.default_configuration ⇒ Object
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 84 85 |
# File 'lib/pact_broker/configuration.rb', line 57 def self.default_configuration require 'pact_broker/versions/parse_semantic_version' require 'pact_broker/pacts/generate_sha' config = Configuration.new config.log_dir = File.("./log") config.auto_migrate_db = true config.auto_migrate_db_data = true config.use_rack_protection = true config.use_hal_browser = true config.validate_database_connection_config = true config.enable_diagnostic_endpoints = true config.enable_public_badge_access = false # For security config.shields_io_base_url = "https://img.shields.io".freeze config.use_case_sensitive_resource_names = true config.html_pact_renderer = default_html_pact_render config.version_parser = PactBroker::Versions::ParseSemanticVersion config.sha_generator = PactBroker::Pacts::GenerateSha config.base_equality_only_on_content_that_affects_verification_results = true config.order_versions_by_date = true config.semver_formats = ["%M.%m.%p%s%d", "%M.%m", "%M"] config.webhook_retry_schedule = [10, 60, 120, 300, 600, 1200] #10 sec, 1 min, 2 min, 5 min, 10 min, 20 min => 38 minutes config.check_for_potential_duplicate_pacticipant_names = true config.disable_ssl_verification = false config.webhook_http_method_whitelist = ['POST'] config.webhook_scheme_whitelist = ['https'] config.webhook_host_whitelist = [] config end |
.default_html_pact_render ⇒ Object
95 96 97 98 99 100 |
# File 'lib/pact_broker/configuration.rb', line 95 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
154 155 156 157 158 159 160 161 162 |
# File 'lib/pact_broker/configuration.rb', line 154 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
146 147 148 149 150 151 152 |
# File 'lib/pact_broker/configuration.rb', line 146 def after_resource &block if block_given? @after_resource_hook = block else @after_resource_hook end end |
#authenticate(&block) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/pact_broker/configuration.rb', line 110 def authenticate &block if block_given? @authenticate = block else @authenticate end end |
#authenticate_with_basic_auth(&block) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/pact_broker/configuration.rb', line 118 def authenticate_with_basic_auth &block if block_given? @authenticate_with_basic_auth = block else @authenticate_with_basic_auth end end |
#authentication_configured? ⇒ Boolean
106 107 108 |
# File 'lib/pact_broker/configuration.rb', line 106 def authentication_configured? !!authenticate || !!authenticate_with_basic_auth end |
#authorization_configured? ⇒ Boolean
126 127 128 |
# File 'lib/pact_broker/configuration.rb', line 126 def !! end |
#authorize(&block) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/pact_broker/configuration.rb', line 130 def &block if block_given? @authorize = block else @authorize end end |
#base_url ⇒ Object
173 174 175 |
# File 'lib/pact_broker/configuration.rb', line 173 def base_url ENV['PACT_BROKER_BASE_URL'] end |
#before_resource(&block) ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/pact_broker/configuration.rb', line 138 def before_resource &block if block_given? @before_resource_hook = block else @before_resource_hook end end |
#enable_badge_resources=(enable_badge_resources) ⇒ Object
168 169 170 171 |
# File 'lib/pact_broker/configuration.rb', line 168 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
183 184 185 186 187 |
# File 'lib/pact_broker/configuration.rb', line 183 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(self) end |
#logger ⇒ Object
87 88 89 |
# File 'lib/pact_broker/configuration.rb', line 87 def logger custom_logger || @semantic_logger end |
#logger=(logger) ⇒ Object
91 92 93 |
# File 'lib/pact_broker/configuration.rb', line 91 def logger= logger @custom_logger = logger end |
#save_to_database ⇒ Object
177 178 179 180 181 |
# File 'lib/pact_broker/configuration.rb', line 177 def save_to_database # Can't require a Sequel::Model class before the connection has been set require 'pact_broker/config/save' PactBroker::Config::Save.call(self, SAVABLE_SETTING_NAMES) end |
#show_backtrace_in_error_response? ⇒ Boolean
102 103 104 |
# File 'lib/pact_broker/configuration.rb', line 102 def show_backtrace_in_error_response? !!(ENV['RACK_ENV'] && ENV['RACK_ENV'].downcase != 'production') end |
#show_webhook_response? ⇒ Boolean
164 165 166 |
# File 'lib/pact_broker/configuration.rb', line 164 def show_webhook_response? webhook_host_whitelist.any? end |