summaryrefslogtreecommitdiff
path: root/lib/gitlab_net.rb
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2018-09-11 11:05:24 +0000
committerNick Thomas <nick@gitlab.com>2018-09-11 11:05:24 +0000
commit624a97d654ed02bd7fb65b6205b1533cfbe2cfbc (patch)
treec71e79f03b1ac7e21a7966d01cbce90f24d690dd /lib/gitlab_net.rb
parente5b6e8e2550e203978cd25d3e07ca468b4d06c91 (diff)
downloadgitlab-shell-624a97d654ed02bd7fb65b6205b1533cfbe2cfbc.tar.gz
Ensure text/plain & text/html content typs are handled and add missing specs for handled HTTP status codes
Diffstat (limited to 'lib/gitlab_net.rb')
-rw-r--r--lib/gitlab_net.rb14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb
index 57ae452..b460f46 100644
--- a/lib/gitlab_net.rb
+++ b/lib/gitlab_net.rb
@@ -14,6 +14,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
class NotFound < StandardError; end
CHECK_TIMEOUT = 5
+ API_INACCESSIBLE_MESSAGE = 'API is not accessible'.freeze
def check_access(cmd, gl_repository, repo, who, changes, protocol, env: {})
changes = changes.join("\n") unless changes.is_a?(String)
@@ -33,12 +34,15 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
url = "#{internal_api_endpoint}/allowed"
resp = post(url, params)
- case resp.code
- when HTTP_SUCCESS, HTTP_MULTIPLE_CHOICES, HTTP_UNAUTHORIZED, HTTP_NOT_FOUND
- GitAccessStatus.create_from_json(resp.body, resp.code)
- else
- GitAccessStatus.new(false, resp.code, 'API is not accessible')
+ case resp
+ when Net::HTTPSuccess, Net::HTTPMultipleChoices, Net::HTTPUnauthorized,
+ Net::HTTPNotFound
+ if resp.content_type == CONTENT_TYPE_JSON
+ return GitAccessStatus.create_from_json(resp.body, resp.code)
+ end
end
+
+ GitAccessStatus.new(false, resp.code, API_INACCESSIBLE_MESSAGE)
end
def discover(who)