Class: Aspera::Faspex4GWServlet
- Inherits:
-
WEBrick::HTTPServlet::AbstractServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- Aspera::Faspex4GWServlet
- Defined in:
- lib/aspera/faspex_gw.rb
Overview
Simulate the Faspex 4 /send API and creates a package on Aspera on Cloud or Faspex 5
Instance Method Summary collapse
- #do_POST(request, response) ⇒ Object
-
#faspex4_send_to_aoc(faspex_pkg_parameters) ⇒ Object
Map Faspex 4 /send API to AoC package create parameters from user to Faspex API call developer.ibm.com/apis/catalog/aspera–aspera-faspex-client-sdk/Sending%20Packages%20(API%20v.3).
- #faspex4_send_to_faspex5(faspex_pkg_parameters) ⇒ Object
-
#initialize(server, app_api, app_context) ⇒ Faspex4GWServlet
constructor
A new instance of Faspex4GWServlet.
Constructor Details
#initialize(server, app_api, app_context) ⇒ Faspex4GWServlet
Returns a new instance of Faspex4GWServlet.
13 14 15 16 17 18 |
# File 'lib/aspera/faspex_gw.rb', line 13 def initialize(server, app_api, app_context) Aspera.assert_values(app_api.class.name, ['Aspera::Api::AoC', 'Aspera::Rest']) super(server) @app_api = app_api @app_context = app_context end |
Instance Method Details
#do_POST(request, response) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/aspera/faspex_gw.rb', line 65 def do_POST(request, response) case request.path when '/aspera/faspex/send' begin raise 'no payload' if request.body.nil? faspex_pkg_parameters = JSON.parse(request.body) Log.log.debug{"faspex pkg create parameters=#{faspex_pkg_parameters}"} # compare string, as class is not yet known here faspex_package_create_result = case @app_api.class.name when 'Aspera::Api::AoC' faspex4_send_to_aoc(faspex_pkg_parameters) when 'Aspera::Rest' faspex4_send_to_faspex5(faspex_pkg_parameters) else Aspera.error_unexpected_value(@app_api.class.name) end Log.log.info{"faspex_package_create_result=#{faspex_package_create_result}"} response.status = 200 response.content_type = 'application/json' response.body = JSON.generate(faspex_package_create_result) rescue => e response.status = 500 response['Content-Type'] = 'application/json' response.body = {error: e.}.to_json Log.log.error(e.) Log.log.debug{e.backtrace.join("\n")} end else response.status = 400 response['Content-Type'] = 'application/json' response.body = {error: 'Unsupported endpoint'}.to_json end end |
#faspex4_send_to_aoc(faspex_pkg_parameters) ⇒ Object
Map Faspex 4 /send API to AoC package create parameters from user to Faspex API call developer.ibm.com/apis/catalog/aspera–aspera-faspex-client-sdk/Sending%20Packages%20(API%20v.3)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/aspera/faspex_gw.rb', line 23 def faspex4_send_to_aoc(faspex_pkg_parameters) faspex_pkg_delivery = faspex_pkg_parameters['delivery'] package_data = { # 'file_names' => faspex_pkg_delivery['sources'][0]['paths'], 'name' => faspex_pkg_delivery['title'], 'note' => faspex_pkg_delivery['note'], 'recipients' => faspex_pkg_delivery['recipients'], 'workspace_id' => @app_context } created_package = @app_api.create_package_simple(package_data, true, nil) # but we place it in a Faspex package creation response return { 'links' => { 'status' => 'unused' }, 'xfer_sessions' => [created_package[:spec]] } end |
#faspex4_send_to_faspex5(faspex_pkg_parameters) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/aspera/faspex_gw.rb', line 40 def faspex4_send_to_faspex5(faspex_pkg_parameters) faspex_pkg_delivery = faspex_pkg_parameters['delivery'] package_data = { 'title' => faspex_pkg_delivery['title'], 'note' => faspex_pkg_delivery['note'], 'recipients' => faspex_pkg_delivery['recipients'].map{|name|{'name'=>name}} } package = @app_api.create('packages', package_data)[:data] # TODO: option to send from remote source or httpgw transfer_spec = @app_api.call( operation: 'POST', subpath: "packages/#{package['id']}/transfer_spec/upload", headers: {'Accept' => 'application/json'}, query: {transfer_type: Cli::Plugins::Faspex5::TRANSFER_CONNECT}, body: {paths: [{'destination'=>'/'}]}, body_type: :json )[:data] transfer_spec.delete('authentication') # but we place it in a Faspex package creation response return { 'links' => { 'status' => 'unused' }, 'xfer_sessions' => [transfer_spec] } end |