Class: OpenC3::ScriptServerProxy

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

Overview

Provides a proxy to the Script Runner Api which communicates with the API server

Instance Method Summary collapse

Constructor Details

#initializeScriptServerProxy

Create a JsonDRbObject connection to the API server



272
273
274
275
276
277
278
# File 'lib/openc3/script/script.rb', line 272

def initialize
  @json_api = JsonApiObject.new(
    url: generate_url(),
    timeout: generate_timeout(),
    authentication: generate_auth()
  )
end

Instance Method Details

#generate_authObject

generate the auth object



263
264
265
266
267
268
269
# File 'lib/openc3/script/script.rb', line 263

def generate_auth
  if ENV['OPENC3_API_USER'].nil?
    return OpenC3Authentication.new()
  else
    return OpenC3KeycloakAuthentication.new(ENV['OPENC3_KEYCLOAK_URL'])
  end
end

#generate_timeoutObject

pull openc3-cmd-tlm-api timeout from environment variables



257
258
259
260
# File 'lib/openc3/script/script.rb', line 257

def generate_timeout
  timeout = ENV['OPENC3_SCRIPT_API_TIMEOUT'] || '5.0'
  return timeout.to_f
end

#generate_urlObject

pull openc3-script-runner-api url from environment variables



248
249
250
251
252
253
254
# File 'lib/openc3/script/script.rb', line 248

def generate_url
  schema = ENV['OPENC3_SCRIPT_API_SCHEMA'] || 'http'
  hostname = ENV['OPENC3_SCRIPT_API_HOSTNAME'] || (ENV['OPENC3_DEVEL'] ? '127.0.0.1' : 'openc3-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



284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/openc3/script/script.rb', line 284

def request(*method_params, **kw_params)
  kw_params[:scope] = $openc3_scope unless kw_params[:scope]
  if $disconnect
    result = nil
    # If :disconnect is there delete it and return the value
    # If it is not there, delete returns nil
    disconnect = kw_params.delete(:disconnect)

    # If they overrode the return value using the disconnect keyword then return that
    return disconnect ? disconnect : result
  else
    @json_api.request(*method_params, **kw_params)
  end
end

#shutdownObject



280
281
282
# File 'lib/openc3/script/script.rb', line 280

def shutdown
  @json_api.shutdown
end