Sha256: 0ff7554375635689ddf3dd377252efc487d1180aec0a724e3ffb7f9c2c67e226

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

# encoding: ascii-8bit

# Copyright 2023 OpenC3, Inc.
# All Rights Reserved.
#
# Licensed for Evaluation and Educational Use
#
# This file may only be used commercially under the terms of a commercial license
# purchased from OpenC3, Inc.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# The development of this software was funded in-whole or in-part by MethaneSAT LLC.

require 'openc3/utilities/authorization'

class ApplicationController < ActionController::API
  include OpenC3::Authorization

  private

  # Authorize and rescue the possible execeptions
  # @return [Boolean] true if authorize successful
  def authorization(permission, target_name: nil, packet_name: nil, interface_name: nil, router_name: nil)
    begin
      authorize(
        permission: permission,
        target_name: target_name,
        packet_name: packet_name,
        interface_name: interface_name,
        router_name: router_name,
        scope: params[:scope],
        token: request.headers['HTTP_AUTHORIZATION'],
      )
    rescue OpenC3::AuthError => e
      render(json: { status: 'error', message: e.message }, status: 401) and
        return false
    rescue OpenC3::ForbiddenError => e
      render(json: { status: 'error', message: e.message }, status: 403) and
        return false
    end
    true
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
openc3-cosmos-cfdp-1.0.2 microservices/CFDP/app/controllers/application_controller.rb
openc3-cosmos-cfdp-1.0.1 microservices/CFDP/app/controllers/application_controller.rb
openc3-cosmos-cfdp-1.0.0 microservices/CFDP/app/controllers/application_controller.rb