aspera-cli 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +518 -137
- data/bin/dascli +13 -0
- data/docs/README.erb.md +473 -105
- data/docs/test_env.conf +4 -1
- data/docs/transfer_spec.html +1 -1
- data/lib/aspera/aoc.rb +68 -86
- data/lib/aspera/cli/formater.rb +2 -0
- data/lib/aspera/cli/main.rb +27 -19
- data/lib/aspera/cli/plugin.rb +9 -4
- data/lib/aspera/cli/plugins/alee.rb +1 -1
- data/lib/aspera/cli/plugins/aoc.rb +173 -136
- data/lib/aspera/cli/plugins/config.rb +80 -27
- data/lib/aspera/cli/plugins/console.rb +2 -2
- data/lib/aspera/cli/plugins/faspex.rb +13 -6
- data/lib/aspera/cli/plugins/faspex5.rb +93 -37
- data/lib/aspera/cli/plugins/node.rb +3 -3
- data/lib/aspera/cli/plugins/preview.rb +25 -24
- data/lib/aspera/cli/plugins/server.rb +23 -8
- data/lib/aspera/cli/transfer_agent.rb +1 -1
- data/lib/aspera/cli/version.rb +1 -1
- data/lib/aspera/fasp/connect.rb +28 -21
- data/lib/aspera/fasp/http_gw.rb +140 -28
- data/lib/aspera/fasp/installation.rb +28 -4
- data/lib/aspera/fasp/local.rb +24 -16
- data/lib/aspera/fasp/manager.rb +12 -0
- data/lib/aspera/fasp/node.rb +4 -4
- data/lib/aspera/fasp/parameters.rb +3 -16
- data/lib/aspera/log.rb +1 -1
- data/lib/aspera/node.rb +48 -1
- data/lib/aspera/oauth.rb +24 -11
- data/lib/aspera/persistency_folder.rb +9 -4
- data/lib/aspera/preview/file_types.rb +53 -21
- data/lib/aspera/preview/generator.rb +3 -3
- data/lib/aspera/rest.rb +38 -18
- data/lib/aspera/temp_file_manager.rb +19 -0
- metadata +37 -20
@@ -7,10 +7,12 @@ require 'aspera/aoc'
|
|
7
7
|
require 'aspera/proxy_auto_config'
|
8
8
|
require 'aspera/uri_reader'
|
9
9
|
require 'aspera/rest'
|
10
|
+
require 'aspera/persistency_action_once'
|
10
11
|
require 'xmlsimple'
|
11
12
|
require 'base64'
|
12
13
|
require 'net/smtp'
|
13
14
|
require 'open3'
|
15
|
+
require 'date'
|
14
16
|
|
15
17
|
module Aspera
|
16
18
|
module Cli
|
@@ -41,17 +43,19 @@ module Aspera
|
|
41
43
|
AOC_COMMAND_CURRENT=AOC_COMMAND_V3
|
42
44
|
CONNECT_WEB_URL = 'https://d3gcli72yxqn2z.cloudfront.net/connect'
|
43
45
|
CONNECT_VERSIONS = 'connectversions.js'
|
46
|
+
TRANSFER_SDK_ARCHIVE_URL = 'https://ibm.biz/aspera_sdk'
|
44
47
|
DEMO='demo'
|
48
|
+
AOC_PATH_API_CLIENTS='admin/api-clients'
|
45
49
|
def option_preset; nil; end
|
46
50
|
|
47
51
|
def option_preset=(value)
|
48
52
|
self.options.add_option_preset(preset_by_name(value))
|
49
53
|
end
|
50
54
|
|
51
|
-
private_constant :
|
55
|
+
private_constant :DEFAULT_CONFIG_FILENAME,:CONF_PRESET_CONFIG,:CONF_PRESET_VERSION,:CONF_PRESET_DEFAULT,:PROGRAM_NAME_V1,:PROGRAM_NAME_V2,:DEFAULT_REDIRECT,:ASPERA_PLUGINS_FOLDERNAME,:RUBY_FILE_EXT,:AOC_COMMAND_V1,:AOC_COMMAND_V2,:AOC_COMMAND_V3,:AOC_COMMAND_CURRENT,:DEMO,:TRANSFER_SDK_ARCHIVE_URL,:AOC_PATH_API_CLIENTS
|
52
56
|
attr_accessor :option_ak_secret,:option_secrets
|
53
57
|
|
54
|
-
def initialize(env,tool_name,help_url,version)
|
58
|
+
def initialize(env,tool_name,help_url,version,main_folder)
|
55
59
|
super(env)
|
56
60
|
@option_ak_secret=nil
|
57
61
|
@option_secrets={}
|
@@ -63,19 +67,11 @@ module Aspera
|
|
63
67
|
@program_version=version
|
64
68
|
@tool_name=tool_name
|
65
69
|
@help_url=help_url
|
66
|
-
|
67
|
-
if ENV.has_key?(tool_main_env_var)
|
68
|
-
@main_folder=ENV[tool_main_env_var]
|
69
|
-
else
|
70
|
-
user_home_folder=Dir.home
|
71
|
-
raise CliError,"Home folder does not exist: #{user_home_folder}. Check your user environment or use #{tool_main_env_var}." unless Dir.exist?(user_home_folder)
|
72
|
-
@main_folder=File.join(user_home_folder,ASPERA_HOME_FOLDER_NAME,tool_name)
|
73
|
-
end
|
70
|
+
@main_folder=main_folder
|
74
71
|
@conf_file_default=File.join(@main_folder,DEFAULT_CONFIG_FILENAME)
|
75
72
|
@option_config_file=@conf_file_default
|
76
73
|
Log.log.debug("#{tool_name} folder: #{@main_folder}")
|
77
74
|
# set folder for FASP SDK
|
78
|
-
Fasp::Installation.instance.folder=File.join(@main_folder,'sdk')
|
79
75
|
add_plugin_lookup_folder(File.join(@main_folder,ASPERA_PLUGINS_FOLDERNAME))
|
80
76
|
add_plugin_lookup_folder(self.class.gem_plugins_folder)
|
81
77
|
# do file parameter first
|
@@ -105,11 +101,18 @@ module Aspera
|
|
105
101
|
self.options.add_opt_simple(:default,"set as default configuration for specified plugin")
|
106
102
|
self.options.add_opt_simple(:secret,"access key secret for node")
|
107
103
|
self.options.add_opt_simple(:secrets,"access key secret for node")
|
104
|
+
self.options.add_opt_simple(:sdk_url,"URL to get SDK")
|
105
|
+
self.options.add_opt_simple(:sdk_folder,"SDK folder location")
|
108
106
|
self.options.add_opt_boolean(:test_mode,"skip user validation in wizard mode")
|
107
|
+
self.options.add_opt_simple(:version_check_days,Integer,"period to check neew version in days (zero to disable)")
|
109
108
|
self.options.set_option(:use_generic_client,true)
|
110
109
|
self.options.set_option(:test_mode,false)
|
110
|
+
self.options.set_option(:version_check_days,7)
|
111
|
+
self.options.set_option(:sdk_url,TRANSFER_SDK_ARCHIVE_URL)
|
112
|
+
self.options.set_option(:sdk_folder,File.join(@main_folder,'sdk'))
|
111
113
|
self.options.parse_options!
|
112
114
|
raise CliBadArgument,"secrets shall be Hash" unless @option_secrets.is_a?(Hash)
|
115
|
+
Fasp::Installation.instance.folder=self.options.get_option(:sdk_folder,:mandatory)
|
113
116
|
end
|
114
117
|
|
115
118
|
def get_secret(id=nil,mandatory=true)
|
@@ -122,6 +125,48 @@ module Aspera
|
|
122
125
|
return @option_secrets
|
123
126
|
end
|
124
127
|
|
128
|
+
def check_gem_version
|
129
|
+
this_gem_name=File.basename(File.dirname(self.class.gem_root)).gsub(/-[0-9].*$/,'')
|
130
|
+
latest_version=begin
|
131
|
+
Rest.new(base_url: "https://rubygems.org/api/v1").read("versions/#{this_gem_name}/latest.json")[:data]['version']
|
132
|
+
rescue
|
133
|
+
nil
|
134
|
+
end
|
135
|
+
return {name: this_gem_name,current: Aspera::Cli::VERSION, latest: latest_version, need_update: Gem::Version.new(Aspera::Cli::VERSION) < Gem::Version.new(latest_version)}
|
136
|
+
end
|
137
|
+
|
138
|
+
def periodic_check_newer_gem_version
|
139
|
+
# get verification period
|
140
|
+
delay_days=options.get_option(:version_check_days,:mandatory)
|
141
|
+
Log.log.info("check days: #{delay_days}")
|
142
|
+
# check only if not zero day
|
143
|
+
if !delay_days.eql?(0)
|
144
|
+
# get last date from persistency
|
145
|
+
last_check_array=[]
|
146
|
+
check_date_persist=PersistencyActionOnce.new(
|
147
|
+
manager: persistency,
|
148
|
+
data: last_check_array,
|
149
|
+
ids: ['version_last_check'])
|
150
|
+
# get persisted date or nil
|
151
|
+
last_check_date = begin
|
152
|
+
Date.strptime(last_check_array.first, "%Y/%m/%d")
|
153
|
+
rescue
|
154
|
+
nil
|
155
|
+
end
|
156
|
+
current_date=Date.today
|
157
|
+
Log.log.info("last check: #{last_check_date.class}")
|
158
|
+
if last_check_date.nil? or (current_date - last_check_date) > delay_days
|
159
|
+
Log.log.info("days elapsed #{last_check_date.is_a?(Date) ? current_date - last_check_date : last_check_date.class.name}")
|
160
|
+
last_check_array[0]=current_date.strftime("%Y/%m/%d")
|
161
|
+
check_date_persist.save
|
162
|
+
check_data=check_gem_version
|
163
|
+
if check_data[:need_update]
|
164
|
+
Log.log.warn("A new version is available: #{check_data[:latest]}. You have #{check_data[:current]}. Upgrade with: gem update #{check_data[:nname]}")
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
125
170
|
# retrieve structure from cloud (CDN) with all versions available
|
126
171
|
def connect_versions
|
127
172
|
if @connect_versions.nil?
|
@@ -452,8 +497,10 @@ module Aspera
|
|
452
497
|
end
|
453
498
|
# read PATHs from ascp directly, and pvcl modules as well
|
454
499
|
Open3.popen3(Fasp::Installation.instance.path(:ascp),'-DDL-') do |stdin, stdout, stderr, thread|
|
500
|
+
last_line=''
|
455
501
|
while line=stderr.gets do
|
456
502
|
line.chomp!
|
503
|
+
last_line=line
|
457
504
|
case line
|
458
505
|
when %r{^DBG Path ([^ ]+) (dir|file) +: (.*)$};data[$1]=$3
|
459
506
|
when %r{^DBG Added module group:"([^"]+)" name:"([^"]+)", version:"([^"]+)" interface:"([^"]+)"$};data[$2]=$4
|
@@ -462,6 +509,9 @@ module Aspera
|
|
462
509
|
when %r{^LOG Initializing FASP version ([^,]+),};data['ascp_version']=$1
|
463
510
|
end
|
464
511
|
end
|
512
|
+
if !thread.value.exitstatus.eql?(1) and !data.has_key?('root')
|
513
|
+
raise last_line
|
514
|
+
end
|
465
515
|
end
|
466
516
|
data['keypass']=Fasp::Installation.instance.bypass_pass
|
467
517
|
return {:type=>:single_object, :data=>data}
|
@@ -478,13 +528,13 @@ module Aspera
|
|
478
528
|
return {:type=>:status, :data=>"saved to default global preset #{preset_name}"}
|
479
529
|
end
|
480
530
|
when :install
|
481
|
-
v=Fasp::Installation.instance.install_sdk
|
531
|
+
v=Fasp::Installation.instance.install_sdk(self.options.get_option(:sdk_url,:mandatory))
|
482
532
|
return {:type=>:status, :data=>"Installed version #{v}"}
|
483
533
|
end
|
484
534
|
raise "unexpected case: #{command}"
|
485
535
|
end
|
486
536
|
|
487
|
-
ACTIONS=[:gem_path, :genkey,:plugins,:flush_tokens,:list,:overview,:open,:echo,:id,:documentation,:wizard,:export_to_cli,:detect,:coffee,:ascp,:email_test,:smtp_settings,:proxy_check,:folder,:file]
|
537
|
+
ACTIONS=[:gem_path, :genkey,:plugins,:flush_tokens,:list,:overview,:open,:echo,:id,:documentation,:wizard,:export_to_cli,:detect,:coffee,:ascp,:email_test,:smtp_settings,:proxy_check,:folder,:file,:check_update]
|
488
538
|
|
489
539
|
# "config" plugin
|
490
540
|
def execute_action
|
@@ -562,7 +612,9 @@ module Aspera
|
|
562
612
|
return Main.result_status("updated: #{config_name}")
|
563
613
|
end
|
564
614
|
when :documentation
|
565
|
-
|
615
|
+
section=options.get_next_argument('private key file path',:single,:optional)
|
616
|
+
section='#'+section unless section.nil?
|
617
|
+
OpenApplication.instance.uri("#{@help_url}#{section}")
|
566
618
|
return Main.result_nothing
|
567
619
|
when :open
|
568
620
|
OpenApplication.instance.uri("#{@option_config_file}") #file://
|
@@ -587,7 +639,6 @@ module Aspera
|
|
587
639
|
return {:type=>:object_list,:data=>self.class.flatten_all_config(@config_presets)}
|
588
640
|
when :wizard
|
589
641
|
self.options.ask_missing_mandatory=true
|
590
|
-
#self.options.set_option(:interactive,:yes)
|
591
642
|
# register url option
|
592
643
|
BasicAuthPlugin.new(@agents.merge(skip_option_header: true))
|
593
644
|
instance_url=self.options.get_option(:url,:mandatory)
|
@@ -624,12 +675,13 @@ module Aspera
|
|
624
675
|
end
|
625
676
|
self.format.display_status("#{private_key_path}")
|
626
677
|
pub_key_pem=OpenSSL::PKey::RSA.new(File.read(private_key_path)).public_key.to_s
|
627
|
-
#
|
678
|
+
# declare command line options for AoC
|
628
679
|
require 'aspera/cli/plugins/aoc'
|
629
680
|
# make username mandatory for jwt, this triggers interactive input
|
630
681
|
self.options.get_option(:username,:mandatory)
|
631
|
-
# instanciate AoC plugin
|
682
|
+
# instanciate AoC plugin, so that command line options are known
|
632
683
|
files_plugin=self.class.plugin_new(AOC_COMMAND_CURRENT,@agents.merge({skip_basic_auth_options: true, private_key_path: private_key_path}))
|
684
|
+
aoc_api=files_plugin.api_aoc
|
633
685
|
auto_set_pub_key=false
|
634
686
|
auto_set_jwt=false
|
635
687
|
use_browser_authentication=false
|
@@ -656,29 +708,28 @@ module Aspera
|
|
656
708
|
self.format.display_status("Once created or identified,")
|
657
709
|
self.format.display_status("Please enter:".red)
|
658
710
|
end
|
659
|
-
OpenApplication.instance.uri(instance_url
|
711
|
+
OpenApplication.instance.uri("#{instance_url}/#{AOC_PATH_API_CLIENTS}")
|
660
712
|
self.options.get_option(:client_id,:mandatory)
|
661
713
|
self.options.get_option(:client_secret,:mandatory)
|
662
714
|
use_browser_authentication=true
|
663
715
|
end
|
664
716
|
if use_browser_authentication
|
665
717
|
self.format.display_status("We will use web authentication to bootstrap.")
|
666
|
-
self.options.set_option(:auth,:web)
|
667
|
-
self.options.set_option(:redirect_uri,DEFAULT_REDIRECT)
|
668
718
|
auto_set_pub_key=true
|
669
719
|
auto_set_jwt=true
|
670
|
-
|
720
|
+
@api_aoc.oauth.params[:auth]=:web
|
721
|
+
@api_aoc.oauth.params[:redirect_uri]=DEFAULT_REDIRECT
|
722
|
+
@api_aoc.oauth.params[:scope]=AoC::SCOPE_FILES_ADMIN
|
671
723
|
end
|
672
|
-
|
673
|
-
myself=files_plugin.api_aoc.read('self')[:data]
|
724
|
+
myself=aoc_api.read('self')[:data]
|
674
725
|
if auto_set_pub_key
|
675
|
-
raise CliError,
|
676
|
-
self.format.display_status(
|
677
|
-
|
726
|
+
raise CliError,'public key is already set in profile (use --override=yes)' unless myself['public_key'].empty? or option_override
|
727
|
+
self.format.display_status('Updating profile with new key')
|
728
|
+
aoc_api.update("users/#{myself['id']}",{'public_key'=>pub_key_pem})
|
678
729
|
end
|
679
730
|
if auto_set_jwt
|
680
731
|
self.format.display_status("Enabling JWT for client")
|
681
|
-
|
732
|
+
aoc_api.update("clients/#{self.options.get_option(:client_id)}",{'jwt_grant_enabled'=>true,'explicit_authorization_required'=>false})
|
682
733
|
end
|
683
734
|
self.format.display_status("creating new config preset: #{aspera_preset_name}")
|
684
735
|
@config_presets[aspera_preset_name]={
|
@@ -764,6 +815,8 @@ module Aspera
|
|
764
815
|
pac_url=self.options.get_option(:fpac,:mandatory)
|
765
816
|
server_url=self.options.get_next_argument("server url")
|
766
817
|
return Main.result_status(Aspera::ProxyAutoConfig.new(UriReader.read(pac_url)).get_proxy(server_url))
|
818
|
+
when :check_update
|
819
|
+
return {:type=>:single_object, :data=>check_gem_version}
|
767
820
|
else raise "error"
|
768
821
|
end
|
769
822
|
end
|
@@ -14,13 +14,13 @@ module Aspera
|
|
14
14
|
self.options.parse_options!
|
15
15
|
end
|
16
16
|
|
17
|
-
ACTIONS=[:transfer,:
|
17
|
+
ACTIONS=[:transfer,:health]
|
18
18
|
|
19
19
|
def execute_action
|
20
20
|
api_console=basic_auth_api('api')
|
21
21
|
command=self.options.get_next_command(ACTIONS)
|
22
22
|
case command
|
23
|
-
when :
|
23
|
+
when :health
|
24
24
|
nagios=Nagios.new
|
25
25
|
begin
|
26
26
|
api_console.read('ssh_keys')
|
@@ -52,7 +52,7 @@ module Aspera
|
|
52
52
|
|
53
53
|
# get faspe: URI from entry in xml, and fix problems..
|
54
54
|
def self.get_fasp_uri_from_entry(entry)
|
55
|
-
raise CliBadArgument, 'package
|
55
|
+
raise CliBadArgument, 'package has no link (deleted?)' unless entry.has_key?('link')
|
56
56
|
result=entry['link'].select{|e| e['rel'].eql?('package')}.first['href']
|
57
57
|
# tags in the end of URL is not well % encoded... there are "=" that should be %3D
|
58
58
|
# TODO: enter ticket to Faspex ?
|
@@ -101,19 +101,26 @@ module Aspera
|
|
101
101
|
return @api_v4
|
102
102
|
end
|
103
103
|
|
104
|
-
ACTIONS=[ :
|
104
|
+
ACTIONS=[ :health,:package, :source, :me, :dropbox, :v4, :address_book, :login_methods ]
|
105
105
|
|
106
106
|
# we match recv command on atom feed on this field
|
107
107
|
PACKAGE_MATCH_FIELD='package_id'
|
108
108
|
|
109
109
|
def mailbox_all_entries
|
110
|
-
|
110
|
+
my_user_name=self.options.get_option(:username,:mandatory)
|
111
|
+
mailbox=self.options.get_option(:box,:mandatory)
|
111
112
|
all_inbox_xml=api_v3.call({:operation=>'GET',:subpath=>"#{mailbox}.atom",:headers=>{'Accept'=>'application/xml'}})[:http].body
|
112
113
|
all_inbox_data=XmlSimple.xml_in(all_inbox_xml, {'ForceArray' => true})
|
113
114
|
Log.dump(:all_inbox_data,all_inbox_data)
|
114
115
|
result=all_inbox_data.has_key?('entry') ? all_inbox_data['entry'] : []
|
115
116
|
result.each do |e|
|
116
|
-
|
117
|
+
case mailbox
|
118
|
+
when :inbox,:archive
|
119
|
+
recipient=e['to'].select{|i|i['name'].first.eql?(my_user_name)}.first
|
120
|
+
e[PACKAGE_MATCH_FIELD]=recipient.nil? ? 'n/a' : recipient['recipient_delivery_id'].first
|
121
|
+
when :sent
|
122
|
+
e[PACKAGE_MATCH_FIELD]=e['delivery_id'].first
|
123
|
+
end
|
117
124
|
end
|
118
125
|
# remove dropbox packages
|
119
126
|
result.select!{|p|p['metadata'].first['field'].select{|j|j['name'].eql?('_dropbox_name')}.empty? rescue false}
|
@@ -155,7 +162,7 @@ module Aspera
|
|
155
162
|
def execute_action
|
156
163
|
command=self.options.get_next_command(ACTIONS)
|
157
164
|
case command
|
158
|
-
when :
|
165
|
+
when :health
|
159
166
|
nagios=Nagios.new
|
160
167
|
begin
|
161
168
|
api_v3.read('me')
|
@@ -241,7 +248,7 @@ module Aspera
|
|
241
248
|
# TODO: delivery id is the right one if package was receive by group
|
242
249
|
endpoint=case self.options.get_option(:box,:mandatory)
|
243
250
|
when :inbox,:archive;'received'
|
244
|
-
when :sent;'sent'
|
251
|
+
when :sent; 'sent'
|
245
252
|
end
|
246
253
|
entry_xml=api_v3.call({:operation=>'GET',:subpath=>"#{endpoint}/#{delivid}",:headers=>{'Accept'=>'application/xml'}})[:http].body
|
247
254
|
package_entry=XmlSimple.xml_in(entry_xml, {'ForceArray' => true})
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'aspera/cli/basic_auth_plugin'
|
2
2
|
require 'aspera/persistency_action_once'
|
3
|
+
require 'securerandom'
|
3
4
|
|
4
5
|
module Aspera
|
5
6
|
module Cli
|
@@ -8,74 +9,129 @@ module Aspera
|
|
8
9
|
VAL_ALL='ALL'
|
9
10
|
def initialize(env)
|
10
11
|
super(env)
|
11
|
-
|
12
|
-
|
12
|
+
options.add_opt_simple(:client_id,'API client identifier in application')
|
13
|
+
options.add_opt_simple(:client_secret,'API client secret in application')
|
14
|
+
options.add_opt_simple(:redirect_uri,'API client redirect URI')
|
15
|
+
options.add_opt_list(:auth,Oauth.auth_types.clone.push(:boot),'type of Oauth authentication')
|
16
|
+
options.add_opt_simple(:private_key,'RSA private key PEM value for JWT (prefix file path with @val:@file:)')
|
17
|
+
options.set_option(:auth,:jwt)
|
18
|
+
options.parse_options!
|
13
19
|
end
|
14
|
-
ACTIONS=[ :node, :package ]
|
20
|
+
ACTIONS=[ :node, :package, :auth_client ]
|
15
21
|
|
16
|
-
|
22
|
+
def set_api
|
23
|
+
faxpex5_api_base_url=options.get_option(:url,:mandatory)
|
24
|
+
faxpex5_api_v5_url="#{faxpex5_api_base_url}/api/v5"
|
25
|
+
faxpex5_api_auth_url="#{faxpex5_api_base_url}/auth"
|
26
|
+
case options.get_option(:auth,:mandatory)
|
27
|
+
when :web
|
28
|
+
@api_v5=Rest.new({
|
29
|
+
:base_url => faxpex5_api_v5_url,
|
30
|
+
:auth => {
|
31
|
+
:type => :oauth2,
|
32
|
+
:base_url => faxpex5_api_auth_url,
|
33
|
+
:grant => :web,
|
34
|
+
:state => SecureRandom.uuid,
|
35
|
+
:client_id => options.get_option(:client_id,:mandatory),
|
36
|
+
:redirect_uri => options.get_option(:redirect_uri,:mandatory),
|
37
|
+
#:token_field =>'auth_token',
|
38
|
+
#:path_token => 'token',
|
39
|
+
#:path_authorize => 'authorize',
|
40
|
+
#:userpass_body => {name: faxpex5_username,password: faxpex5_password}
|
41
|
+
}})
|
42
|
+
when :boot
|
43
|
+
@api_v5=Rest.new({
|
44
|
+
:base_url => faxpex5_api_v5_url,
|
45
|
+
:headers => {'Authorization'=>options.get_option(:password,:mandatory)},
|
46
|
+
})
|
47
|
+
when :jwt
|
48
|
+
#raise "JWT to be implemented"
|
49
|
+
@api_v5=Rest.new({
|
50
|
+
:base_url => faxpex5_api_base_url,
|
51
|
+
:auth => {
|
52
|
+
:type => :oauth2,
|
53
|
+
:base_url => faxpex5_api_auth_url,
|
54
|
+
:grant => :jwt,
|
55
|
+
:client_id => options.get_option(:client_id,:mandatory),
|
56
|
+
:client_secret => options.get_option(:client_secret,:mandatory),
|
57
|
+
#:redirect_uri => options.get_option(:redirect_uri,:mandatory),
|
58
|
+
:jwt_subject => "client:#{options.get_option(:client_id,:mandatory)}", # TODO Mmmm
|
59
|
+
:jwt_private_key_obj => OpenSSL::PKey::RSA.new(options.get_option(:private_key,:mandatory)),
|
60
|
+
:jwt_audience =>options.get_option(:client_id,:mandatory), # TODO Mmmm
|
61
|
+
#:token_field =>'auth_token',
|
62
|
+
#:path_token => 'authenticate',
|
63
|
+
#:path_authorize => :unused,
|
64
|
+
#:userpass_body => {name: options.get_option(:username,:mandatory),password: options.get_option(:password,:mandatory)}
|
65
|
+
}})
|
66
|
+
# former version
|
67
|
+
# # get parameters
|
68
|
+
# faxpex5_username=options.get_option(:username,:mandatory)
|
69
|
+
# faxpex5_password=options.get_option(:password,:mandatory)
|
70
|
+
# # create object for REST calls to Shares2
|
71
|
+
# @api_v5=Rest.new({
|
72
|
+
# :base_url => faxpex5_api_base_url,
|
73
|
+
# :auth => {
|
74
|
+
# :type => :oauth2,
|
75
|
+
# :base_url => faxpex5_api_base_url,
|
76
|
+
# :grant => :body_data,
|
77
|
+
# :token_field =>'auth_token',
|
78
|
+
# :path_token => 'authenticate',
|
79
|
+
# :path_authorize => :unused,
|
80
|
+
# :userpass_body => {name: faxpex5_username,password: faxpex5_password}
|
81
|
+
# }})
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
17
86
|
def execute_action
|
18
|
-
|
19
|
-
|
20
|
-
faxpex5_username=self.options.get_option(:username,:mandatory)
|
21
|
-
faxpex5_password=self.options.get_option(:password,:mandatory)
|
22
|
-
faxpex5_api_base_url+='/api/v5'
|
23
|
-
# create object for REST calls to Shares2
|
24
|
-
api_v5=Rest.new({
|
25
|
-
:base_url => faxpex5_api_base_url,
|
26
|
-
:auth => {
|
27
|
-
:type => :oauth2,
|
28
|
-
:base_url => faxpex5_api_base_url,
|
29
|
-
:grant => :body_data,
|
30
|
-
:token_field =>'auth_token',
|
31
|
-
:path_token => 'authenticate',
|
32
|
-
:path_authorize => :unused,
|
33
|
-
:userpass_body => {name: faxpex5_username,password: faxpex5_password}
|
34
|
-
}})
|
35
|
-
command=self.options.get_next_command(ACTIONS)
|
87
|
+
set_api
|
88
|
+
command=options.get_next_command(ACTIONS)
|
36
89
|
case command
|
90
|
+
when :auth_client
|
91
|
+
api_auth=Rest.new(@api_v5.params.merge({base_url: @api_v5.params[:base_url].gsub(/api\/v5$/,'auth')}))
|
92
|
+
return self.entity_action(api_auth,'oauth_clients',nil,:id,nil,true)
|
37
93
|
when :node
|
38
|
-
return self.entity_action(api_v5,'nodes',nil,:id,nil,true)
|
94
|
+
return self.entity_action(@api_v5,'nodes',nil,:id,nil,true)
|
39
95
|
when :package
|
40
|
-
command=
|
96
|
+
command=options.get_next_command([:list,:show,:send,:receive])
|
41
97
|
case command
|
42
98
|
when :list
|
43
|
-
parameters=
|
44
|
-
return {:type => :object_list, :data
|
99
|
+
parameters=options.get_option(:value,:optional)
|
100
|
+
return {:type => :object_list, :data=>@api_v5.read('packages',parameters)[:data]['packages']}
|
45
101
|
when :show
|
46
|
-
id=
|
47
|
-
return {:type => :single_object, :data
|
102
|
+
id=options.get_option(:id,:mandatory)
|
103
|
+
return {:type => :single_object, :data=>@api_v5.read("packages/#{id}")[:data]}
|
48
104
|
when :send
|
49
|
-
parameters=
|
105
|
+
parameters=options.get_option(:value,:mandatory)
|
50
106
|
raise CliBadArgument,'package value must be hash, refer to API' unless parameters.is_a?(Hash)
|
51
|
-
package
|
52
|
-
transfer_spec
|
107
|
+
package=@api_v5.create('packages',parameters)[:data]
|
108
|
+
transfer_spec=@api_v5.create("packages/#{package['id']}/transfer_spec/upload",{transfer_type: 'Connect'})[:data]
|
53
109
|
transfer_spec.delete('authentication')
|
54
110
|
return Main.result_transfer(self.transfer.start(transfer_spec,{:src=>:node_gen3}))
|
55
111
|
when :receive
|
56
112
|
pkg_type='received'
|
57
|
-
pack_id=
|
113
|
+
pack_id=options.get_option(:id,:mandatory)
|
58
114
|
package_ids=[pack_id]
|
59
115
|
skip_ids_data=[]
|
60
116
|
skip_ids_persistency=nil
|
61
|
-
if
|
117
|
+
if options.get_option(:once_only,:mandatory)
|
62
118
|
skip_ids_persistency=PersistencyActionOnce.new(
|
63
119
|
manager: @agents[:persistency],
|
64
120
|
data: skip_ids_data,
|
65
|
-
ids: ['faspex_recv',
|
121
|
+
ids: ['faspex_recv',options.get_option(:url,:mandatory),options.get_option(:username,:mandatory),pkg_type])
|
66
122
|
end
|
67
123
|
if pack_id.eql?(VAL_ALL)
|
68
124
|
# todo: if packages have same name, they will overwrite
|
69
|
-
parameters=
|
125
|
+
parameters=options.get_option(:value,:optional)
|
70
126
|
parameters||={"type"=>"received","subtype"=>"mypackages","limit"=>1000}
|
71
127
|
raise CliBadArgument,'value filter must be hash (API GET)' unless parameters.is_a?(Hash)
|
72
|
-
package_ids
|
128
|
+
package_ids=@api_v5.read('packages',parameters)[:data]['packages'].map{|p|p['id']}
|
73
129
|
package_ids.select!{|i|!skip_ids_data.include?(i)}
|
74
130
|
end
|
75
131
|
result_transfer=[]
|
76
132
|
package_ids.each do |id|
|
77
133
|
# TODO: allow from sent as well ?
|
78
|
-
transfer_spec
|
134
|
+
transfer_spec=@api_v5.create("packages/#{id}/transfer_spec/download",{transfer_type: 'Connect', type: pkg_type})[:data]
|
79
135
|
transfer_spec.delete('authentication')
|
80
136
|
statuses=self.transfer.start(transfer_spec,{:src=>:node_gen3})
|
81
137
|
result_transfer.push({'package'=>id,'status'=>statuses.map{|i|i.to_s}.join(',')})
|