Created
July 13, 2012 12:15
-
-
Save Yggdrasil/3104595 to your computer and use it in GitHub Desktop.
Sinatra Hooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require './hooks' | |
run Hooks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'sinatra/base' | |
require 'json' | |
require 'pp' | |
class Hooks < Sinatra::Base | |
set :sessions, false | |
set :token, 'xxxxxxxxxxxxx' #A simple token | |
PUPPETDIR = '/srv/puppet' | |
MODULESDIR = "#{PUPPETDIR}/modules" | |
CLIENTSDIR = "#{PUPPETDIR}/clients" | |
def update_submodule(name) | |
system "cd #{MODULESDIR}/#{name} && git fetch && git pull origin master" | |
end | |
def update_client(name) | |
system "cd #{CLIENTSDIR}/#{name} && git fetch && git pull origin master" | |
end | |
def update_master | |
system "cd #{PUPPETDIR} && git fetch && git pull origin master" | |
end | |
get '/hooks*' do | |
'Nothing to see here! Please disperse!' | |
end | |
post '/hooks/github/puppetmaster/:token' do | |
token = params['token'] | |
halt 403, 'Token is wrong' unless token == settings.token | |
update_master | |
end | |
post '/hooks/github/puppet/:type/:name/:token' do | |
type = params['type'] | |
name = params['name'] | |
token = params['token'] | |
halt 403, 'Token is wrong' unless token == settings.token | |
case type | |
when 'module' | |
update_submodule name | |
when 'client' | |
update_client name | |
else | |
halt 404, 'Nothing to do here' | |
end | |
end | |
end | |
#push = JSON.parse(params[:payload]) | |
#repo_name = push["repository"]["name"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location /hooks { | |
alias /srv/hooks/public; | |
passenger_enabled on; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment