Class: GithubBot::ApplicationController
- Inherits:
-
ActionController::API
- Object
- ActionController::API
- GithubBot::ApplicationController
- Includes:
- GithubRequestHelper, Response
- Defined in:
- app/controllers/github_bot/application_controller.rb
Overview
Public: Base controller for handing rails routes into the GithubBot
Direct Known Subclasses
Instance Method Summary collapse
-
#event_processing ⇒ Object
Public: Initial the request for event processing.
-
#valid_request? ⇒ Boolean
Public: Returns <true> if the incoming request if properly authorized.
Methods included from GithubRequestHelper
#check_run?, #comment_body, #github_event, #github_payload, #github_payload_raw, #github_signature, #issue_comment?, #issue_comment_recheck?, #labeled?, #ping?, #pull_request, #pull_request?, #pull_request_action, #pull_request_review?, #recheck_application?, #repository, #review_request_removed?, #review_requested?, #unlabeled?
Methods included from Response
#json_access_denied, #json_not_found, #json_response
Instance Method Details
#event_processing ⇒ Object
Public: Initial the request for event processing
16 17 18 |
# File 'app/controllers/github_bot/application_controller.rb', line 16 def event_processing Github::Client.initialize(request) end |
#valid_request? ⇒ Boolean
Public: Returns <true> if the incoming request if properly authorized
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/github_bot/application_controller.rb', line 21 def valid_request? signature = github_signature my_signature = 'sha1=' + OpenSSL::HMAC.hexdigest( OpenSSL::Digest.new('sha1'), ENV['GITHUB_WEBHOOK_SECRET'], github_payload_raw ) json_response(json_access_denied, :unauthorized) unless Rack::Utils.secure_compare(my_signature, signature) rescue StandardError => e msg = "#{self.class}##{__method__} An error occurred while determine if request is valid" Rails.logger.error( message: msg, exception: e ) json_response(json_access_denied(errors: { message: "#{msg}, exception: #{e.}" }), :unauthorized) end |