Class: OpenC3::ScriptServerProxy
Overview
Provides a proxy to the Script Runner Api which communicates with the API server
Instance Method Summary collapse
-
#generate_auth ⇒ Object
generate the auth object.
-
#generate_timeout ⇒ Object
pull openc3-cosmos-script-runner-api timeout from environment variables.
-
#generate_url ⇒ Object
pull openc3-cosmos-script-runner-api url from environment variables.
-
#initialize ⇒ ScriptServerProxy
constructor
Create a JsonDRbObject connection to the API server.
- #request(*method_params, **kw_params) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize ⇒ ScriptServerProxy
Create a JsonDRbObject connection to the API server
320 321 322 323 324 325 326 |
# File 'lib/openc3/script/script.rb', line 320 def initialize @json_api = JsonApiObject.new( url: generate_url(), timeout: generate_timeout(), authentication: generate_auth() ) end |
Instance Method Details
#generate_auth ⇒ Object
generate the auth object
307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/openc3/script/script.rb', line 307 def generate_auth if ENV['OPENC3_API_TOKEN'].nil? and ENV['OPENC3_API_USER'].nil? if ENV['OPENC3_API_PASSWORD'] return OpenC3Authentication.new() else return nil end else return OpenC3KeycloakAuthentication.new(ENV['OPENC3_KEYCLOAK_URL']) end end |
#generate_timeout ⇒ Object
pull openc3-cosmos-script-runner-api timeout from environment variables
301 302 303 304 |
# File 'lib/openc3/script/script.rb', line 301 def generate_timeout timeout = ENV['OPENC3_SCRIPT_API_TIMEOUT'] || '5.0' return timeout.to_f end |
#generate_url ⇒ Object
pull openc3-cosmos-script-runner-api url from environment variables
292 293 294 295 296 297 298 |
# File 'lib/openc3/script/script.rb', line 292 def generate_url schema = ENV['OPENC3_SCRIPT_API_SCHEMA'] || 'http' hostname = ENV['OPENC3_SCRIPT_API_HOSTNAME'] || (ENV['OPENC3_DEVEL'] ? '127.0.0.1' : 'openc3-cosmos-script-runner-api') port = ENV['OPENC3_SCRIPT_API_PORT'] || '2902' port = port.to_i return "#{schema}://#{hostname}:#{port}" end |
#request(*method_params, **kw_params) ⇒ Object
332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/openc3/script/script.rb', line 332 def request(*method_params, **kw_params) kw_params[:scope] = $openc3_scope unless kw_params[:scope] # If :disconnect is there delete it and return the value # If it is not there, delete returns nil disconnect = kw_params.delete(:disconnect) if $disconnect and disconnect # If they overrode the return value using the disconnect keyword then return that return disconnect else @json_api.request(*method_params, **kw_params) end end |
#shutdown ⇒ Object
328 329 330 |
# File 'lib/openc3/script/script.rb', line 328 def shutdown @json_api.shutdown end |