Class: RedfishClient::Root

Inherits:
Resource show all
Defined in:
lib/redfish_client/root.rb

Overview

Root resource represents toplevel entry point into Redfish service data. Its main purpose is to provide authentication support for the API.

Defined Under Namespace

Classes: AuthError

Constant Summary collapse

BASIC_AUTH_HEADER =

Basic and token authentication headers.

"Authorization"
TOKEN_AUTH_HEADER =
"X-Auth-Token"

Instance Attribute Summary

Attributes inherited from Resource

#headers

Instance Method Summary collapse

Methods inherited from Resource

#[], #delete, #dig, #initialize, #key?, #method_missing, #patch, #post, #raw, #reset, #respond_to_missing?, #to_s

Constructor Details

This class inherits a constructor from RedfishClient::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RedfishClient::Resource

Instance Method Details

#find(oid) ⇒ Resource?

Find Redfish service object by OData ID field.

Parameters:

  • oid (String)

    Odata id of the resource

Returns:

  • (Resource, nil)

    new resource or nil if resource cannot be found



50
51
52
53
54
# File 'lib/redfish_client/root.rb', line 50

def find(oid)
  find!(oid)
rescue NoResource
  nil
end

#find!(oid) ⇒ Resource

Find Redfish service object by OData ID field.

Parameters:

  • oid (String)

    Odata id of the resource

Returns:

Raises:



61
62
63
# File 'lib/redfish_client/root.rb', line 61

def find!(oid)
  Resource.new(@connector, oid: oid)
end

#login(username, password) ⇒ Object

Authenticate against the service.

Calling this method will try to create new session on the service using provided credentials. If the session creation fails, basic authentication will be attempted. If basic authentication fails, AuthError will be raised.

Parameters:

  • username (String)

    username

  • password (String)

    password

Raises:

  • (AuthError)

    if user session could not be created



28
29
30
31
32
33
34
35
36
# File 'lib/redfish_client/root.rb', line 28

def (username, password)
  # Since session auth is more secure, we try it first and use basic auth
  # only if session auth is not available.
  if 
    (username, password)
  else
    (username, password)
  end
end

#logoutObject

Sign out of the service.

If the session could not be deleted, AuthError will be raised.



41
42
43
44
# File 'lib/redfish_client/root.rb', line 41

def logout
  session_logout
  basic_logout
end