Class: Concourse::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/concourse/client.rb

Constant Summary collapse

API_BASE_PATH =
'/api/v1/teams/main/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(concourse_uri, username: nil, password: nil, options: {}) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
# File 'lib/concourse/client.rb', line 13

def initialize(concourse_uri, username: nil, password: nil, options: {})
  @concourse_uri = URI(concourse_uri)
  @username = username
  @password = password
  @options = options
  @base_uri = @concourse_uri.merge(API_BASE_PATH)
end

Instance Attribute Details

#base_uriObject (readonly)

Returns the value of attribute base_uri.



11
12
13
# File 'lib/concourse/client.rb', line 11

def base_uri
  @base_uri
end

Instance Method Details

#get(path) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/concourse/client.rb', line 21

def get(path)
  path = path[1..-1] if path.start_with?('/')

  begin
    options_with_auth = if authenticated?
                          options.merge('Cookie' => "ATC-Authorization=\"#{bearer_token}\"")
                        else
                          options
                        end

    open(base_uri.merge(path), options_with_auth).read
  rescue OpenURI::HTTPError => e
    if e.message == '401 Unauthorized' && @bearer_token
      @bearer_token = nil
      retry
    else
      raise
    end
  end
end