Sha256: a1b813ff5e720d2225604b9581247d53ac2d0c833bc8e46a2cad7e0e246e83c3

Contents?: true

Size: 1.47 KB

Versions: 23

Compression:

Stored size: 1.47 KB

Contents

require_dependency "hubstats/application_controller"

module Hubstats
  class EventsController < ApplicationController

    # Public - Verifies that the request we're receiving is a new event, and then will handle it and route
    # it to the correct place.
    #
    # request - the request of the new event
    #
    # Returns - nothing, but makes a new event
    def handler
      verify_signature(request)
      
      kind = request.headers['X-Github-Event']
      event = event_params.with_indifferent_access

      raw_parameters = request.request_parameters
      event[:github_action] = raw_parameters["action"]

      eventsHandler = Hubstats::EventsHandler.new()
      eventsHandler.route(event, kind)

      render :nothing => true
    end

    # Public - Will check that the request passed is a valid signature.
    # 
    # request - the signature to be checked
    #
    # Returns - an error if the signatures don't match
    private
    def verify_signature(request)
      request.body.rewind
      payload_body = request.body.read
      signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), Hubstats.config.webhook_endpoint, payload_body)
      return 500, "Signatures didn't match!" unless Rack::Utils.secure_compare(signature, request.env['HTTP_X_HUB_SIGNATURE'])
    end

    # Private - Allows only these parameters to be added when creating an event
    #
    # Returns - hash of parameters
    private
    def event_params
      params.permit!
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
hubstats-0.12.2 app/controllers/hubstats/events_controller.rb
hubstats-0.12.1 app/controllers/hubstats/events_controller.rb
hubstats-0.12.0 app/controllers/hubstats/events_controller.rb
hubstats-0.11.5 app/controllers/hubstats/events_controller.rb
hubstats-0.11.4 app/controllers/hubstats/events_controller.rb
hubstats-0.11.1 app/controllers/hubstats/events_controller.rb
hubstats-0.11.0 app/controllers/hubstats/events_controller.rb
hubstats-0.10.0 app/controllers/hubstats/events_controller.rb
hubstats-0.9.5 app/controllers/hubstats/events_controller.rb
hubstats-0.9.4 app/controllers/hubstats/events_controller.rb
hubstats-0.9.3 app/controllers/hubstats/events_controller.rb
hubstats-0.9.2 app/controllers/hubstats/events_controller.rb
hubstats-0.9.1 app/controllers/hubstats/events_controller.rb
hubstats-0.9.0 app/controllers/hubstats/events_controller.rb
hubstats-0.8.0 app/controllers/hubstats/events_controller.rb
hubstats-0.7.7 app/controllers/hubstats/events_controller.rb
hubstats-0.7.6 app/controllers/hubstats/events_controller.rb
hubstats-0.7.5 app/controllers/hubstats/events_controller.rb
hubstats-0.7.4 app/controllers/hubstats/events_controller.rb
hubstats-0.7.3 app/controllers/hubstats/events_controller.rb