Class: HubSsoLib::Trust

Inherits:
Object
  • Object
show all
Defined in:
lib/hub_sso_lib.rb

Overview

Class: Trust #

#

Purpose: Allow other applications to call into the Hub Rails #

application to tell it about untrusted user operations.    #
The application can then store the details, e-mail         #
moderators and in due course call back to the originating  #
other application to move the user action forwards.        #
                                                           #
The external API is HubSsoLib::Trust::Server, implemented  #
by the Hub Rails application, not this gem.                #
                                                           #

Author: A.D.Hodgkinson #

#

History: 19-Mar-2025 (ADH): Created #

Class Method Summary collapse

Class Method Details

.already_running?Boolean

Is the server already running?

Returns:

  • (Boolean)


923
924
925
926
927
928
# File 'lib/hub_sso_lib.rb', line 923

def self.already_running?
  uri  = self.get_trust_server_connection_uri()
  path = URI.parse(uri).path

  return File.exist?(path)
end

.get_trust_objectObject

Obtain a connection to the trust server. This is called by any client code that needs to talk to the server which must, at the time called, be running via startup within the Hub Rails application.

The returned object is an instance of ::HubSsoLib::Trust::Server, which is defined inside the Hub Rails application. See there for details.



962
963
964
965
966
967
968
969
970
971
972
973
974
# File 'lib/hub_sso_lib.rb', line 962

def self.get_trust_object
  HUB_MUTEX.synchronize do
    begin
      DRb.current_server
    rescue DRb::DRbServerNotFound
      DRb.start_service()
    end

    @@trust_object ||= DRbObject.new_with_uri(self.get_trust_server_connection_uri())
  end

  return @@trust_object
end

.get_trust_server_connection_uriObject

Return the DRb endpoint URI for the trust server.



917
918
919
# File 'lib/hub_sso_lib.rb', line 917

def self.get_trust_server_connection_uri
  HUB_TRUST_CONNECTION_URI
end

.launch_serverObject

Start the trust server. This should only ever be called by the Hub Rails application, which implements HubSsoLib::Trust::Server.



933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
# File 'lib/hub_sso_lib.rb', line 933

def self.launch_server
  uri             = self.get_trust_server_connection_uri()
  already_running = self.already_running?

  unless ENV['HUB_QUIET_SERVER'] == 'yes'
    message = unless already_running
      "Trust server: Starting at #{ uri }"
    else
      "Trust server: Already running at at #{ uri }"
    end

    puts message
  end

  unless already_running
    loop do
      DRb.start_service(uri, ::HubSsoLib::Trust::Server.new)
      DRb.thread.join # Keep the thread alive...
    end               # ...but auto-restart if e.g. DRb.stop_service() is invoked
  end
end