@@ -64,9 +64,6 @@ class Faspex < Aspera::Rest
6464 PATH_AUTH = 'auth'
6565 PATH_API_V5 = 'api/v5'
6666 PATH_HEALTH = 'configuration/ping'
67- private_constant :PATH_AUTH ,
68- :PATH_API_V5 ,
69- :PATH_HEALTH
7067 RECIPIENT_TYPES = %w[ user workgroup external_user distribution_list shared_inbox ] . freeze
7168 PACKAGE_TERMINATED = %w[ completed failed ] . freeze
7269 # list of supported mailbox types (to list packages)
@@ -152,6 +149,7 @@ def box_type(box)
152149 def initialize (
153150 url :,
154151 auth :,
152+ root : PATH_API_V5 ,
155153 password : nil ,
156154 client_id : nil ,
157155 client_secret : nil ,
@@ -165,23 +163,23 @@ def initialize(
165163 super ( **
166164 case auth
167165 when :public_link
168- # Get URL of final redirect of public link
169- redir_url = Rest . new ( base_url : url , redirect_max : 3 ) . call ( operation : 'GET' , ret : :resp ) . uri . to_s
170- Log . dump ( :redir_url , redir_url , level : :trace1 )
171- # get context from query
172- encoded_context = Rest . query_to_h ( URI . parse ( redir_url ) . query ) [ 'context' ]
166+ # Get URL of final redirect of provided public link
167+ final_url = Rest . new ( base_url : url , redirect_max : 3 ) . call ( operation : 'GET' , ret : :resp ) . uri . to_s
168+ Log . dump ( :final_url , final_url , level : :trace1 )
169+ # Get context from query
170+ encoded_context = Rest . query_to_h ( URI . parse ( final_url ) . query ) [ 'context' ]
173171 raise ParameterError , 'Bad faspex5 public link, missing context in query' if encoded_context . nil?
174172 # public link information (contains passcode and allowed usage)
175173 @pub_link_context = JSON . parse ( Base64 . decode64 ( encoded_context ) )
176174 Log . dump ( :pub_link_context , @pub_link_context , level : :trace1 )
177175 # Get the base url, i.e. .../aspera/faspex
178- base_url = redir_url . gsub ( %r{/public/.*} , '' ) . gsub ( /\? .*/ , '' )
176+ base_url = final_url . gsub ( %r{/public/.*} , '' ) . gsub ( /\? .*/ , '' )
179177 # Get web UI client_id and redirect_uri
180178 # TODO: change this for something more reliable
181179 config = JSON . parse ( Rest . new ( base_url : "#{ base_url } /config.js" , redirect_max : 3 ) . call ( operation : 'GET' ) . sub ( /^[^=]+=/ , '' ) . gsub ( /([a-z_]+):/ , '"\1":' ) . delete ( "\n " ) . tr ( "'" , '"' ) ) . symbolize_keys
182- Log . dump ( :configjs , config )
180+ Log . dump ( :config_js , config )
183181 {
184- base_url : "#{ base_url } /#{ PATH_API_V5 } " ,
182+ base_url : "#{ base_url } /#{ root } " ,
185183 auth : {
186184 type : :oauth2 ,
187185 base_url : "#{ base_url } /#{ PATH_AUTH } " ,
@@ -198,15 +196,15 @@ def initialize(
198196 Aspera . assert ( password , type : ParameterError ) { 'Missing password' }
199197 # the password here is the token copied directly from browser in developer mode
200198 {
201- base_url : "#{ url } /#{ PATH_API_V5 } " ,
199+ base_url : "#{ url } /#{ root } " ,
202200 headers : { 'Authorization' => password }
203201 }
204202 when :web
205203 Aspera . assert ( client_id , type : ParameterError ) { 'Missing client_id' }
206204 Aspera . assert ( redirect_uri , type : ParameterError ) { 'Missing redirect_uri' }
207205 # opens a browser and ask user to auth using web
208206 {
209- base_url : "#{ url } /#{ PATH_API_V5 } " ,
207+ base_url : "#{ url } /#{ root } " ,
210208 auth : {
211209 type : :oauth2 ,
212210 base_url : "#{ url } /#{ PATH_AUTH } " ,
@@ -221,7 +219,7 @@ def initialize(
221219 Aspera . assert ( client_id , type : ParameterError ) { 'Missing client_id' }
222220 Aspera . assert ( private_key , type : ParameterError ) { 'Missing private_key' }
223221 {
224- base_url : "#{ url } /#{ PATH_API_V5 } " ,
222+ base_url : "#{ url } /#{ root } " ,
225223 auth : {
226224 type : :oauth2 ,
227225 base_url : "#{ url } /#{ PATH_AUTH } " ,
@@ -242,10 +240,6 @@ def initialize(
242240 end
243241 )
244242 end
245-
246- def auth_api
247- Rest . new ( **params , base_url : base_url . sub ( PATH_API_V5 , PATH_AUTH ) )
248- end
249243 end
250244 end
251245end
0 commit comments