class PactBroker::Api::Contracts::WebhookContract
Public Class Methods
errors()
click to toggle source
rubocop: disable Lint/NestedMethodDefinition
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 24 def self.errors; @first_errors end
host_error_message()
click to toggle source
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 127 def self.host_error_message "host must be in the whitelist #{PactBroker.configuration.webhook_host_whitelist.join(",")}. See /doc/webhooks#whitelist for more information." end
http_method_error_message()
click to toggle source
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 115 def self.http_method_error_message if PactBroker.configuration.webhook_http_method_whitelist.size == 1 "must be #{PactBroker.configuration.webhook_http_method_whitelist.first}. See /doc/webhooks#whitelist for more information." else "must be one of #{PactBroker.configuration.webhook_http_method_whitelist.join(", ")}. See /doc/webhooks#whitelist for more information." end end
messages()
click to toggle source
Calls superclass method
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 103 def self.messages super.merge( en: { errors: { allowed_webhook_method?: http_method_error_message, allowed_webhook_scheme?: scheme_error_message, allowed_webhook_host?: host_error_message } } ) end
scheme_error_message()
click to toggle source
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 123 def self.scheme_error_message "scheme must be #{PactBroker.configuration.webhook_scheme_whitelist.join(", ")}. See /doc/webhooks#whitelist for more information." end
Public Instance Methods
allowed_webhook_host?(url)
click to toggle source
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 155 def allowed_webhook_host?(url) if host_whitelist.any? PactBroker::Webhooks::CheckHostWhitelist.call(parse_uri(url).host, host_whitelist).any? else true end end
allowed_webhook_method?(http_method)
click to toggle source
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 142 def allowed_webhook_method?(http_method) PactBroker.configuration.webhook_http_method_whitelist.any? do | allowed_method | http_method.downcase == allowed_method.downcase end end
allowed_webhook_scheme?(url)
click to toggle source
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 148 def allowed_webhook_scheme?(url) scheme = parse_uri(url).scheme PactBroker.configuration.webhook_scheme_whitelist.any? do | allowed_scheme | scheme.downcase == allowed_scheme.downcase end end
host_whitelist()
click to toggle source
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 167 def host_whitelist PactBroker.configuration.webhook_host_whitelist end
non_templated_host?(url)
click to toggle source
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 163 def non_templated_host?(url) parse_uri(url).host == parse_uri(url, "differentplaceholder").host end
pacticipant_exists?(name)
click to toggle source
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 49 def pacticipant_exists?(name) !!PactBroker::Pacticipants::Service.find_pacticipant_by_name(name) end
parse_uri(uri_string, placeholder = "placeholder")
click to toggle source
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 171 def parse_uri(uri_string, placeholder = "placeholder") URI(PactBroker::Webhooks::Render.render_with_placeholder(uri_string, placeholder)) end
valid_method?(http_method)
click to toggle source
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 131 def valid_method?(http_method) Net::HTTP.const_defined?(http_method.capitalize) end
valid_url?(url)
click to toggle source
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 135 def valid_url?(url) uri = parse_uri(url) uri.scheme && uri.host rescue URI::InvalidURIError, ArgumentError nil end
validate(*)
click to toggle source
Calls superclass method
# File lib/pact_broker/api/contracts/webhook_contract.rb, line 12 def validate(*) result = super # I just cannot seem to get the validation to stop on the first error. # If one rule fails, they all come back failed, and it's driving me nuts. # Why on earth would I want that behaviour? # I cannot believe I have to do this shit. @first_errors = errors @first_errors.messages.keys.each do | key | @first_errors.messages[key] = @first_errors.messages[key][0...1] end # rubocop: disable Lint/NestedMethodDefinition def self.errors; @first_errors end # rubocop: enable Lint/NestedMethodDefinition result end