diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2014-11-20 11:06:27 +0100 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2014-11-20 11:06:27 +0100 |
commit | f8453da5868dd7a23d0f2f3da7a45e33c441d1db (patch) | |
tree | 4287dcaab5a9b0e8be14e82104a109ca9349b81a /lib | |
parent | 11311a95545f967a5736cd16ab5fc37f7e658519 (diff) | |
download | gitlab-shell-f8453da5868dd7a23d0f2f3da7a45e33c441d1db.tar.gz |
Revert "Merge branch 'git_hook_messages'"
At least the following things were broken:
- missing require for 'gitlab_access_status' in lib/gitlab_net.rb
- gitlabhq master internal API returns 'true' or 'false', gitlab-shell
expects JSON
This reverts commit 11311a95545f967a5736cd16ab5fc37f7e658519, reversing
changes made to 45444597aef3e434571de2491934ae92357ad231.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab_access.rb | 10 | ||||
-rw-r--r-- | lib/gitlab_access_status.rb | 20 | ||||
-rw-r--r-- | lib/gitlab_net.rb | 8 | ||||
-rw-r--r-- | lib/gitlab_shell.rb | 2 |
4 files changed, 7 insertions, 33 deletions
diff --git a/lib/gitlab_access.rb b/lib/gitlab_access.rb index 547b81d..78d353c 100644 --- a/lib/gitlab_access.rb +++ b/lib/gitlab_access.rb @@ -1,6 +1,5 @@ require_relative 'gitlab_init' require_relative 'gitlab_net' -require_relative 'gitlab_access_status' require_relative 'names_helper' require 'json' @@ -18,14 +17,13 @@ class GitlabAccess end def exec - status = api.check_access('git-receive-pack', @repo_name, @actor, @changes) - if status.allowed? - true + if api.allowed?('git-receive-pack', @repo_name, @actor, @changes) + return true else # reset GL_ID env since we stop git push here ENV['GL_ID'] = nil - puts "GitLab: #{status.message}" - false + puts "GitLab: You are not allowed to access some of the refs!" + return false end end diff --git a/lib/gitlab_access_status.rb b/lib/gitlab_access_status.rb deleted file mode 100644 index 597fcbb..0000000 --- a/lib/gitlab_access_status.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'json' - -class GitAccessStatus - attr_accessor :status, :message - alias_method :allowed?, :status - - def initialize(status, message = '') - @status = status - @message = message - end - - def self.create_from_json(json) - values = JSON.parse(json) - self.new(values["status"], values["message"]) - end - - def to_json - {status: @status, message: @message}.to_json - end -end
\ No newline at end of file diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb index 1f27398..e6478ef 100644 --- a/lib/gitlab_net.rb +++ b/lib/gitlab_net.rb @@ -6,7 +6,7 @@ require_relative 'gitlab_config' require_relative 'gitlab_logger' class GitlabNet - def check_access(cmd, repo, actor, changes) + def allowed?(cmd, repo, actor, changes) project_name = repo.gsub("'", "") project_name = project_name.gsub(/\.git\Z/, "") project_name = project_name.gsub(/\A\//, "") @@ -26,11 +26,7 @@ class GitlabNet url = "#{host}/allowed" resp = post(url, params) - if resp.code == '200' - GitAccessStatus.create_from_json(resp.body) - else - GitAccessStatus.new(false, "API is not accesible") - end + !!(resp.code == '200' && resp.body == 'true') end def discover(key) diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb index 95fad9e..e2cb2cc 100644 --- a/lib/gitlab_shell.rb +++ b/lib/gitlab_shell.rb @@ -60,7 +60,7 @@ class GitlabShell end def validate_access - api.check_access(@git_cmd, @repo_name, @key_id, '_any').allowed? + api.allowed?(@git_cmd, @repo_name, @key_id, '_any') end # This method is not covered by Rspec because it ends the current Ruby process. |