class TrainPlugins::Rest::Redfish

Authentication and Session handling for the Redfish 1.0 API

@see www.dmtf.org/standards/redfish

Public Instance Methods

auth_headers() click to toggle source
# File lib/train-rest/auth_handler/redfish.rb, line 38
def auth_headers
  return {} unless @session_token

  { "X-Auth-Token": @session_token }
end
check_options() click to toggle source
# 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
login() click to toggle source
# File lib/train-rest/auth_handler/redfish.rb, line 14
def login
  response = connection.post(
    login_url,
    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
logout() click to toggle source
# File lib/train-rest/auth_handler/redfish.rb, line 34
def logout
  connection.delete(@logout_url)
end

Private Instance Methods

login_url() click to toggle source

Prepend the RedFish base, if not a global setting in the connection URL

# File lib/train-rest/auth_handler/redfish.rb, line 47
def login_url
  return "SessionService/Sessions/" if options[:endpoint].include?("redfish/v1")

  "redfish/v1/SessionService/Sessions/"
end