diff --git a/openc3-cosmos-cmd-tlm-api/app/controllers/api_controller.rb b/openc3-cosmos-cmd-tlm-api/app/controllers/api_controller.rb index d1dc15b542..d4306e2afb 100644 --- a/openc3-cosmos-cmd-tlm-api/app/controllers/api_controller.rb +++ b/openc3-cosmos-cmd-tlm-api/app/controllers/api_controller.rb @@ -23,13 +23,16 @@ require 'openc3/utilities/open_telemetry' class ApiController < ApplicationController + def ping + render plain: 'OK' + end def api OpenC3.in_span('jsonrpc_api') do |span| req = Rack::Request.new(request.env) if request.post? - request_headers = Hash[*request.env.select {|k,v| k.start_with? 'HTTP_'}.sort.flatten] + request_headers = Hash[*request.env.select {|k,_v| k.start_with? 'HTTP_'}.sort.flatten] request_data = req.body.read span.add_attributes({ "request_data" => request_data }) if span and request_data.length <= 1000 status = nil @@ -40,7 +43,7 @@ def api OpenC3::Logger.info("API data: #{request_data}", scope: nil, user: username()) OpenC3::Logger.debug("API headers: #{request_headers}", scope: nil, user: username()) status, content_type, body = handle_post(request_data, request_headers) - rescue OpenC3::AuthError => error + rescue OpenC3::AuthError => e id = 1 begin parsed = JSON.parse(request_data, :allow_nan => true) @@ -50,7 +53,7 @@ def api end error_code = OpenC3::JsonRpcError::ErrorCode::AUTH_ERROR response = OpenC3::JsonRpcErrorResponse.new( - OpenC3::JsonRpcError.new(error_code, error.message, error), id + OpenC3::JsonRpcError.new(error_code, e.message, e), id ) status = 401 content_type = "application/json-rpc" @@ -94,15 +97,17 @@ def handle_post(request_data, request_headers) # see http://www.jsonrpc.org/historical/json-rpc-over-http.html#errors if error_code case error_code - when OpenC3::JsonRpcError::ErrorCode::PARSE_ERROR then status = 500 # Internal server error when OpenC3::JsonRpcError::ErrorCode::INVALID_REQUEST then status = 400 # Bad request + when OpenC3::JsonRpcError::ErrorCode::AUTH_ERROR then status = 401 # Auth + when OpenC3::JsonRpcError::ErrorCode::FORBIDDEN_ERROR then status = 403 # Forbidden when OpenC3::JsonRpcError::ErrorCode::METHOD_NOT_FOUND then status = 404 # Not found - when OpenC3::JsonRpcError::ErrorCode::INVALID_PARAMS then status = 500 # Internal server error - when OpenC3::JsonRpcError::ErrorCode::INTERNAL_ERROR then status = 500 # Internal server error - when OpenC3::JsonRpcError::ErrorCode::AUTH_ERROR then status = 401 - when OpenC3::JsonRpcError::ErrorCode::FORBIDDEN_ERROR then status = 403 when OpenC3::JsonRpcError::ErrorCode::HAZARDOUS_ERROR then status = 409 # Server conflict - else status = 500 # Internal server error + else + # Also includes the following errors: + # OpenC3::JsonRpcError::ErrorCode::PARSE_ERROR + # OpenC3::JsonRpcError::ErrorCode::INVALID_PARAMS + # OpenC3::JsonRpcError::ErrorCode::INTERNAL_ERROR + status = 500 # Internal server error end # Note we don't log an error here because it's logged in JsonDRb::process_request else diff --git a/openc3-cosmos-cmd-tlm-api/config/routes.rb b/openc3-cosmos-cmd-tlm-api/config/routes.rb index 3ba66ec88a..156c76d631 100644 --- a/openc3-cosmos-cmd-tlm-api/config/routes.rb +++ b/openc3-cosmos-cmd-tlm-api/config/routes.rb @@ -181,6 +181,7 @@ delete '/secrets/:key', to: 'secrets#destroy', key: /[^\/]+/ post "/api" => "api#api" + get "/ping" => "api#ping" get "/auth/token-exists" => "auth#token_exists" post "/auth/verify" => "auth#verify" diff --git a/openc3-cosmos-script-runner-api/app/controllers/scripts_controller.rb b/openc3-cosmos-script-runner-api/app/controllers/scripts_controller.rb index ca402b57ed..a6a6e82794 100644 --- a/openc3-cosmos-script-runner-api/app/controllers/scripts_controller.rb +++ b/openc3-cosmos-script-runner-api/app/controllers/scripts_controller.rb @@ -33,6 +33,10 @@ class ScriptsController < ApplicationController SUITE_REGEX = /^\s*class\s+\w+\s+<\s+(Cosmos::|OpenC3::)?(Suite|TestSuite)/ PYTHON_SUITE_REGEX = /^\s*class\s+\w+\s*\(\s*(Suite|TestSuite)\s*\)/ + def ping + render plain: 'OK' + end + def index return unless authorization('script_view') render :json => Script.all(params[:scope]) @@ -48,7 +52,6 @@ def body file = Script.body(params[:scope], params[:name]) if file - success = true locked = Script.locked?(params[:scope], params[:name]) unless locked Script.lock(params[:scope], params[:name], username()) diff --git a/openc3-cosmos-script-runner-api/config/routes.rb b/openc3-cosmos-script-runner-api/config/routes.rb index c55c6ccf00..e84a3e9ee7 100644 --- a/openc3-cosmos-script-runner-api/config/routes.rb +++ b/openc3-cosmos-script-runner-api/config/routes.rb @@ -1,5 +1,6 @@ Rails.application.routes.draw do scope "script-api" do + get "/ping" => "scripts#ping" get "/scripts" => "scripts#index" delete "/scripts/temp_files" => "scripts#delete_temp" get "/scripts/*name" => "scripts#body", format: false, defaults: { format: 'html' }