Sha256: b292f28b41a61c48cdcf1627df0407967d73458af8102bcea19c15bcb1c595a4

Contents?: true

Size: 980 Bytes

Versions: 52

Compression:

Stored size: 980 Bytes

Contents

class DiscoApp::WebhookService

  # Return true iff the provided hmac_to_verify matches that calculated from the
  # given data and secret.
  def self.is_valid_hmac?(body, secret, hmac_to_verify)
    ActiveSupport::SecurityUtils.secure_compare(self.calculated_hmac(body, secret), hmac_to_verify.to_s)
  end

  # Calculate the HMAC for the given data and secret.
  def self.calculated_hmac(body, secret)
    digest  = OpenSSL::Digest.new('sha256')
    Base64.encode64(OpenSSL::HMAC.digest(digest, secret, body)).strip
  end

  # Try to find a job class for the given webhook topic.
  def self.find_job_class(topic)
    begin
      # First try to find a top-level matching job class.
      "#{topic}_job".gsub('/', '_').classify.constantize
    rescue NameError
      # If that fails, try to find a DiscoApp:: prefixed job class.
      begin
        %Q{DiscoApp::#{"#{topic}_job".gsub('/', '_').classify}}.constantize
      rescue NameError
        nil
      end
    end
  end

end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
disco_app-0.16.1.pre.sidekiq.pre.6.pre.release app/services/disco_app/webhook_service.rb
disco_app-0.8.4 app/services/disco_app/webhook_service.rb
disco_app-0.8.5 app/services/disco_app/webhook_service.rb
disco_app-0.8.6 app/services/disco_app/webhook_service.rb
disco_app-0.8.7 app/services/disco_app/webhook_service.rb
disco_app-0.8.8 app/services/disco_app/webhook_service.rb
disco_app-0.8.9 app/services/disco_app/webhook_service.rb
disco_app-0.9.0 app/services/disco_app/webhook_service.rb
disco_app-0.9.1 app/services/disco_app/webhook_service.rb
disco_app-0.9.2 app/services/disco_app/webhook_service.rb
disco_app-0.9.3 app/services/disco_app/webhook_service.rb
disco_app-0.9.4 app/services/disco_app/webhook_service.rb
disco_app-0.9.5 app/services/disco_app/webhook_service.rb
disco_app-0.9.6 app/services/disco_app/webhook_service.rb
disco_app-0.9.7 app/services/disco_app/webhook_service.rb
disco_app-0.9.8 app/services/disco_app/webhook_service.rb
disco_app-0.9.9 app/services/disco_app/webhook_service.rb
disco_app-0.9.10 app/services/disco_app/webhook_service.rb
disco_app-0.9.11 app/services/disco_app/webhook_service.rb
disco_app-0.10.0 app/services/disco_app/webhook_service.rb