aspera-cli 4.13.0 → 4.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +28 -5
  4. data/CONTRIBUTING.md +17 -1
  5. data/README.md +782 -401
  6. data/examples/dascli +1 -1
  7. data/examples/rubyc +24 -0
  8. data/lib/aspera/aoc.rb +21 -32
  9. data/lib/aspera/ascmd.rb +1 -0
  10. data/lib/aspera/cli/basic_auth_plugin.rb +6 -6
  11. data/lib/aspera/cli/formatter.rb +17 -25
  12. data/lib/aspera/cli/main.rb +21 -27
  13. data/lib/aspera/cli/manager.rb +128 -114
  14. data/lib/aspera/cli/plugin.rb +87 -38
  15. data/lib/aspera/cli/plugins/alee.rb +2 -2
  16. data/lib/aspera/cli/plugins/aoc.rb +216 -102
  17. data/lib/aspera/cli/plugins/ats.rb +16 -18
  18. data/lib/aspera/cli/plugins/bss.rb +3 -3
  19. data/lib/aspera/cli/plugins/config.rb +177 -367
  20. data/lib/aspera/cli/plugins/console.rb +4 -6
  21. data/lib/aspera/cli/plugins/cos.rb +12 -13
  22. data/lib/aspera/cli/plugins/faspex.rb +17 -18
  23. data/lib/aspera/cli/plugins/faspex5.rb +332 -216
  24. data/lib/aspera/cli/plugins/node.rb +171 -142
  25. data/lib/aspera/cli/plugins/orchestrator.rb +15 -18
  26. data/lib/aspera/cli/plugins/preview.rb +38 -60
  27. data/lib/aspera/cli/plugins/server.rb +22 -15
  28. data/lib/aspera/cli/plugins/shares.rb +24 -33
  29. data/lib/aspera/cli/plugins/sync.rb +3 -3
  30. data/lib/aspera/cli/transfer_agent.rb +29 -26
  31. data/lib/aspera/cli/version.rb +1 -1
  32. data/lib/aspera/colors.rb +9 -7
  33. data/lib/aspera/data/6 +0 -0
  34. data/lib/aspera/environment.rb +7 -3
  35. data/lib/aspera/fasp/agent_connect.rb +5 -0
  36. data/lib/aspera/fasp/agent_direct.rb +5 -5
  37. data/lib/aspera/fasp/agent_httpgw.rb +138 -60
  38. data/lib/aspera/fasp/agent_trsdk.rb +2 -0
  39. data/lib/aspera/fasp/error_info.rb +2 -0
  40. data/lib/aspera/fasp/installation.rb +18 -19
  41. data/lib/aspera/fasp/parameters.rb +18 -17
  42. data/lib/aspera/fasp/parameters.yaml +2 -1
  43. data/lib/aspera/fasp/resume_policy.rb +3 -3
  44. data/lib/aspera/fasp/transfer_spec.rb +6 -5
  45. data/lib/aspera/fasp/uri.rb +23 -21
  46. data/lib/aspera/faspex_postproc.rb +1 -1
  47. data/lib/aspera/hash_ext.rb +12 -2
  48. data/lib/aspera/keychain/macos_security.rb +13 -13
  49. data/lib/aspera/log.rb +1 -0
  50. data/lib/aspera/node.rb +62 -80
  51. data/lib/aspera/oauth.rb +1 -1
  52. data/lib/aspera/persistency_action_once.rb +1 -1
  53. data/lib/aspera/preview/terminal.rb +61 -15
  54. data/lib/aspera/preview/utils.rb +3 -3
  55. data/lib/aspera/proxy_auto_config.js +2 -2
  56. data/lib/aspera/rest.rb +37 -0
  57. data/lib/aspera/secret_hider.rb +6 -1
  58. data/lib/aspera/ssh.rb +1 -1
  59. data/lib/aspera/sync.rb +2 -0
  60. data.tar.gz.sig +0 -0
  61. metadata +3 -4
  62. metadata.gz.sig +0 -0
  63. data/docs/test_env.conf +0 -186
  64. data/lib/aspera/data/7 +0 -0
@@ -40,19 +40,15 @@ module Aspera
40
40
  CONF_PRESET_GLOBAL = 'global_common_defaults'
41
41
  CONF_PLUGIN_SYM = :config # Plugins::Config.name.split('::').last.downcase.to_sym
42
42
  CONF_GLOBAL_SYM = :config
43
- # old tool name
44
- PROGRAM_NAME_V1 = 'aslmcli'
45
- PROGRAM_NAME_V2 = 'mlia'
46
43
  # default redirect for AoC web auth
47
44
  DEFAULT_REDIRECT = 'http://localhost:12345'
48
45
  # folder containing custom plugins in user's config folder
49
46
  ASPERA_PLUGINS_FOLDERNAME = 'plugins'
50
47
  RUBY_FILE_EXT = '.rb'
51
- AOC_COMMAND_V1 = 'files'
52
- AOC_COMMAND_V2 = 'aspera'
53
- AOC_COMMAND_V3 = 'aoc'
54
- AOC_COMMAND_CURRENT = AOC_COMMAND_V3
48
+ ASPERA = 'aspera'
49
+ AOC_COMMAND = 'aoc'
55
50
  SERVER_COMMAND = 'server'
51
+ APP_NAME_SDK = 'sdk'
56
52
  CONNECT_WEB_URL = 'https://d3gcli72yxqn2z.cloudfront.net/connect'
57
53
  CONNECT_VERSIONS = 'connectversions.js'
58
54
  TRANSFER_SDK_ARCHIVE_URL = 'https://ibm.biz/aspera_transfer_sdk'
@@ -80,15 +76,11 @@ module Aspera
80
76
  :CONF_PRESET_VERSION,
81
77
  :CONF_PRESET_DEFAULT,
82
78
  :CONF_PRESET_GLOBAL,
83
- :PROGRAM_NAME_V1,
84
- :PROGRAM_NAME_V2,
85
79
  :DEFAULT_REDIRECT,
86
80
  :ASPERA_PLUGINS_FOLDERNAME,
87
81
  :RUBY_FILE_EXT,
88
- :AOC_COMMAND_V1,
89
- :AOC_COMMAND_V2,
90
- :AOC_COMMAND_V3,
91
- :AOC_COMMAND_CURRENT,
82
+ :ASPERA,
83
+ :AOC_COMMAND,
92
84
  :DEMO,
93
85
  :TRANSFER_SDK_ARCHIVE_URL,
94
86
  :AOC_PATH_API_CLIENTS,
@@ -117,13 +109,13 @@ module Aspera
117
109
  @conf_file_default = File.join(@main_folder, DEFAULT_CONFIG_FILENAME)
