Class: TrainPlugins::Rest::Redfish

Inherits:
AuthHandler show all
Defined in:
lib/train-rest/auth_handler/redfish.rb

Overview

Authentication and Session handling for the Redfish 1.0 API

Instance Attribute Summary

Attributes inherited from AuthHandler

#connection, #options

Instance Method Summary collapse

Methods inherited from AuthHandler

#auth_parameters, descendants, #initialize, name, #process, #process_error, #renew_session, #renewal_needed?, #signature_based?

Constructor Details

This class inherits a constructor from TrainPlugins::Rest::AuthHandler

Instance Method Details

#auth_headersObject



38
39
40
41
42
# File 'lib/train-rest/auth_handler/redfish.rb', line 38

def auth_headers
  return {} unless @session_token

  { "X-Auth-Token": @session_token }
end

#check_optionsObject

Raises:

  • (ArgumentError)


9
10
11
12
# File 'lib/train-rest/auth_handler/redfish.rb', line 9

def check_options
  raise ArgumentError.new("Need username for Redfish authentication") unless options[:username]
  raise ArgumentError.new("Need password for Redfish authentication") unless options[:password]
end

#loginObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/train-rest/auth_handler/redfish.rb', line 14

def 
  response = connection.post(
    ,
    headers: {
      "Content-Type" => "application/json",
      "OData-Version" => "4.0",
    },
    data: {
      "UserName" => options[:username],
      "Password" => options[:password],
    }
  )

  @session_token = response.headers["x-auth-token"].first
  @logout_url = response.headers["location"].first

rescue ::RestClient::RequestFailed => err
  raise StandardError.new("Authentication with Redfish failed: " + err.message)
end

#logoutObject



34
35
36
# File 'lib/train-rest/auth_handler/redfish.rb', line 34

def logout
  connection.delete(@logout_url)
end