Class: Gitlab::Jira::HttpClient

Inherits:
JIRA::HttpClient
  • Object
show all
Extended by:
Utils::Override
Defined in:
lib/gitlab/jira/http_client.rb

Overview

Gitlab JIRA HTTP client to be used with jira-ruby gem, this subclasses JIRA::HTTPClient. Uses Gitlab::HTTP to make requests to JIRA REST API. The parent class implementation can be found at: github.com/sumoheavy/jira-ruby/blob/master/lib/jira/http_client.rb

Instance Method Summary collapse

Methods included from Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Instance Method Details



21
22
23
24
25
26
27
28
# File 'lib/gitlab/jira/http_client.rb', line 21

def make_cookie_auth_request
  body = {
    username: @options.delete(:username),
    password: @options.delete(:password)
  }.to_json

  make_request(:post, @options[:context_path] + '/rest/auth/1/session', body, 'Content-Type' => 'application/json')
end

#make_request(http_method, path, body = '', headers = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gitlab/jira/http_client.rb', line 31

def make_request(http_method, path, body = '', headers = {})
  request_params = { headers: headers }
  request_params[:body] = body if body.present?
  request_params[:headers][:Cookie] = get_cookies if options[:use_cookies]
  request_params[:base_uri] = uri.to_s
  request_params.merge!(auth_params)

  result = Gitlab::HTTP.public_send(http_method, path, **request_params) # rubocop:disable GitlabSecurity/PublicSend
  @authenticated = result.response.is_a?(Net::HTTPOK)
  store_cookies(result) if options[:use_cookies]

  # This is needed to make response.to_s work. HTTParty::Response internal uses a Net::HTTPResponse as @response.
  # When a block is used, Net::HTTPResponse#body will be a Net::ReadAdapter instead of a String.
  # In this case HTTParty::Response.to_s will default to inspecting the Net::HTTPResponse class instead
  # of returning the content of body.
  # See https://github.com/jnunemaker/httparty/blob/v0.18.1/lib/httparty/response.rb#L86-L92
  # See https://github.com/ruby/net-http/blob/v0.1.1/lib/net/http/response.rb#L346-L350
  result.response.body = result.body

  result
end

#request(*args) ⇒ Object

Raises:

  • (JIRA::HTTPError)


12
13
14
15
16
17
18
# File 'lib/gitlab/jira/http_client.rb', line 12

def request(*args)
  result = make_request(*args)

  raise JIRA::HTTPError, result.response unless result.response.is_a?(Net::HTTPSuccess)

  result
end