Module: Salt::Api::Client

Included in:
Salt::Api
Defined in:
lib/salt/api/client.rb

Instance Method Summary collapse

Instance Method Details

#clientObject



7
8
9
10
11
12
13
14
# File 'lib/salt/api/client.rb', line 7

def client
  Net::HTTP.new(hostname, port).tap do |client|
    client.use_ssl = use_ssl
    client.open_timeout = timeout
    # TODO: Allow specifying CA and such
    client.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
end

#loginObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/salt/api/client.rb', line 16

def 
  req = Net::HTTP::Post.new("/login")
  req.set_form_data({
    'eauth' => 'pam',
    'username' => username,
    'password' => password
  })
  req['Accept'] = "application/x-yaml"
  resp = client.request(req)
  raise "Login failed" unless resp.kind_of? Net::HTTPSuccess
  parsed_resp = YAML.load(resp.body)["return"]
  raise "Multiple results? (#{parsed_resp.inspect})" if parsed_resp.length > 1
  parsed_resp.first
end

#tokenObject



31
32
33
# File 'lib/salt/api/client.rb', line 31

def token
  @token ||= ["token"]
end