diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-01 19:00:06 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-01 19:00:06 +0300 |
commit | 119aae7d71cac17af9a68122c8b3021adf5cbfd9 (patch) | |
tree | 40c4756ad1b647dd655c13b0805ecf14ae2be372 /lib/gitlab_access.rb | |
parent | c6909d0c941784d60cb552d5685e1ff808323991 (diff) | |
download | gitlab-shell-119aae7d71cac17af9a68122c8b3021adf5cbfd9.tar.gz |
GitlabAccess and GitlabPostReceive classes added
Gitlab Access handles security check. GitlabPostReceive creates a sidekiq job
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'lib/gitlab_access.rb')
-rw-r--r-- | lib/gitlab_access.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/gitlab_access.rb b/lib/gitlab_access.rb new file mode 100644 index 0000000..1f328b7 --- /dev/null +++ b/lib/gitlab_access.rb @@ -0,0 +1,34 @@ +require_relative 'gitlab_init' +require_relative 'gitlab_net' +require_relative 'names_helper' +require 'json' + +class GitlabAccess + include NamesHelper + + attr_reader :config, :repo_path, :repo_name, :changes + + def initialize(repo_path, actor, changes) + @config = GitlabConfig.new + @repo_path, @actor = repo_path.strip, actor + @repo_name = extract_repo_name(@repo_path.dup, config.repos_path.to_s) + @changes = changes.lines + end + + def exec + if api.allowed?('git-receive-pack', @repo_name, @actor, @changes) + exit 0 + else + # reset GL_ID env since we stop git push here + ENV['GL_ID'] = nil + puts "GitLab: You are not allowed to access #{@ref_name}!" + exit 1 + end + end + + protected + + def api + GitlabNet.new + end +end |