class PactBroker::Webhooks::WebhookRequestTemplate
Constants
- HEADERS_TO_REDACT
Attributes
Public Class Methods
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 23 def initialize attributes = {} attributes.each do | (name, value) | instance_variable_set("@#{name}", value) if respond_to?(name) end @headers = Rack::Headers.new @headers.merge!(attributes[:headers]) if attributes[:headers] end
Public Instance Methods
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 70 def body_string String === body ? body : body&.to_json end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 82 def body_template_parameters(scope = nil) body_string.scan(parameter_pattern(scope)).flatten.uniq end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 31 def build(template_params, user_agent: nil, disable_ssl_verification: false, cert_store: nil) attributes = { method: http_method, url: build_url(template_params), headers: build_headers(template_params), username: build_string(username, template_params), password: build_string(password, template_params), uuid: uuid, body: build_body(template_params), user_agent: user_agent, disable_ssl_verification: disable_ssl_verification, cert_store: cert_store } PactBroker::Domain::WebhookRequest.new(attributes) end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 95 def credentials_template_parameters(scope = nil) pattern = parameter_pattern(scope) [username, password].compact.collect do | credential | credential.scan(pattern) end.flatten.uniq end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 47 def description "#{http_method.upcase} #{URI(PactBroker::Webhooks::Render.render_with_placeholder(url)).host}" end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 51 def display_password password.nil? ? nil : (PactBroker::Webhooks::Render.includes_parameter?(password) ? password : "**********") end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 86 def header_template_parameters(scope = nil) pattern = parameter_pattern(scope) headers.values.collect { |value| value.scan(pattern) }.flatten.uniq end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 62 def headers= headers @headers.replace(headers) end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 55 def redacted_headers headers.each_with_object({}) do | (name, value), new_headers | redact = HEADERS_TO_REDACT.any?{ | pattern | name =~ pattern } && !PactBroker::Webhooks::Render.includes_parameter?(value) new_headers[name] = redact ? "**********" : value end end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 78 def template_parameters(scope = nil) body_template_parameters(scope) + url_template_parameters(scope) + header_template_parameters(scope) + credentials_template_parameters(scope) end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 74 def to_s "#{method.upcase} #{url}, username=#{username}, password=#{display_password}, headers=#{redacted_headers}, body=#{body}" end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 91 def url_template_parameters(scope = nil) url.scan(parameter_pattern(scope)).flatten.uniq end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 66 def uses_parameter?(parameter_name) !!body_string&.include?("${" + parameter_name + "}") end
Private Instance Methods
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 112 def build_body(template_params) body_string = String === body ? body : body.to_json build_string(body_string, template_params) end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 117 def build_headers(template_params) headers.each_with_object(Rack::Headers.new) do | (key, value), new_headers | new_headers[key] = build_string(value, template_params) end end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 123 def build_string(string, template_params) return string if string.nil? || string.blank? PactBroker::Webhooks::Render.call(string, template_params) end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 108 def build_url(template_params) URI(PactBroker::Webhooks::Render.call(url, template_params){ | value | CGI::escape(value) if !value.nil? } ).to_s end
Source
# File lib/pact_broker/webhooks/webhook_request_template.rb, line 104 def parameter_pattern(scope) scope ? /\${(#{scope}\.[a-zA-z]+)}/ : /\${([a-zA-z]+\.[a-zA-z]+)}/ end