Module: Tenter::Helpers Private

Defined in:
lib/tenter/helpers.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Sinatra helpers for Tenter

These helpers provide idiomatic methods for use in Sinatra routes. This module is intended to be called by passing it to the ‘Sinatra::Base.helpers` method.

Since:

  • 0.1.1

Instance Method Summary collapse

Instance Method Details

#authenticateObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Authenticates the request

Since:

  • 0.1.1



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tenter/helpers.rb', line 21

def authenticate
  msg = "X-Hub-Signature header not set"
  halt 400, msg unless request.env['HTTP_X_HUB_SIGNATURE']

  msg = "X-Hub-Signature header did not match"
  halt 403, msg unless Tenter::Utils.dir_exists? params[:site_dir]

  secret = Tenter::Utils.secret params[:site_dir]

  request_sig = request.env['HTTP_X_HUB_SIGNATURE']
  request_body = request.body.read
  computed_sig = 'sha1=' +
                 OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'),
                                         secret,
                                         request_body)

  msg = "X-Hub-Signature header did not match"
  halt 403, msg unless Rack::Utils.secure_compare computed_sig, request_sig
end

#initiateObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Executes the command

Since:

  • 0.1.1



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tenter/helpers.rb', line 45

def initiate
  command = Tenter::Utils.command params[:command_name], params[:site_dir]

  msg = "Command not found"
  halt 400, msg unless File.file? command["path"]

  ts = Tenter.settings[:timestamp] ? "[#{Time.now}] " : ""
  msg = ts + "Initiating: #{command["path"]}\n"
  Tenter::Utils.append_to_log command["log"], msg

  pid = if defined?(Bundler) && Bundler.respond_to?(:with_original_env)
          Bundler.with_original_env { command["proc"].call }
        else
          command["proc"].call
        end
  (ENV["APP_ENV"] != "test") ? Process.detach(pid) : Process.wait(pid)
end

#notify(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Generates the response’s HTTP header status and body

Parameters:

  • message (Symbol)

    the type of response

Since:

  • 0.1.1



68
69
70
71
72
73
74
75
# File 'lib/tenter/helpers.rb', line 68

def notify(message)
  case message
  when :initiated
    return 200, "Command initiated"
  when :missing
    halt 404, "Page not found"
  end
end