118
110
  @option_config_file = @conf_file_default
119
111
  @pac_exec = nil
112
+ @sdk_default_location = false
120
113
  Log.log.debug{"#{@info[:name]} folder: #{@main_folder}"}
121
114
  # set folder for FASP SDK
122
115
  add_plugin_lookup_folder(self.class.gem_plugins_folder)
123
116
  add_plugin_lookup_folder(File.join(@main_folder, ASPERA_PLUGINS_FOLDERNAME))
124
117
  # do file parameter first
125
- options.set_obj_attr(:config_file, self, :option_config_file)
126
- options.add_opt_simple(:config_file, "read parameters from file in YAML format, current=#{@option_config_file}")
118
+ options.declare(:config_file, "Read parameters from file in YAML format, current=#{@option_config_file}", handler: {o: self, m: :option_config_file})
127
119
  options.parse_options!
128
120
  # read correct file (set @config_presets)
129
121
  read_config_file
@@ -134,40 +126,46 @@ module Aspera
134
126
  # load defaults before it can be overridden
135
127
  add_plugin_default_preset(CONF_GLOBAL_SYM)
136
128
  options.parse_options!
137
- options.set_obj_attr(:ascp_path, Fasp::Installation.instance, :ascp_path)
138
- options.set_obj_attr(:sdk_folder, Fasp::Installation.instance, :sdk_folder)
139
- options.set_obj_attr(:use_product, self, :option_use_product)
140
- options.set_obj_attr(:preset, self, :option_preset)
141
- options.set_obj_attr(:plugin_folder, self, :option_plugin_folder)
142
- options.add_opt_switch(:no_default, '-N', 'do not load default configuration for plugin') { @use_plugin_defaults = false }
143
- options.add_opt_boolean(:override, 'Wizard: override existing value')
144
- options.add_opt_boolean(:use_generic_client, 'Wizard: AoC: use global or org specific jwt client id')
145
- options.add_opt_boolean(:default, 'Wizard: set as default configuration for specified plugin (also: update)')
146
- options.add_opt_boolean(:test_mode, 'Wizard: skip private key check step')
147
- options.add_opt_simple(:preset, '-PVALUE', 'load the named option preset from current config file')
148
- options.add_opt_simple(:pkeypath, 'Wizard: path to private key for JWT')
149
- options.add_opt_simple(:ascp_path, 'Path to ascp')
150
- options.add_opt_simple(:use_product, 'Use ascp from specified product')
151
- options.add_opt_simple(:smtp, 'SMTP configuration (extended value: hash)')
152
- options.add_opt_simple(:fpac, 'Proxy auto configuration script')
153
- options.add_opt_simple(:proxy_credentials, 'HTTP proxy credentials (Array with user and password)')
154
- options.add_opt_simple(:secret, 'Secret for access keys')
155
- options.add_opt_simple(:vault, 'Vault for secrets')
156
- options.add_opt_simple(:vault_password, 'Vault password')
157
- options.add_opt_simple(:sdk_url, 'URL to get SDK')
158
- options.add_opt_simple(:sdk_folder, 'SDK folder path')
159
- options.add_opt_simple(:notif_to, 'Email recipient for notification of transfers')
160
- options.add_opt_simple(:notif_template, 'Email ERB template for notification of transfers')
161
- options.add_opt_simple(:version_check_days, Integer, 'Period in days to check new version (zero to disable)')
162
- options.add_opt_simple(:plugin_folder, 'Folder where to find additional plugins')
163
- options.set_option(:use_generic_client, true)
164
- options.set_option(:test_mode, false)
165
- options.set_option(:default, true)
166
- options.set_option(:version_check_days, DEFAULT_CHECK_NEW_VERSION_DAYS)
167
- options.set_option(:sdk_url, TRANSFER_SDK_ARCHIVE_URL)
168
- options.set_option(:sdk_folder, File.join(@main_folder, 'sdk'))
169
- options.set_option(:override, :no)
129
+ options.declare(:no_default, 'Do not load default configuration for plugin', values: :none, short: 'N') { @use_plugin_defaults = false }
130
+ options.declare(:override, 'Wizard: override existing value', values: :bool, default: :no)
131
+ options.declare(:use_generic_client, 'Wizard: AoC: use global or org specific jwt client id', values: :bool, default: true)
132
+ options.declare(:default, 'Wizard: set as default configuration for specified plugin (also: update)', values: :bool, default: true)
133
+ options.declare(:test_mode, 'Wizard: skip private key check step', values: :bool, default: false)
134
+ options.declare(:preset, 'Load the named option preset from current config file', short: 'P', handler: {o: self, m: :option_preset})
135
+ options.declare(:pkeypath, 'Wizard: path to private key for JWT')
136
+ options.declare(:ascp_path, 'Path to ascp', handler: {o: Fasp::Installation.instance, m: :ascp_path})
137
+ options.declare(:use_product, 'Use ascp from specified product', handler: {o: self, m: :option_use_product})
138
+ options.declare(:smtp, 'SMTP configuration', types: Hash)
139
+ options.declare(:fpac, 'Proxy auto configuration script')
140
+ options.declare(:proxy_credentials, 'HTTP proxy credentials (Array with user and password)')
141
+ options.declare(:secret, 'Secret for access keys')
142
+ options.declare(:vault, 'Vault for secrets')
143
+ options.declare(:vault_password, 'Vault password')
144
+ options.declare(:sdk_url, 'URL to get SDK', default: TRANSFER_SDK_ARCHIVE_URL)
145
+ options.declare(:sdk_folder, 'SDK folder path', handler: {o: Fasp::Installation.instance, m: :sdk_folder})
146
+ options.declare(:notif_to, 'Email recipient for notification of transfers')
147
+ options.declare(:notif_template, 'Email ERB template for notification of transfers')
148
+ options.declare(:version_check_days, 'Period in days to check new version (zero to disable)', coerce: Integer, default: DEFAULT_CHECK_NEW_VERSION_DAYS)
149
+ options.declare(:plugin_folder, 'Folder where to find additional plugins', handler: {o: self, m: :option_plugin_folder})
170
150
  options.parse_options!
