Class: TrainPlugins::Rest::Redfish
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, #renew_session, #renewal_needed?
Instance Method Details
38
39
40
41
42
|
# File 'lib/train-rest/auth_handler/redfish.rb', line 38
def
return {} unless @session_token
{ "X-Auth-Token": @session_token }
end
|
#check_options ⇒ Object
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
|
#login ⇒ Object
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 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.["x-auth-token"].first
@logout_url = response.["location"].first
rescue ::RestClient::RequestFailed => err
raise StandardError.new("Authentication with Redfish failed: " + err.message)
end
|
#logout ⇒ Object
34
35
36
|
# File 'lib/train-rest/auth_handler/redfish.rb', line 34
def logout
connection.delete(@logout_url)
end
|