2011-10-08 23:36:38 +02:00
|
|
|
require 'inifile'
|
2011-10-09 23:15:28 +02:00
|
|
|
require 'timeout'
|
2011-10-08 23:36:38 +02:00
|
|
|
class Gitosis
|
2011-10-09 23:15:28 +02:00
|
|
|
class AccessDenied < StandardError; end
|
2011-10-08 23:36:38 +02:00
|
|
|
|
|
|
|
def pull
|
|
|
|
# create tmp dir
|
|
|
|
@local_dir = File.join(Dir.tmpdir,"gitme-gitosis-#{Time.now.to_i}")
|
|
|
|
|
|
|
|
Dir.mkdir @local_dir
|
|
|
|
|
2011-10-09 00:15:24 +02:00
|
|
|
@repo = Git.clone(GITOSIS['admin_uri'], "#{@local_dir}/gitosis")
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def push
|
2011-10-09 00:15:24 +02:00
|
|
|
@repo.add('.')
|
|
|
|
@repo.commit_all "Gitlab"
|
|
|
|
@repo.push
|
2011-10-08 23:36:38 +02:00
|
|
|
|
|
|
|
`rm -Rf #{@local_dir}`
|
|
|
|
end
|
|
|
|
|
|
|
|
def configure
|
2011-10-09 23:15:28 +02:00
|
|
|
status = Timeout::timeout(5) {
|
|
|
|
File.open(File.join(Dir.tmpdir,"gitme-gitosis.lock"), "w+") do |f|
|
2011-10-08 23:36:38 +02:00
|
|
|
f.flock(File::LOCK_EX)
|
2011-10-09 23:15:28 +02:00
|
|
|
|
2011-10-08 23:36:38 +02:00
|
|
|
pull
|
|
|
|
yield(self)
|
|
|
|
push
|
2011-10-09 23:15:28 +02:00
|
|
|
|
2011-10-08 23:36:38 +02:00
|
|
|
f.flock(File::LOCK_UN)
|
2011-10-09 23:15:28 +02:00
|
|
|
end
|
|
|
|
}
|
|
|
|
rescue Exception => ex
|
|
|
|
raise Gitosis::AccessDenied.new("gitosis timeout")
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_project(project)
|
|
|
|
`rm -Rf #{project.path_to_repo}`
|
|
|
|
|
|
|
|
conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf'))
|
|
|
|
|
|
|
|
conf.delete_section("group #{project.path}")
|
|
|
|
|
|
|
|
conf.write
|
|
|
|
end
|
|
|
|
|
|
|
|
#update or create
|
|
|
|
def update_keys(user, key)
|
|
|
|
File.open(File.join(@local_dir, 'gitosis/keydir',"#{user}.pub"), 'w') {|f| f.write(key.gsub(/\n/,'')) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_key(user)
|
|
|
|
File.unlink(File.join(@local_dir, 'gitosis/keydir',"#{user}.pub"))
|
|
|
|
`cd #{File.join(@local_dir,'gitosis')} ; git rm keydir/#{user}.pub`
|
|
|
|
end
|
|
|
|
|
2011-10-09 23:15:28 +02:00
|
|
|
#update or create
|
2011-10-08 23:36:38 +02:00
|
|
|
def update_project(repo_name, name_writers)
|
|
|
|
# write config file
|
|
|
|
conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf'))
|
|
|
|
|
|
|
|
conf["group #{repo_name}"]['writable'] = repo_name
|
|
|
|
conf["group #{repo_name}"]['members'] = name_writers.join(' ')
|
|
|
|
|
|
|
|
conf.write
|
|
|
|
end
|
|
|
|
end
|