151
+ # Check SDK folder is set or not, for compatibility, we check in two places
152
+ sdk_folder = Fasp::Installation.instance.sdk_folder rescue nil
153
+ if sdk_folder.nil?
154
+ @sdk_default_location = true
155
+ Log.log.debug('SDK folder is not set, checking default')
156
+ # new location
157
+ sdk_folder = default_app_main_folder(app_name: APP_NAME_SDK)
158
+ Log.log.debug{"checking: #{sdk_folder}"}
159
+ if !Dir.exist?(sdk_folder)
160
+ Log.log.debug{"not exists: #{sdk_folder}"}
161
+ # former location
162
+ former_sdk_folder = File.join(default_app_main_folder, APP_NAME_SDK)
163
+ Log.log.debug{"checking: #{former_sdk_folder}"}
164
+ sdk_folder = former_sdk_folder if Dir.exist?(former_sdk_folder)
165
+ end
166
+ Log.log.debug{"using: #{sdk_folder}"}
167
+ Fasp::Installation.instance.sdk_folder = sdk_folder
168
+ end
171
169
  pac_script = options.get_option(:fpac)
172
170
  # create PAC executor
173
171
  @pac_exec = Aspera::ProxyAutoConfig.new(pac_script).register_uri_generic unless pac_script.nil?
@@ -186,15 +184,20 @@ module Aspera
186
184
  return "#{@info[:name]}_home".upcase
187
185
  end
188
186
 
189
- def default_app_main_folder
187
+ # return product family folder (~/.aspera)
188
+ def module_family_folder
189
+ user_home_folder = Dir.home
190
+ raise CliError, "Home folder does not exist: #{user_home_folder}. Check your user environment." unless Dir.exist?(user_home_folder)
191
+ return File.join(user_home_folder, ASPERA_HOME_FOLDER_NAME)
192
+ end
193
+
194
+ # return product config folder (~/.aspera/<name>)
195
+ def default_app_main_folder(app_name: nil)
196
+ app_name = @info[:name] if app_name.nil?
190
197
  # find out application main folder
191
198
  app_folder = ENV[conf_dir_env_var]
192
199
  # if env var undefined or empty
193
- if app_folder.nil? || app_folder.empty?
194
- user_home_folder = Dir.home
195
- raise CliError, "Home folder does not exist: #{user_home_folder}. Check your user environment or use #{conf_dir_env_var}." unless Dir.exist?(user_home_folder)
196
- app_folder = File.join(user_home_folder, ASPERA_HOME_FOLDER_NAME, @info[:name])
197
- end
200
+ app_folder = File.join(module_family_folder, app_name) if app_folder.nil? || app_folder.empty?
198
201
  return app_folder
199
202
  end
200
203
 
@@ -222,7 +225,7 @@ module Aspera
222
225
 
223
226
  def periodic_check_newer_gem_version
224
227
  # get verification period
225
- delay_days = options.get_option(:version_check_days, is_type: :mandatory)
228
+ delay_days = options.get_option(:version_check_days, mandatory: true)
226
229
  Log.log.info{"check days: #{delay_days}"}
227
230
  # check only if not zero day
228
231
  return if delay_days.eql?(0)
@@ -283,17 +286,17 @@ module Aspera
283
286
 
284
287
  private
285
288
 
286
- def generate_rsa_private_key(private_key_path, length)
287
- require 'openssl'
288
- priv_key = OpenSSL::PKey::RSA.new(length)
289
- File.write(private_key_path, priv_key.to_s)
290
- File.write(private_key_path + '.pub', priv_key.public_key.to_s)
291
- Environment.restrict_file_access(private_key_path)
292
- Environment.restrict_file_access(private_key_path + '.pub')
293
- nil
294
- end
295
-
296
289
  class << self
290
+ def generate_rsa_private_key(path:, length: DEFAULT_PRIVKEY_LENGTH)
291
+ require 'openssl'
292
+ priv_key = OpenSSL::PKey::RSA.new(length)
293
+ File.write(path, priv_key.to_s)
294
+ File.write(path + '.pub', priv_key.public_key.to_s)
295
+ Environment.restrict_file_access(path)
296
+ Environment.restrict_file_access(path + '.pub')
297
+ nil
298
+ end
299
+
297
300
  # folder containing plugins in the gem's main folder
298
301
  def gem_plugins_folder
299
302
  File.dirname(File.expand_path(__FILE__))
@@ -417,43 +420,15 @@ module Aspera
417
420
  end
418
421
  end
419
422
 
420
- def convert_preset_path(old_name, new_name, files_to_copy)
421
- old_subpath = File.join('', ASPERA_HOME_FOLDER_NAME, old_name, '')
422
- new_subpath = File.join('', ASPERA_HOME_FOLDER_NAME, new_name, '')
423
- # convert possible keys located in config folder
424
- @config_presets.values.select{|p|p.is_a?(Hash)}.each do |preset|
425
- preset.values.select{|v|v.is_a?(String) && v.include?(old_subpath)}.each do |value|
426
- old_val = value.clone
427
- included_path = File.expand_path(old_val.gsub(/^@file:/, ''))
428
- files_to_copy.push(included_path) unless files_to_copy.include?(included_path) || !File.exist?(included_path)
429
- value.gsub!(old_subpath, new_subpath)
430
- Log.log.warn{"Converted config value: #{old_val} -> #{value}"}
431
- end
432
- end
433
- end
434
-
435
- def convert_preset_plugin_name(old_name, new_name)
436
- default_preset = @config_presets[CONF_PRESET_DEFAULT]
437
- return unless default_preset.is_a?(Hash) && default_preset.key?(old_name)
438
- default_preset[new_name] = default_preset[old_name]
439
- default_preset.delete(old_name)
440
- Log.log.warn{"Converted plugin default: #{old_name} -> #{new_name}"}
441
- end
442
-
443
423
  # read config file and validate format
444
- # tries to convert from older version if possible and required
445
424
  def read_config_file
446
425
  Log.log.debug{"config file is: #{@option_config_file}".red}
447
- conf_file_v1 = File.join(Dir.home, ASPERA_HOME_FOLDER_NAME, PROGRAM_NAME_V1, DEFAULT_CONFIG_FILENAME)
448
- conf_file_v2 = File.join(Dir.home, ASPERA_HOME_FOLDER_NAME, PROGRAM_NAME_V2, DEFAULT_CONFIG_FILENAME)
449
426
  # files search for configuration, by default the one given by user
450
427
  search_files = [@option_config_file]
451
- # if default file, then also look for older versions
452
- search_files.push(conf_file_v2, conf_file_v1) if @option_config_file.eql?(@conf_file_default)
453
428
  # find first existing file (or nil)
454
429
  conf_file_to_load = search_files.find{|f| File.exist?(f)}
455
430
  # require save if old version of file
456
- save_required = !@option_config_file.eql?(conf_file_to_load)
431
+ save_required = false
457
432
  # if no file found, create default config
458
433
  if conf_file_to_load.nil?
459
434
  Log.log.warn{"No config file found. Creating empty configuration file: #{@option_config_file}"}
