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

#event_listenerEventListener?

Return event listener.

If the service does not support SSE, this function will return nil.

Returns:



73
74
75
76
77
78
# File 'lib/redfish_client/root.rb', line 73

def event_listener
  address = dig("EventService", "ServerSentEventUri")
  return nil if address.nil?

  EventListener.new(ServerSentEvents.create_client(address))
end

#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



53
54
55
56
57
# File 'lib/redfish_client/root.rb', line 53

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:



64
65
66
# File 'lib/redfish_client/root.rb', line 64

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



31
32
33
34
35
36
37
38
39
# File 'lib/redfish_client/root.rb', line 31

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.



44
45
46
47
# File 'lib/redfish_client/root.rb', line 44

def logout
  session_logout
  basic_logout
end