Class: Rancher::Client

Inherits:
Object
  • Object
show all
Includes:
Authentication, Classify, Configurable, Connection
Defined in:
lib/rancher/client.rb

Overview

The Main Client for talking with Rancher

Constant Summary collapse

CONVENIENCE_HEADERS =

Header keys that can be passed in options hash to Rancher::Connection#get,Rancher::Connection#head

Set.new([:accept, :content_type])

Instance Attribute Summary collapse

Attributes included from Configurable

#access_key, #api_endpoint, #connection_options, #default_media_type, #middleware, #proxy, #secret_key, #user_agent

Instance Method Summary collapse

Methods included from Classify

#classify

Methods included from Connection

#agent, #delete, #get, #head, #last_response, #paginate, #patch, #post, #put, #root

Methods included from Authentication

#basic_authenticated?

Methods included from Configurable

#configure, keys, #reset!, #same_options?

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rancher/client.rb', line 20

def initialize(options = {})
  # Use options passed in, but fall back to module defaults
  @types = {}
  Rancher::Configurable.keys.each do |key|
    instance_variable_set(
      :"@#{key}",
      options[key] || Rancher.instance_variable_get(:"@#{key}")
    )
  end

  load_schema
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



74
75
76
77
78
# File 'lib/rancher/client.rb', line 74

def method_missing(method_name, *args, &block)
  return @types[method_name] if respond_to?(method_name)

  super
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



15
16
17
# File 'lib/rancher/client.rb', line 15

def types
  @types
end

Instance Method Details

#access_key=(value) ⇒ Object

Set Rancher access_key

Parameters:

  • value (String)

    Rancher access_key



57
58
59
60
# File 'lib/rancher/client.rb', line 57

def access_key=(value)
  reset_agent
  @access_key = value
end

#inspectString

Text representation of the client, masking tokens and passwords

Returns:

  • (String)


44
45
46
47
48
49
50
51
52
# File 'lib/rancher/client.rb', line 44

def inspect
  inspected = super

  if @secret_key
    inspected = inspected.gsub! @secret_key, "#{'*'*36}#{@secret_key[36..-1]}"
  end

  inspected
end

#load_schemaObject



33
34
35
36
37
38
39
# File 'lib/rancher/client.rb', line 33

def load_schema
  response = get 'schema'

  response.each do |res|
    @types[res.get_id.to_sym] = Rancher::Type.new(res)
  end if response.is_a?(Rancher::Collection)
end

#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/rancher/client.rb', line 70

def respond_to_missing?(method_name, _include_private = false)
  (@types.key?(method_name))
end

#secret_key=(value) ⇒ Object

Set Rancher secret_key

Parameters:

  • value (String)

    Rancher secret_key



65
66
67
68
# File 'lib/rancher/client.rb', line 65

def secret_key=(value)
  reset_agent
  @secret_key = value
end