@@ -473,32 +448,8 @@ module Aspera
473
448
  if version.nil?
474
449
  raise 'No version found in config section.'
475
450
  end
476
- # oldest compatible conf file format, update to latest version when an incompatible change is made
477
- # check compatibility of version of conf file
478
- config_tested_version = '0.4.5'
479
- if Gem::Version.new(version) < Gem::Version.new(config_tested_version)
480
- raise "Unsupported config file version #{version}. Expecting min version #{config_tested_version}"
481
- end
482
- config_tested_version = '0.6.15'
483
- if Gem::Version.new(version) < Gem::Version.new(config_tested_version)
484
- convert_preset_plugin_name(AOC_COMMAND_V1, AOC_COMMAND_V2)
485
- version = @config_presets[CONF_PRESET_CONFIG][CONF_PRESET_VERSION] = config_tested_version
486
- save_required = true
487
- end
488
- config_tested_version = '0.8.10'
489
- if Gem::Version.new(version) <= Gem::Version.new(config_tested_version)
490
- convert_preset_path(PROGRAM_NAME_V1, PROGRAM_NAME_V2, files_to_copy)
491
- version = @config_presets[CONF_PRESET_CONFIG][CONF_PRESET_VERSION] = config_tested_version
492
- save_required = true
493
- end
494
- config_tested_version = '1.0'
495
- if Gem::Version.new(version) <= Gem::Version.new(config_tested_version)
496
- convert_preset_plugin_name(AOC_COMMAND_V2, AOC_COMMAND_V3)
497
- convert_preset_path(PROGRAM_NAME_V2, @info[:name], files_to_copy)
498
- version = @config_presets[CONF_PRESET_CONFIG][CONF_PRESET_VERSION] = config_tested_version
499
- save_required = true
500
- end
501
451
  Log.log.debug{"conf version: #{version}"}
452
+ # if there are any conversion needed, those happen here.
502
453
  # Place new compatibility code here
503
454
  if save_required
504
455
  Log.log.warn('Saving automatic conversion.')
@@ -552,13 +503,18 @@ module Aspera
552
503
  @plugins[plugin_symbol] = {source: path, require_stanza: req}
553
504
  end
554
505
 
555
- def identify_plugin_for_url(url)
506
+ # Find a plugin, and issue the "require"
507
+ # @return [Hash] plugin info: { product: , url:, version: }
508
+ def identify_plugin_for_url(url, check_only: nil)
509
+ check_only = check_only.to_sym unless check_only.nil?
556
510
  plugins.each do |plugin_name_sym, plugin_info|
557
511
  # no detection for internal plugin
558
512
  next if plugin_name_sym.eql?(CONF_PLUGIN_SYM)
513
+ next if check_only && !check_only.eql?(plugin_name_sym)
559
514
  # load plugin class
560
515
  require plugin_info[:require_stanza]
561
516
  c = self.class.plugin_class(plugin_name_sym)
517
+ # requires detection method
562
518
  next unless c.respond_to?(:detect)
563
519
  current_url = url
564
520
  detection_info = nil
@@ -567,7 +523,7 @@ module Aspera
567
523
  detection_info = c.detect(current_url)
568
524
  rescue OpenSSL::SSL::SSLError => e
569
525
  Log.log.warn(e.message)
570
- Log.log.warn('Use option --insecure=yes to ignore certificate') if e.message.include?('cert')
526
+ Log.log.warn('Use option --insecure=yes to allow unchecked certificate') if e.message.include?('cert')
571
527
  rescue StandardError => e
572
528
  Log.log.debug{"Cannot detect #{plugin_name_sym} : #{e.class}/#{e.message}"}
573
529
  end
@@ -676,6 +632,10 @@ module Aspera
676
632
  end
677
633
  end
678
634
  data['keypass'] = Fasp::Installation.instance.bypass_pass
635
+ # log is "-" no need to display
636
+ data.delete('log')
637
+ # show command line transfer spec
638
+ data['ts'] = transfer.updated_ts
679
639
  return {type: :single_object, data: data}
680
640
  when :products
681
641
  command = options.get_next_command(%i[list use])
@@ -689,7 +649,9 @@ module Aspera
689
649
  return Main.result_status("Saved to default global preset #{preset_name}")
690
650
  end
691
651
  when :install
692
- v = Fasp::Installation.instance.install_sdk(options.get_option(:sdk_url, is_type: :mandatory))
652
+ # reset to default location, if older default was used
653
+ Fasp::Installation.instance.sdk_folder = default_app_main_folder(app_name: APP_NAME_SDK) if @sdk_default_location
654
+ v = Fasp::Installation.instance.install_sdk(options.get_option(:sdk_url, mandatory: true))
693
655
  return Main.result_status("Installed version #{v}")
694
656
  when :spec
695
657
  return {
@@ -789,8 +751,8 @@ module Aspera
789
751
  return Main.result_status("Updated: #{name}")
790
752
  when :lookup
791
753
  BasicAuthPlugin.register_options(@agents)
792
- url = options.get_option(:url, is_type: :mandatory)
793
- user = options.get_option(:username, is_type: :mandatory)
754
+ url = options.get_option(:url, mandatory: true)
755
+ user = options.get_option(:username, mandatory: true)
794
756
  result = lookup_preset(url: url, username: user)
795
757
  raise 'no such config found' if result.nil?
796
758
  return {type: :single_object, data: result}
@@ -823,7 +785,6 @@ module Aspera
823
785
  end
824
786
 
825
787
  ACTIONS = %i[
826
- id
827
788
  preset
828
789
  open
829
790
  documentation
@@ -833,7 +794,6 @@ module Aspera
833
794
  flush_tokens
834
795
  echo
835
796
  wizard
836
- export_to_cli
837
797
  detect
838
798
  coffee
839
799
  ascp
@@ -844,19 +804,12 @@ module Aspera
844
804
  file
845
805
  check_update
846
806
  initdemo
847
- vault].concat(PRESET_GBL_ACTIONS).freeze
807
+ vault].freeze
848
808
 
849
809
  # "config" plugin
850
810
  def execute_action
851
811
  action = options.get_next_command(ACTIONS)
852
812
  case action
853
- when *PRESET_GBL_ACTIONS # older syntax
854
- Log.log.warn{"This syntax is deprecated, use command: preset #{action}"}
855
- return execute_preset(action: action)
856
- when :id # older syntax
857
- identifier = options.get_next_argument('config name')
858
- Log.log.warn{"This syntax is deprecated, use command: preset <verb> #{identifier}"}
859
- return execute_preset(name: identifier)
860
813
  when :preset # newer syntax
861
814
  return execute_preset
