OpenC3 / cosmos

OpenC3 COSMOS
https://openc3.com
Other
103 stars 30 forks source link

Add Additional Whitelisted Functions To ScriptRunner #445

Closed jeffstjean closed 1 year ago

jeffstjean commented 1 year ago

Is your feature request related to a problem? Please describe. I would like to be able to access functionality that I've created in a Microservice via the ScriptRunner.

Describe the solution you'd like A Microservice can add functions to the API module's WHITELIST as follows:

module CustomMicroservice
  OpenC3::Api::WHITELIST ||= []
  OpenC3::Api::WHITELIST.concat("custom_method")

  def custom_method(scope: $openc3_scope, token: $openc3_token)
    authorize(permission: 'system', scope: scope, token: token)
    return "some results"
  end
end

and this could be used in the ScriptRunner:

puts(custom_method())

I do believe this will have some issues with namespacing and need some additional logic in api.rb/script.rb to ensure the files are included and the methods added as proxies. However, I think this would be a pretty powerful addition to the ScriptRunner

ryanmelt commented 1 year ago

We have the ability to add entirely new APIs running in microservices now. See: https://github.com/openc3/openc3-cosmos-cfdp for a great example. More documentation coming soon.