Merge pull request #3414 from okriuchykhin/ok_SCI_5843

Add biomolecular toolkit API proxying endpoint [SCI-5843]
This commit is contained in:
Alex Kriuchykhin 2021-07-21 13:14:04 +02:00 committed by GitHub
commit e881bf32ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View file

@ -4,10 +4,10 @@ class BioEddieAssetsController < ApplicationController
include BioEddieActions
include ActiveStorage::SetCurrent
before_action :load_vars, except: :create
before_action :load_vars, except: %i(create bmt_request)
before_action :load_create_vars, only: :create
before_action :check_read_permission
before_action :check_read_permission, except: %i(update create start_editing bmt_request)
before_action :check_edit_permission, only: %i(update create start_editing)
def create
@ -43,6 +43,23 @@ class BioEddieAssetsController < ApplicationController
end
end
def bmt_request
return_404 unless ENV['BIOMOLECULE_TOOLKIT_BASE_URL']
uri = URI.parse(ENV['BIOMOLECULE_TOOLKIT_BASE_URL'])
uri.path = request.original_fullpath.remove('/biomolecule_toolkit')
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
api_request = "Net::HTTP::#{request.request_method.capitalize}".constantize.new(uri)
api_request['x-api-key'] = ENV['BIOMOLECULE_TOOLKIT_API_KEY'] if ENV['BIOMOLECULE_TOOLKIT_API_KEY']
api_request['Content-Type'] = 'application/json'
request_body = request.body.read
api_request.body = request_body if request_body.present?
api_response = http.request(api_request)
render body: api_response.body, content_type: api_response.content_type, status: api_response.code
end
end
def start_editing
create_edit_bio_eddie_activity(@asset, current_user, :start_editing)
end

View file

@ -779,6 +779,10 @@ Rails.application.routes.draw do
end
end
match 'biomolecule_toolkit/*path', to: 'bio_eddie_assets#bmt_request',
via: %i(get post put delete),
defaults: { format: 'json' }
post 'global_activities', to: 'global_activities#index'
constraints WopiSubdomain do