862
815
  when :open
@@ -870,7 +823,7 @@ module Aspera
870
823
  when :genkey # generate new rsa key
871
824
  private_key_path = options.get_next_argument('private key file path')
872
825
  private_key_length = options.get_next_argument('size in bits', mandatory: false) || DEFAULT_PRIVKEY_LENGTH
873
- generate_rsa_private_key(private_key_path, private_key_length)
826
+ self.class.generate_rsa_private_key(path: private_key_path, length: private_key_length)
874
827
  return Main.result_status('Generated key: ' + private_key_path)
875
828
  when :echo # display the content of a value given on command line
876
829
  result = {type: :other_struct, data: options.get_next_argument('value')}
@@ -912,70 +865,83 @@ module Aspera
912
865
  BasicAuthPlugin.register_options(@agents)
913
866
  params = {}
914
867
  # get from option, or ask
915
- params[:instance_url] = options.get_option(:url, is_type: :mandatory)
868
+ params[:instance_url] = options.get_option(:url, mandatory: true)
869
+ # check it is a well formatted url: starts with scheme
870
+ if !params[:instance_url].match?(%r{^[a-z]{1,6}://})
871
+ new_url = "https://#{params[:instance_url]}"
872
+ Log.log.warn("URL #{params[:instance_url]} does not start with a scheme, using #{new_url}")
873
+ params[:instance_url] = new_url
874
+ end
916
875
  # allow user to tell the preset name
917
876
  params[:preset_name] = options.get_option(:id)
918
- # allow user to specify type of application
919
- params[:application] = options.get_option(:value)
920
- params[:application] = params[:application].nil? ? identify_plugin_for_url(params[:instance_url])[:product] : params[:application].to_sym
921
- params[:plugin_name] = params[:application]
922
- params[:test_args] = '<replace per app>'
923
- case params[:application]
924
- when :faspex5
925
- wizard_faspex5(params)
926
- when :aoc
927
- wizard_aoc(params)
928
- else
929
- raise CliBadArgument, "Supports only: aoc. Detected: #{params[:application]}"
930
- end # product
931
- if params[:option_default]
932
- formatter.display_status("Setting config preset as default for #{params[:plugin_name]}")
933
- @config_presets[CONF_PRESET_DEFAULT][params[:plugin_name]] = params[:preset_name]
877
+ # allow user to specify type of application (symbol)
878
+ identification = identify_plugin_for_url(params[:instance_url], check_only: value_or_query(allowed_types: String))
879
+ Log.log.debug{"Detected: #{identification}"}
880
+ formatter.display_status("Detected: #{identification[:name]} at #{identification[:url]}".bold)
881
+ # we detected application (not set by user)
882
+ params[:plugin_sym] = identification[:product]
883
+ # update the url option
884
+ params[:instance_url] = identification[:url]
885
+ options.set_option(:url, params[:instance_url])
886
+ # instantiate plugin: command line options are known and wizard can be called
887
+ plugin_instance = self.class.plugin_class(params[:plugin_sym]).new(@agents.merge({skip_basic_auth_options: true}))
888
+ raise CliBadArgument, "Detected: #{params[:plugin_sym]}, no wizard available for this application" unless plugin_instance.respond_to?(:wizard)
889
+ # get default preset name if not set by user
890
+ params[:prepare] = true
891
+ plugin_instance.send(:wizard, params)
892
+ params[:prepare] = false
893
+
894
+ if params[:need_private_key]
895
+ # lets see if path to priv key is provided
896
+ private_key_path = options.get_option(:pkeypath)
897
+ # give a chance to provide
898
+ if private_key_path.nil?
899
+ formatter.display_status('Please provide path to your private RSA key, or empty to generate one:')
900
+ private_key_path = options.get_option(:pkeypath, mandatory: true).to_s
901
+ # private_key_path = File.expand_path(private_key_path)
902
+ end
903
+ # else generate path
904
+ if private_key_path.empty?
905
+ private_key_path = File.join(@main_folder, DEFAULT_PRIV_KEY_FILENAME)
906
+ end
907
+ if File.exist?(private_key_path)
908
+ formatter.display_status('Using existing key:')
909
+ else
910
+ formatter.display_status("Generating #{DEFAULT_PRIVKEY_LENGTH} bit RSA key...")
911
+ Config.generate_rsa_private_key(path: private_key_path)
912
+ formatter.display_status('Created key:')
913
+ end
914
+ formatter.display_status(private_key_path)
915
+ params[:pub_key_pem] = OpenSSL::PKey::RSA.new(File.read(private_key_path)).public_key.to_s
916
+ params[:private_key_path] = private_key_path
917
+ end
918
+
919
+ formatter.display_status("Preparing preset: #{params[:preset_name]}")
920
+ # init defaults if necessary
921
+ @config_presets[CONF_PRESET_DEFAULT] ||= {}
922
+ option_override = options.get_option(:override, mandatory: true)
923
+ raise CliError, "A default configuration already exists for plugin '#{params[:plugin_sym]}' (use --override=yes or --default=no)" \
924
+ if !option_override && options.get_option(:default, mandatory: true) && @config_presets[CONF_PRESET_DEFAULT].key?(params[:plugin_sym])
925
+ raise CliError, "Preset already exists: #{params[:preset_name]} (use --override=yes or --id=<name>)" \
926
+ if !option_override && @config_presets.key?(params[:preset_name])
927
+ wizard_result = plugin_instance.send(:wizard, params)
928
+ Log.log.debug{"wizard result: #{wizard_result}"}
929
+ raise "Internal error: missing keys in wizard result: #{wizard_result.keys}" unless %i[preset_value test_args].eql?(wizard_result.keys.sort)
930
+ @config_presets[params[:preset_name]] = wizard_result[:preset_value].stringify_keys
931
+ params[:test_args] = wizard_result[:test_args]
932
+ if options.get_option(:default, mandatory: true)
933
+ formatter.display_status("Setting config preset as default for #{params[:plugin_sym]}")
934
+ @config_presets[CONF_PRESET_DEFAULT][params[:plugin_sym].to_s] = params[:preset_name]
934
935
  else
935
936
  params[:test_args] = "-P#{params[:preset_name]} #{params[:test_args]}"
936
937
  end
937
938
  formatter.display_status('Saving config file.')
938
939
  save_presets_to_config_file
939
940
  return Main.result_status("Done.\nYou can test with:\n#{@info[:name]} #{params[:test_args]}")
940
- when :export_to_cli # this method shall be deprecated in the future: it was used to export configuration to "aspera.exe" CLI
941
- formatter.display_status('Exporting: Aspera on Cloud')
942
- require 'aspera/cli/plugins/aoc'
943
- # need url / username
944
- add_plugin_default_preset(AOC_COMMAND_V3.to_sym)
945
- # instantiate AoC plugin
946
- self.class.plugin_class(AOC_COMMAND_CURRENT).new(@agents) # TODO: is this line needed ? get options ?
947
- url = options.get_option(:url, is_type: :mandatory)
948
- cli_conf_file = Fasp::Installation.instance.cli_conf_file
949
- data = JSON.parse(File.read(cli_conf_file))
950
- organization, instance_domain = AoC.parse_url(url)
951
- key_basename = 'org_' + organization + '.pem'
952
- key_file = File.join(File.dirname(File.dirname(cli_conf_file)), 'etc', key_basename)
953
- File.write(key_file, options.get_option(:private_key, is_type: :mandatory))
954
- new_conf = {
955
- 'organization' => organization,
956
- 'hostname' => [organization, instance_domain].join('.'),
957
- 'privateKeyFilename' => key_basename,
958
- 'username' => options.get_option(:username, is_type: :mandatory)
959
- }
960
- new_conf['clientId'] = options.get_option(:client_id)
961
- new_conf['clientSecret'] = options.get_option(:client_secret)
962
- if new_conf['clientId'].nil?
963
- new_conf['clientId'], new_conf['clientSecret'] = AoC.get_client_info
964
- end
965
- entry = data['AoCAccounts'].find{|i|i['organization'].eql?(organization)}
966
- if entry.nil?
967
- data['AoCAccounts'].push(new_conf)
968
- formatter.display_status("Creating new aoc entry: #{organization}")
969
- else
970
- formatter.display_status("Updating existing aoc entry: #{organization}")
971
- entry.merge!(new_conf)
972
- end
973
- File.write(cli_conf_file, JSON.pretty_generate(data))
974
- return Main.result_status("Updated: #{cli_conf_file}")
975
941
  when :detect
976
942
  # need url / username
977
943
  BasicAuthPlugin.register_options(@agents)
978
- return {type: :single_object, data: identify_plugin_for_url(options.get_option(:url, is_type: :mandatory))}
944
+ return {type: :single_object, data: identify_plugin_for_url(options.get_option(:url, mandatory: true))}
979
945
  when :coffee
980
946
  if OpenApplication.instance.url_method.eql?(:text)
981
947
  require 'aspera/preview/terminal'
@@ -1002,7 +968,7 @@ module Aspera
1002
968
  return {type: :single_object, data: email_settings}
1003
969
  when :proxy_check
1004
970
  # ensure fpac was provided
1005
- options.get_option(:fpac, is_type: :mandatory)
971
+ options.get_option(:fpac, mandatory: true)
1006
972
  server_url = options.get_next_argument('server url')
1007
973
  return Main.result_status(@pac_exec.find_proxy_for_url(server_url))
1008
974
  when :check_update
@@ -1014,8 +980,8 @@ module Aspera
1014
980
  Log.log.info{"Creating Demo server preset: #{DEMO_SERVER_PRESET}"}
1015
981
  @config_presets[DEMO_SERVER_PRESET] = {
1016
982
  'url' => 'ssh://' + DEMO + '.asperasoft.com:33001',
1017
- 'username' => AOC_COMMAND_V2,
1018
- 'ssAP'.downcase.reverse + 'drow'.reverse => DEMO + AOC_COMMAND_V2
983
+ 'username' => ASPERA,
984
+ 'ssAP'.downcase.reverse + 'drow'.reverse => DEMO + ASPERA # cspell:disable-line
1019
985
  }
1020
986
  end
1021
987
  @config_presets[CONF_PRESET_DEFAULT] ||= {}
@@ -1036,18 +1002,24 @@ module Aspera
1036
1002
 
1037
1003
  # @return email server setting with defaults if not defined
1038
1004
  def email_settings
1039
- smtp = options.get_option(:smtp, is_type: :mandatory)
1005
+ smtp = options.get_option(:smtp, mandatory: true, allowed_types: [Hash])
1040
1006
  # change string keys into symbol keys
1041
- smtp = smtp.keys.each_with_object({}){|v, m|m[v.to_sym] = smtp[v]; }
1007
+ smtp = smtp.symbolize_keys
1042
1008
  # defaults
1043
- smtp[:tls] ||= true
1044
- smtp[:port] ||= smtp[:tls] ? 587 : 25
1009
+ smtp[:tls] = !smtp[:ssl] unless smtp.key?(:tls)
1010
+ smtp[:port] ||= if smtp[:tls]
1011
+ 587
1012
+ elsif smtp[:ssl]
1013
+ 465
1014
+ else
1015
+ 25
1016
+ end
1045
1017
  smtp[:from_email] ||= smtp[:username] if smtp.key?(:username)
1046
1018
  smtp[:from_name] ||= smtp[:from_email].gsub(/@.*$/, '').gsub(/[^a-zA-Z]/, ' ').capitalize if smtp.key?(:username)
1047
1019
  smtp[:domain] ||= smtp[:from_email].gsub(/^.*@/, '') if smtp.key?(:from_email)
1048
1020
  # check minimum required
1049
1021
  %i[server port domain].each do |n|
1050
- raise "Missing smtp parameter: #{n}" unless smtp.key?(n)
1022
+ raise "Missing mandatory smtp parameter: #{n}" unless smtp.key?(n)
1051
1023
  end
1052
1024
  Log.log.debug{"smtp=#{smtp}"}
1053
1025
  return smtp
@@ -1059,8 +1031,8 @@ module Aspera
1059
1031
  end
1060
1032
 
1061
1033
  def send_email_template(email_template_default: nil, values: {})
1062
- values[:to] ||= options.get_option(:notif_to, is_type: :mandatory)
1063
- notif_template = options.get_option(:notif_template, is_type: email_template_default.nil? ? :mandatory : :optional) || email_template_default
1034
+ values[:to] ||= options.get_option(:notif_to, mandatory: true)
1035
+ notif_template = options.get_option(:notif_template, mandatory: email_template_default.nil?) || email_template_default
1064
1036
  mail_conf = email_settings
1065
1037
  values[:from_name] ||= mail_conf[:from_name]
1066
1038
  values[:from_email] ||= mail_conf[:from_email]
@@ -1081,6 +1053,7 @@ module Aspera
1081
1053
  Log.dump(:msg_with_headers, msg_with_headers)
1082
1054
  smtp = Net::SMTP.new(mail_conf[:server], mail_conf[:port])
1083
1055
  smtp.enable_starttls if mail_conf[:tls]
1056
+ smtp.enable_tls if mail_conf[:ssl]
1084
1057
  smtp.start(*start_options) do |smtp_session|
1085
1058
  smtp_session.send_message(msg_with_headers, values[:from_email], values[:to])
1086
1059
  end
@@ -1097,20 +1070,20 @@ module Aspera
1097
1070
 
1098
1071
  # returns [String] name if config_presets has default
1099
1072
  # returns nil if there is no config or bypass default params
1100
- def get_plugin_default_config_name(plugin_sym)
1073
+ def get_plugin_default_config_name(plugin_name_sym)
1101
1074
  raise 'internal error: config_presets shall be defined' if @config_presets.nil?
1102
1075
  if !@use_plugin_defaults
1103
1076
  Log.log.debug('skip default config')
1104
1077
  return nil
1105
1078
  end
1106
1079
  if @config_presets.key?(CONF_PRESET_DEFAULT) &&
1107
- @config_presets[CONF_PRESET_DEFAULT].key?(plugin_sym.to_s)
1108
- default_config_name = @config_presets[CONF_PRESET_DEFAULT][plugin_sym.to_s]
1080
+ @config_presets[CONF_PRESET_DEFAULT].key?(plugin_name_sym.to_s)
1081
+ default_config_name = @config_presets[CONF_PRESET_DEFAULT][plugin_name_sym.to_s]
1109
1082
  if !@config_presets.key?(default_config_name)
1110
1083
  Log.log.error do
1111
- "Default config name [#{default_config_name}] specified for plugin [#{plugin_sym}], but it does not exist in config file.\n"\
1084
+ "Default config name [#{default_config_name}] specified for plugin [#{plugin_name_sym}], but it does not exist in config file.\n"\
1112
1085
  'Please fix the issue: either create preset with one parameter: '\
1113
- "(#{@info[:name]} config id #{default_config_name} init @json:'{}') or remove default (#{@info[:name]} config id default remove #{plugin_sym})."
1086
+ "(#{@info[:name]} config id #{default_config_name} init @json:'{}') or remove default (#{@info[:name]} config id default remove #{plugin_name_sym})."
1114
1087
  end
1115
1088
  end
1116
1089
  raise CliError, "Config name [#{default_config_name}] must be a hash, check config file." if !@config_presets[default_config_name].is_a?(Hash)
@@ -1160,7 +1133,7 @@ module Aspera
1160
1133
  def vault
1161
1134
  if @vault.nil?
1162
1135
  vault_info = options.get_option(:vault) || {'type' => 'file', 'name' => 'vault.bin'}
1163
- vault_password = options.get_option(:vault_password, is_type: :mandatory)
1136
+ vault_password = options.get_option(:vault_password, mandatory: true)
1164
1137
  raise 'vault must be Hash' unless vault_info.is_a?(Hash)
1165
1138
  vault_type = vault_info['type'] || 'file'
1166
1139
  vault_name = vault_info['name'] || (vault_type.eql?('file') ? 'vault.bin' : PROGRAM_NAME)
@@ -1214,169 +1187,6 @@ module Aspera
1214
1187
  end
1215
1188
  return secret
1216
1189
  end
1217
-
1218
- def wizard_aoc(params)
1219
- formatter.display_status('Detected: Aspera on Cloud'.bold)
1220
- params[:plugin_name] = AOC_COMMAND_CURRENT
1221
- organization = AoC.parse_url(params[:instance_url]).first
1222
- # if not defined by user, generate name
1223
- params[:preset_name] = [params[:application], organization].join('_') if params[:preset_name].nil?
1224
- formatter.display_status("Preparing preset: #{params[:preset_name]}")
1225
- # init defaults if necessary
1226
- @config_presets[CONF_PRESET_DEFAULT] ||= {}
1227
- option_override = options.get_option(:override, is_type: :mandatory)
1228
- params[:option_default] = options.get_option(:default, is_type: :mandatory)
1229
- Log.log.error{"override=#{option_override} -> #{option_override.class}"}
1230
- raise CliError, "A default configuration already exists for plugin '#{params[:plugin_name]}' (use --override=yes or --default=no)" \
1231
- if !option_override && params[:option_default] && @config_presets[CONF_PRESET_DEFAULT].key?(params[:plugin_name])
1232
- raise CliError, "Preset already exists: #{params[:preset_name]} (use --override=yes or --id=<name>)" \
1233
- if !option_override && @config_presets.key?(params[:preset_name])
1234
- # lets see if path to priv key is provided
1235
- private_key_path = options.get_option(:pkeypath)
1236
- # give a chance to provide
1237
- if private_key_path.nil?
1238
- formatter.display_status('Please provide path to your private RSA key, or empty to generate one:')
1239
- private_key_path = options.get_option(:pkeypath, is_type: :mandatory).to_s
1240
- end
1241
- # else generate path
1242
- if private_key_path.empty?
1243
- private_key_path = File.join(@main_folder, DEFAULT_PRIV_KEY_FILENAME)
1244
- end
1245
- if File.exist?(private_key_path)
1246
- formatter.display_status('Using existing key:')
1247
- else
1248
- formatter.display_status("Generating #{DEFAULT_PRIVKEY_LENGTH} bit RSA key...")
1249
- generate_rsa_private_key(private_key_path, DEFAULT_PRIVKEY_LENGTH)
1250
- formatter.display_status('Created:')
1251
- end
1252
- formatter.display_status(private_key_path)
1253
- pub_key_pem = OpenSSL::PKey::RSA.new(File.read(private_key_path)).public_key.to_s
1254
- # declare command line options for AoC
1255
- require 'aspera/cli/plugins/aoc'
1256
- # make username mandatory for jwt, this triggers interactive input
1257
- options.get_option(:username, is_type: :mandatory)
1258
- # instantiate AoC plugin, so that command line options are known
1259
- aoc_api = self.class.plugin_class(params[:plugin_name]).new(@agents.merge({skip_basic_auth_options: true, private_key_path: private_key_path})).aoc_api
1260
- auto_set_pub_key = false
1261
- auto_set_jwt = false
1262
- use_browser_authentication = false
1263
- if options.get_option(:use_generic_client)
1264
- formatter.display_status('Using global client_id.')
1265
- formatter.display_status('Please Login to your Aspera on Cloud instance.'.red)
1266
- formatter.display_status('Navigate to your "Account Settings"'.red)
1267
- formatter.display_status('Check or update the value of "Public Key" to be:'.red.blink)
1268
- formatter.display_status(pub_key_pem.to_s)
1269
- if !options.get_option(:test_mode)
1270
- formatter.display_status('Once updated or validated, press enter.')
1271
- OpenApplication.instance.uri(params[:instance_url])
1272
- $stdin.gets
1273
- end
1274
- else
1275
- formatter.display_status('Using organization specific client_id.')
1276
- if options.get_option(:client_id).nil? || options.get_option(:client_secret, is_type: :optional).nil?
1277
- formatter.display_status('Please login to your Aspera on Cloud instance.'.red)
1278
- formatter.display_status('Go to: Apps->Admin->Organization->Integrations')
1279
- formatter.display_status('Create or check if there is an existing integration named:')
1280
- formatter.display_status("- name: #{@info[:name]}")
1281
- formatter.display_status("- redirect uri: #{DEFAULT_REDIRECT}")
1282
- formatter.display_status('- origin: localhost')
1283
- formatter.display_status('Once created or identified,')
1284
- formatter.display_status('Please enter:'.red)
1285
- end
1286
- OpenApplication.instance.uri("#{params[:instance_url]}/#{AOC_PATH_API_CLIENTS}")
1287
- options.get_option(:client_id, is_type: :mandatory)
1288
- options.get_option(:client_secret, is_type: :mandatory)
1289
- use_browser_authentication = true
1290
- end
1291
- if use_browser_authentication
1292
- formatter.display_status('We will use web authentication to bootstrap.')
1293
- auto_set_pub_key = true
1294
- auto_set_jwt = true
1295
- aoc_api.oauth.generic_parameters[:grant_method] = :web
1296
- aoc_api.oauth.generic_parameters[:scope] = AoC::SCOPE_FILES_ADMIN
1297
- aoc_api.oauth.specific_parameters[:redirect_uri] = DEFAULT_REDIRECT
1298
- end
1299
- myself = aoc_api.read('self')[:data]
1300
- if auto_set_pub_key
1301
- raise CliError, 'Public key is already set in profile (use --override=yes)' unless myself['public_key'].empty? || option_override
1302
- formatter.display_status('Updating profile with new key')
1303
- aoc_api.update("users/#{myself['id']}", {'public_key' => pub_key_pem})
1304
- end
1305
- if auto_set_jwt
1306
- formatter.display_status('Enabling JWT for client')
1307
- aoc_api.update("clients/#{options.get_option(:client_id)}", {'jwt_grant_enabled' => true, 'explicit_authorization_required' => false})
1308
- end
1309
- formatter.display_status("Creating new config preset: #{params[:preset_name]}")
1310
- @config_presets[params[:preset_name]] = {
1311
- :url.to_s => options.get_option(:url),
1312
- :username.to_s => myself['email'],
1313
- :auth.to_s => :jwt.to_s,
1314
- :private_key.to_s => '@file:' + private_key_path
1315
- }
1316
- # set only if non nil
1317
- %i[client_id client_secret].each do |s|
1318
- o = options.get_option(s)
1319
- @config_presets[params[:preset_name]][s.to_s] = o unless o.nil?
1320
- end
1321
- params[:test_args] = "#{params[:plugin_name]} user profile show"
1322
- end
1323
-
1324
- def wizard_faspex5(params)
1325
- formatter.display_status('Detected: Faspex v5'.bold)
1326
- # if not defined by user, generate unique name
1327
- params[:preset_name] = [params[:application]].concat(URI.parse(params[:instance_url]).host.gsub(/[^a-z0-9.]/, '').split('.')).join('_') \
1328
- if params[:preset_name].nil?
1329
- formatter.display_status("Preparing preset: #{params[:preset_name]}")
1330
- # init defaults if necessary
1331
- @config_presets[CONF_PRESET_DEFAULT] ||= {}
1332
- option_override = options.get_option(:override, is_type: :mandatory)
1333
- params[:option_default] = options.get_option(:default, is_type: :mandatory)
1334
- Log.log.error{"override=#{option_override} -> #{option_override.class}"}
1335
- raise CliError, "A default configuration already exists for plugin '#{params[:plugin_name]}' (use --override=yes or --default=no)" \
1336
- if !option_override && params[:option_default] && @config_presets[CONF_PRESET_DEFAULT].key?(params[:plugin_name])
1337
- raise CliError, "Preset already exists: #{params[:preset_name]} (use --override=yes or --id=<name>)" \
1338
- if !option_override && @config_presets.key?(params[:preset_name])
1339
- # lets see if path to priv key is provided
1340
- private_key_path = options.get_option(:pkeypath)
1341
- # give a chance to provide
1342
- if private_key_path.nil?
1343
- formatter.display_status('Please provide path to your private RSA key, or empty to generate one:')
1344
- private_key_path = options.get_option(:pkeypath, is_type: :mandatory).to_s
1345
- end
1346
- # else generate path
1347
- if private_key_path.empty?
1348
- private_key_path = File.join(@main_folder, DEFAULT_PRIV_KEY_FILENAME)
1349
- end
1350
- if File.exist?(private_key_path)
1351
- formatter.display_status('Using existing key:')
1352
- else
1353
- formatter.display_status("Generating #{DEFAULT_PRIVKEY_LENGTH} bit RSA key...")
1354
- generate_rsa_private_key(private_key_path, DEFAULT_PRIVKEY_LENGTH)
1355
- formatter.display_status('Created:')
1356
- end
1357
- formatter.display_status(private_key_path)
1358
- pub_key_pem = OpenSSL::PKey::RSA.new(File.read(private_key_path)).public_key.to_s
1359
- # declare command line options for AoC
1360
- require 'aspera/cli/plugins/faspex5'
1361
- self.class.plugin_class(params[:plugin_name]).new(@agents.merge({skip_basic_auth_options: true}))
1362
- formatter.display_status('Please login to Faspex 5.'.red)
1363
- OpenApplication.instance.uri(params[:instance_url])
1364
- formatter.display_status('Navigate to: 𓃑 → Admin → Configurations → API clients')
1365
- formatter.display_status('Create a client with:')
1366
- formatter.display_status('- JWT enabled')
1367
- formatter.display_status('- The following public key:')
1368
- formatter.display_status(pub_key_pem.to_s)
1369
- formatter.display_status('Once created, copy the following parameters:')
1370
- @config_presets[params[:preset_name]] = {
1371
- :url.to_s => options.get_option(:url),
1372
- :username.to_s => options.get_option(:username),
1373
- :auth.to_s => :jwt.to_s,
1374
- :private_key.to_s => '@file:' + private_key_path,
1375
- :client_id.to_s => options.get_option(:client_id, is_type: :mandatory),
1376
- :client_secret.to_s => options.get_option(:client_secret, is_type: :mandatory)
1377
- }
1378
- params[:test_args] = "#{params[:plugin_name]} user profile show"
1379
- end
1380
1190
  end
1381
1191
  end
1382
1192
  end