aspera-cli 4.29.1 → 4.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (264) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +4 -4
  3. data/CHANGELOG.md +119 -0
  4. data/CONTRIBUTING.md +8 -1
  5. data/README.md +2 -0
  6. data/TODO.md +4 -5
  7. data/bin/asession +2 -2
  8. data/docs/README.md +616 -86
  9. data/docs/test-mcp-with-ai.md +4 -0
  10. data/lib/aspera/agent/base.rb +62 -6
  11. data/lib/aspera/agent/factory.rb +127 -20
  12. data/lib/aspera/ascp/data_repository.rb +71 -0
  13. data/lib/aspera/ascp/installation.rb +16 -11
  14. data/lib/aspera/ascp/log_analyzer/lines.rb +4 -4
  15. data/lib/aspera/ascp/log_analyzer/log_file.rb +5 -3
  16. data/lib/aspera/ascp/log_analyzer/records.rb +11 -6
  17. data/lib/aspera/ascp/log_analyzer.rb +43 -18
  18. data/lib/aspera/ascp/log_locations.rb +2 -2
  19. data/lib/aspera/assert.rb +8 -0
  20. data/lib/aspera/bundle_registry.rb +528 -0
  21. data/lib/aspera/cli/argument.rb +110 -0
  22. data/lib/aspera/cli/bool_value.rb +41 -0
  23. data/lib/aspera/cli/bootstrapper.rb +31 -24
  24. data/lib/aspera/cli/command/mount.rb +53 -0
  25. data/lib/aspera/cli/command/registry.rb +434 -0
  26. data/lib/aspera/cli/command.rb +95 -0
  27. data/lib/aspera/cli/command_line.rb +91 -91
  28. data/lib/aspera/cli/complete.rb +22 -0
  29. data/lib/aspera/cli/completion_actions.rb +28 -26
  30. data/lib/aspera/cli/context.rb +29 -6
  31. data/lib/aspera/cli/error.rb +39 -0
  32. data/lib/aspera/cli/extended_value.rb +25 -4
  33. data/lib/aspera/cli/formatter.rb +8 -8
  34. data/lib/aspera/cli/hints.rb +17 -52
  35. data/lib/aspera/cli/http.rb +17 -12
  36. data/lib/aspera/cli/mailer.rb +7 -24
  37. data/lib/aspera/cli/mcp/tool.rb +10 -2
  38. data/lib/aspera/cli/option/declarator.rb +80 -0
  39. data/lib/aspera/cli/option/registry.rb +74 -0
  40. data/lib/aspera/cli/option/source.rb +38 -0
  41. data/lib/aspera/cli/option/type.rb +37 -0
  42. data/lib/aspera/cli/option/value.rb +376 -0
  43. data/lib/aspera/cli/option.rb +78 -0
  44. data/lib/aspera/cli/options.schema.yaml +28 -783
  45. data/lib/aspera/cli/parser.rb +73 -41
  46. data/lib/aspera/cli/plugins/base.rb +122 -42
  47. data/lib/aspera/cli/plugins/basic_auth.rb +13 -2
  48. data/lib/aspera/cli/plugins/config.rb +101 -167
  49. data/lib/aspera/cli/plugins/factory.rb +139 -43
  50. data/lib/aspera/cli/plugins/mcp.rb +61 -54
  51. data/lib/aspera/cli/plugins/oauth.rb +19 -6
  52. data/lib/aspera/cli/poll.rb +14 -20
  53. data/lib/aspera/cli/preset_actions.rb +11 -3
  54. data/lib/aspera/cli/preset_manager.rb +16 -6
  55. data/lib/aspera/cli/result.rb +2 -2
  56. data/lib/aspera/cli/runner.rb +71 -99
  57. data/lib/aspera/cli/secret_finder.rb +1 -1
  58. data/lib/aspera/cli/security.rb +102 -4
  59. data/lib/aspera/{preview/terminal.rb → cli/terminal_image.rb} +93 -94
  60. data/lib/aspera/cli/vault_manager.rb +3 -3
  61. data/lib/aspera/cli/version.rb +1 -1
  62. data/lib/aspera/cli/wizard.rb +9 -3
  63. data/lib/aspera/coverage.rb +1 -2
  64. data/lib/aspera/line_logger.rb +35 -6
  65. data/lib/aspera/log.rb +3 -2
  66. data/lib/aspera/oauth/client/base.rb +19 -1
  67. data/lib/aspera/oauth/client/factory.rb +1 -7
  68. data/lib/aspera/plugin.schema.yaml +178 -0
  69. data/lib/aspera/plugins/alee/api.rb +25 -0
  70. data/lib/aspera/{cli/plugins/alee.rb → plugins/alee/commands.rb} +10 -8
  71. data/lib/aspera/plugins/alee/plugin.yaml +3 -0
  72. data/lib/aspera/plugins/aoc/admin_resources.rb +148 -0
  73. data/lib/aspera/plugins/aoc/api.rb +783 -0
  74. data/lib/aspera/{cli/plugins/aoc.rb → plugins/aoc/commands.rb} +404 -330
  75. data/lib/aspera/plugins/aoc/graphql.rb +45 -0
  76. data/lib/aspera/plugins/aoc/plugin.yaml +31 -0
  77. data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +15042 -7076
  78. data/lib/aspera/plugins/aoc/schemas/options.yaml +47 -0
  79. data/lib/aspera/plugins/ats/api.rb +51 -0
  80. data/lib/aspera/{cli/plugins/ats.rb → plugins/ats/commands.rb} +33 -33
  81. data/lib/aspera/plugins/ats/plugin.yaml +6 -0
  82. data/lib/aspera/plugins/connect/agent.rb +199 -0
  83. data/lib/aspera/plugins/connect/plugin.yaml +11 -0
  84. data/lib/aspera/plugins/connect/schemas/agent_options.yaml +6 -0
  85. data/lib/aspera/{cli/plugins/console.rb → plugins/console/commands.rb} +41 -33
  86. data/lib/aspera/plugins/console/plugin.yaml +8 -0
  87. data/lib/aspera/plugins/cos/api.rb +114 -0
  88. data/lib/aspera/{cli/plugins/cos.rb → plugins/cos/commands.rb} +19 -16
  89. data/lib/aspera/plugins/cos/plugin.yaml +9 -0
  90. data/lib/aspera/plugins/cos/schemas/options.yaml +30 -0
  91. data/lib/aspera/plugins/desktop/agent.rb +165 -0
  92. data/lib/aspera/plugins/desktop/plugin.yaml +11 -0
  93. data/lib/aspera/plugins/desktop/schemas/agent_options.yaml +6 -0
  94. data/lib/aspera/plugins/direct/agent.rb +518 -0
  95. data/lib/aspera/plugins/direct/plugin.yaml +11 -0
  96. data/lib/aspera/plugins/direct/schemas/agent_options.yaml +86 -0
  97. data/lib/aspera/plugins/faspex4/gateway_options.rb +18 -0
  98. data/lib/aspera/plugins/faspex4/gw_servlet.rb +122 -0
  99. data/lib/aspera/plugins/faspex4/plugin.yaml +7 -0
  100. data/lib/aspera/plugins/faspex4/schemas/options.yaml +57 -0
  101. data/lib/aspera/plugins/faspex5/api.rb +269 -0
  102. data/lib/aspera/{cli/plugins/faspex5.rb → plugins/faspex5/commands.rb} +152 -114
  103. data/lib/aspera/plugins/faspex5/faspex4_post_proc_servlet.rb +241 -0
  104. data/lib/aspera/plugins/faspex5/plugin.yaml +14 -0
  105. data/lib/aspera/{schema → plugins/faspex5/schemas}/IBM Aspera Faspex API-5.0-enhanced.yaml +279 -76
  106. data/lib/aspera/plugins/faspex5/schemas/options.yaml +87 -0
  107. data/lib/aspera/{cli/plugins/faspio.rb → plugins/faspio/commands.rb} +11 -7
  108. data/lib/aspera/plugins/faspio/plugin.yaml +8 -0
  109. data/lib/aspera/{schema → plugins/faspio/schemas}/IBM Aspera faspio Gateway API-1.0.0-enhanced.yaml +4 -2
  110. data/lib/aspera/plugins/httpgw/agent.rb +126 -0
  111. data/lib/aspera/plugins/httpgw/api.rb +411 -0
  112. data/lib/aspera/{cli/plugins/httpgw.rb → plugins/httpgw/commands.rb} +9 -9
  113. data/lib/aspera/plugins/httpgw/plugin.yaml +12 -0
  114. data/lib/aspera/plugins/httpgw/schemas/agent_options.yaml +24 -0
  115. data/lib/aspera/plugins/node/agent.rb +184 -0
  116. data/lib/aspera/plugins/node/api.rb +699 -0
  117. data/lib/aspera/{cli/plugins/node.rb → plugins/node/commands.rb} +166 -141
  118. data/lib/aspera/plugins/node/emulator.rb +774 -0
  119. data/lib/aspera/plugins/node/plugin.yaml +20 -0
  120. data/lib/aspera/plugins/node/schemas/agent_options.yaml +20 -0
  121. data/lib/aspera/plugins/node/schemas/options.yaml +190 -0
  122. data/lib/aspera/{cli/plugins/orchestrator.rb → plugins/orchestrator/commands.rb} +139 -110
  123. data/lib/aspera/plugins/orchestrator/plugin.yaml +34 -0
  124. data/lib/aspera/{schema → plugins/orchestrator/schemas}/IBM Aspera Orchestrator API-v1-enhanced.yaml +486 -16
  125. data/lib/aspera/plugins/orchestrator/schemas/options.yaml +143 -0
  126. data/lib/aspera/plugins/orchestrator/workflow_checker.rb +692 -0
  127. data/lib/aspera/{cli/plugins/preview.rb → plugins/preview/commands.rb} +53 -51
  128. data/lib/aspera/plugins/preview/file_types.rb +121 -0
  129. data/lib/aspera/plugins/preview/generator.rb +350 -0
  130. data/lib/aspera/plugins/preview/plugin.yaml +12 -0
  131. data/lib/aspera/{preview/options.schema.yaml → plugins/preview/schemas/options.yaml} +1 -1
  132. data/lib/aspera/plugins/preview/utils.rb +213 -0
  133. data/lib/aspera/plugins/server/ascmd.rb +374 -0
  134. data/lib/aspera/{cli/plugins/server.rb → plugins/server/commands.rb} +48 -32
  135. data/lib/aspera/plugins/server/plugin.yaml +9 -0
  136. data/lib/aspera/plugins/server/schemas/options.yaml +30 -0
  137. data/lib/aspera/{cli/plugins/shares.rb → plugins/shares/commands.rb} +29 -21
  138. data/lib/aspera/plugins/shares/plugin.yaml +10 -0
  139. data/lib/aspera/plugins/shares/shares_web.rb +97 -0
  140. data/lib/aspera/plugins/transferd/agent.rb +258 -0
  141. data/lib/aspera/plugins/transferd/api.rb +180 -0
  142. data/lib/aspera/plugins/transferd/client.rb +67 -0
  143. data/lib/aspera/{cli/plugins/transferd.rb → plugins/transferd/commands.rb} +43 -42
  144. data/lib/aspera/plugins/transferd/config_commands.rb +38 -0
  145. data/lib/aspera/plugins/transferd/plugin.yaml +27 -0
  146. data/lib/aspera/plugins/transferd/product.rb +146 -0
  147. data/lib/aspera/plugins/transferd/schemas/agent_options.yaml +31 -0
  148. data/lib/aspera/plugins/transferd/schemas/options.yaml +80 -0
  149. data/lib/aspera/plugins/transferd/service.rb +617 -0
  150. data/lib/aspera/plugins/xfer/ascp_actions.rb +131 -0
  151. data/lib/aspera/plugins/xfer/ascp_logs_actions.rb +198 -0
  152. data/lib/aspera/plugins/xfer/async_transfer_store.rb +131 -0
  153. data/lib/aspera/plugins/xfer/config_commands.rb +119 -0
  154. data/lib/aspera/plugins/xfer/helper.rb +19 -0
  155. data/lib/aspera/plugins/xfer/plugin.yaml +42 -0
  156. data/lib/aspera/plugins/xfer/schemas/agent_extension.schema.yaml +26 -0
  157. data/lib/aspera/plugins/xfer/schemas/options.yaml +125 -0
  158. data/lib/aspera/plugins/xfer/sync_actions.rb +253 -0
  159. data/lib/aspera/plugins/xfer/transfer_actions.rb +176 -0
  160. data/lib/aspera/plugins/xfer/transfer_agent.rb +505 -0
  161. data/lib/aspera/products/cli_v3.rb +34 -0
  162. data/lib/aspera/products/connect.rb +1 -1
  163. data/lib/aspera/products/drive.rb +29 -0
  164. data/lib/aspera/products/hsts.rb +34 -0
  165. data/lib/aspera/products/transferd.rb +25 -3
  166. data/lib/aspera/products.rb +54 -0
  167. data/lib/aspera/prompt.rb +184 -0
  168. data/lib/aspera/proxy_auto_config.rb +3 -3
  169. data/lib/aspera/rest/aspera_errors.rb +4 -38
  170. data/lib/aspera/rest/error_analyzer.rb +6 -2
  171. data/lib/aspera/rest/list.rb +4 -5
  172. data/lib/aspera/schema/reader.rb +15 -0
  173. data/lib/aspera/schema/registry.rb +239 -45
  174. data/lib/aspera/schema/validator.rb +63 -17
  175. data/lib/aspera/sealed_hash.rb +4 -0
  176. data/lib/aspera/secret/hider.rb +159 -24
  177. data/lib/aspera/secret/reference.rb +8 -0
  178. data/lib/aspera/secret/resolver.rb +8 -4
  179. data/lib/aspera/secret/store/base.rb +10 -9
  180. data/lib/aspera/secret/store/encrypted_hash.rb +6 -6
  181. data/lib/aspera/secret/store/hashicorp_vault.rb +3 -3
  182. data/lib/aspera/secret/store/keeper.rb +2 -2
  183. data/lib/aspera/secret/store/macos_security.rb +2 -3
  184. data/lib/aspera/secret/store/one_password_api.rb +2 -2
  185. data/lib/aspera/secret/store/one_password_cli.rb +3 -3
  186. data/lib/aspera/secret/store/secret_service.rb +2 -2
  187. data/lib/aspera/ssl.rb +3 -3
  188. data/lib/aspera/standard_input.rb +20 -0
  189. data/lib/aspera/{schema → sync}/async_tables.yaml +1 -1
  190. data/lib/aspera/sync/database.rb +7 -0
  191. data/lib/aspera/sync/log_parser.rb +138 -0
  192. data/lib/aspera/sync/operations.rb +59 -34
  193. data/lib/aspera/transfer/command_line_builder.rb +248 -0
  194. data/lib/aspera/transfer/command_line_converter.rb +37 -0
  195. data/lib/aspera/transfer/faux_file.rb +2 -2
  196. data/lib/aspera/transfer/parameters.rb +9 -10
  197. data/lib/aspera/transfer/spec.rb +28 -1
  198. data/lib/aspera/transfer/spec.schema.yaml +30 -5
  199. data/lib/aspera/units/decimal.rb +1 -1
  200. data/lib/aspera/units/timestamp.rb +84 -0
  201. data/lib/aspera/uri_reader.rb +2 -2
  202. data/lib/aspera/web_auth/paste.rb +2 -2
  203. data/lib/aspera/web_server_simple.rb +10 -4
  204. data.tar.gz.sig +0 -0
  205. metadata +137 -80
  206. metadata.gz.sig +0 -0
  207. data/lib/aspera/agent/connect.rb +0 -188
  208. data/lib/aspera/agent/desktop.rb +0 -154
  209. data/lib/aspera/agent/direct.rb +0 -496
  210. data/lib/aspera/agent/httpgw.rb +0 -100
  211. data/lib/aspera/agent/node.rb +0 -166
  212. data/lib/aspera/agent/transferd.rb +0 -341
  213. data/lib/aspera/api/alee.rb +0 -19
  214. data/lib/aspera/api/aoc.rb +0 -776
  215. data/lib/aspera/api/ats.rb +0 -49
  216. data/lib/aspera/api/cos_node.rb +0 -107
  217. data/lib/aspera/api/faspex.rb +0 -258
  218. data/lib/aspera/api/httpgw.rb +0 -409
  219. data/lib/aspera/api/node.rb +0 -684
  220. data/lib/aspera/ascmd.rb +0 -248
  221. data/lib/aspera/cli/ascp_actions.rb +0 -113
  222. data/lib/aspera/cli/ascp_logs_actions.rb +0 -188
  223. data/lib/aspera/cli/async_transfer_store.rb +0 -129
  224. data/lib/aspera/cli/command_registry.rb +0 -371
  225. data/lib/aspera/cli/command_spec.rb +0 -273
  226. data/lib/aspera/cli/option_declarator.rb +0 -74
  227. data/lib/aspera/cli/option_registry.rb +0 -72
  228. data/lib/aspera/cli/option_types.rb +0 -120
  229. data/lib/aspera/cli/option_value.rb +0 -345
  230. data/lib/aspera/cli/prompt.rb +0 -186
  231. data/lib/aspera/cli/sync_actions.rb +0 -181
  232. data/lib/aspera/cli/transfer_actions.rb +0 -98
  233. data/lib/aspera/cli/transfer_agent.rb +0 -348
  234. data/lib/aspera/command_line_builder.rb +0 -244
  235. data/lib/aspera/command_line_converter.rb +0 -35
  236. data/lib/aspera/data_repository.rb +0 -69
  237. data/lib/aspera/faspex_gw.rb +0 -172
  238. data/lib/aspera/faspex_postproc.rb +0 -237
  239. data/lib/aspera/graphql.rb +0 -41
  240. data/lib/aspera/node_emulator.rb +0 -758
  241. data/lib/aspera/oauth/client/shares_web.rb +0 -94
  242. data/lib/aspera/orchestrator_workflow_checker.rb +0 -688
  243. data/lib/aspera/preview/file_types.rb +0 -119
  244. data/lib/aspera/preview/generator.rb +0 -345
  245. data/lib/aspera/preview/utils.rb +0 -211
  246. data/lib/aspera/products/other.rb +0 -92
  247. data/lib/aspera/products/transferd_service.rb +0 -610
  248. /data/lib/aspera/{data → ascp/data}/1 +0 -0
  249. /data/lib/aspera/{data → ascp/data}/2 +0 -0
  250. /data/lib/aspera/{data → ascp/data}/3 +0 -0
  251. /data/lib/aspera/{data → ascp/data}/4 +0 -0
  252. /data/lib/aspera/{data → ascp/data}/5 +0 -0
  253. /data/lib/aspera/{data → ascp/data}/6 +0 -0
  254. /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_account.graphql +0 -0
  255. /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_usage.graphql +0 -0
  256. /data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +0 -0
  257. /data/lib/aspera/{schema → plugins/console/schemas}/IBM Aspera Console-enhanced.yaml +0 -0
  258. /data/lib/aspera/{schema → plugins/node/schemas}/IBM Aspera Node API-4.4.6.yaml +0 -0
  259. /data/lib/aspera/{preview → plugins/preview}/image_error.png +0 -0
  260. /data/lib/aspera/{preview → plugins/preview}/video_error.png +0 -0
  261. /data/lib/aspera/{schema → plugins/shares/schemas}/IBM_Aspera_Shares.yaml +0 -0
  262. /data/lib/{transferd_pb.rb → aspera/plugins/transferd/grpc/transferd_pb.rb} +0 -0
  263. /data/lib/{transferd_services_pb.rb → aspera/plugins/transferd/grpc/transferd_services_pb.rb} +0 -0
  264. /data/lib/aspera/{schema → plugins/transferd/schemas}/transferd-config.schema.json +0 -0
@@ -3,16 +3,24 @@
3
3
  # SPDX-FileCopyrightText: IBM Corp.
4
4
  # SPDX-License-Identifier: Apache-2.0
5
5
 
6
- require_relative 'basic_auth'
7
- require_relative 'node'
6
+ require_relative '../../cli/plugins/basic_auth'
7
+ require_relative '../../cli/result'
8
+ require_relative '../../schema/registry'
9
+ require_relative '../node/commands'
10
+ require_relative '../node/api'
11
+ require_relative 'shares_web'
8
12
  require_relative '../../assert'
9
13
  require_relative '../../rest/list'
10
14
 
11
15
  module Aspera
12
- module Cli
13
- module Plugins
16
+ module Plugins
17
+ module Shares
14
18
  # Plugin for Aspera Shares v1
15
- class Shares < BasicAuth
19
+ class Commands < Cli::Plugins::Base
20
+ include Cli::Plugins::BasicAuth
21
+
22
+ # Key of the Shares API in the schemas of the bundle (manifest), with the path prefix of the admin API
23
+ API_SCHEMA = 'shares+/api/v1'
16
24
  # path for node API after base url
17
25
  NODE_API_PATH = 'node_api'
18
26
  # path for node admin after base url
@@ -198,9 +206,9 @@ module Aspera
198
206
  # --- DSL ---
199
207
 
200
208
  command :health, description: 'Check Shares health'
201
- command :info, description: 'Show server information', action: ->(**) { Result::SingleObject.new(basic_auth_api(NODE_API_PATH).read('info', headers: {'Content-Type' => Mime::JSON})) }
209
+ command :info, description: 'Show server information', action: ->(**) { Cli::Result::SingleObject.new(basic_auth_api(NODE_API_PATH).read('info', headers: {'Content-Type' => Mime::JSON})) }
202
210
  command :files, description: 'Browse and transfer files on Shares', aliases: [:repository],
203
- mount: {plugin: Node, instance: :shares_node_plugin, only: Node::COMMANDS_SHARES}
211
+ mount: {plugin: Node::Commands, instance: :shares_node_plugin, only: Node::Commands::COMMANDS_SHARES}
204
212
  command :admin, description: 'Administer Shares', setup: :setup_admin
205
213
  command :share, description: 'Shares accessible to current user'
206
214
 
@@ -233,7 +241,7 @@ module Aspera
233
241
  crud_commands entity: 'data/smtp_server',
234
242
  api: :@api_shares_admin,
235
243
  is_singleton: true,
236
- body_component: Schema::Registry::SHARES,
244
+ body_component: API_SCHEMA,
237
245
  operations: %i[show create modify]
238
246
  end
239
247
  commands_under :directory do
@@ -322,7 +330,7 @@ module Aspera
322
330
  name: "local #{entity_type}",
323
331
  lookup: lookup_method_local,
324
332
  display_fields: user_fields,
325
- body_component: Schema::Registry::SHARES
333
+ body_component: API_SCHEMA
326
334
  if entity_type.eql?(:group)
327
335
  command :users,
328
336
  description: 'Manage users of a local group',
@@ -393,7 +401,7 @@ module Aspera
393
401
  crud_commands entity: 'data/shares',
394
402
  api: :@api_shares_admin,
395
403
  display_fields: SHARE_DISPLAY_FIELDS,
396
- body_component: Schema::Registry::SHARES,
404
+ body_component: API_SCHEMA,
397
405
  lookup: :lookup_share_id
398
406
  command :user_permissions,
399
407
  description: 'Manage user permissions on a share',
@@ -413,7 +421,7 @@ module Aspera
413
421
  name: entity_noun(perm_type),
414
422
  id_name: :"#{entity_type}_id",
415
423
  lookup: :"lookup_shares_#{entity_type}_all_id",
416
- body_component: Schema::Registry::SHARES,
424
+ body_component: API_SCHEMA,
417
425
  schema_entity: "data/shares/{share_id}/#{perm_type}"
418
426
  end
419
427
  end
@@ -428,10 +436,10 @@ module Aspera
428
436
  # --- setup ---
429
437
 
430
438
  # files - mount target: Node plugin on the Shares node API.
431
- # Api::Node (not plain Rest::Client) so that Node commands using its helpers work (e.g. spec, transport).
439
+ # Node::Api (not plain Rest::Client) so that Node commands using its helpers work (e.g. spec, transport).
432
440
  # @return [Node]
433
441
  def shares_node_plugin(**)
434
- Node.new(context: context, api: Api::Node.new(**basic_auth_params(NODE_API_PATH)))
442
+ Node::Commands.new(context: context, api: Node::Api.new(**basic_auth_params(NODE_API_PATH)))
435
443
  end
436
444
 
437
445
  # Build the admin REST API and store in ivar.
@@ -495,7 +503,7 @@ module Aspera
495
503
  else
496
504
  nagios.add_critical('system', health[:system].to_s)
497
505
  end
498
- Result::ObjectList.new(nagios.status_list)
506
+ Cli::Result::ObjectList.new(nagios.status_list)
499
507
  end
500
508
 
501
509
  private
@@ -587,10 +595,10 @@ module Aspera
587
595
  path = admin_entity_path(entity_type, :saml)
588
596
  bulk_result(kwargs.fetch(entity_type), command: :import) do |entity_parameters|
589
597
  entity_parameters = entity_parameters.transform_keys { |k| k.gsub(/\s+/, '_').downcase }
590
- Aspera.assert_type(entity_parameters, Hash)
591
- SAML_IMPORT_MANDATORY.each { |p| raise "missing mandatory field: #{p}" if entity_parameters[p].nil? }
598
+ Aspera.assert_type(entity_parameters, Hash, type: Cli::BadArgument) { 'SAML import entry' }
599
+ SAML_IMPORT_MANDATORY.each { |p| raise Cli::BadArgument, "SAML import entry: missing mandatory field: #{p}" if entity_parameters[p].nil? }
592
600
  entity_parameters.each_key do |p|
593
- Aspera.assert_values(p, SAML_IMPORT_ALLOWED) { 'SAML field' }
601
+ Aspera.assert_values(p, SAML_IMPORT_ALLOWED, type: Cli::BadArgument) { 'SAML field' }
594
602
  end
595
603
  @api_shares_admin.create("#{path}/import", entity_parameters)
596
604
  end
@@ -601,7 +609,7 @@ module Aspera
601
609
  entity_plural = entity_type.eql?(:user) ? 'users' : 'groups'
602
610
  define_action_method(%i[admin].push(entity_type, :search, :show)) do |**kwargs|
603
611
  urn = URI.encode_www_form_component(kwargs[:"#{entity_type}_urn"])
604
- Result::SingleObject.new(@api_shares_admin.read("#{entity_plural}/#{urn}"))
612
+ Cli::Result::SingleObject.new(@api_shares_admin.read("#{entity_plural}/#{urn}"))
605
613
  end
606
614
  next unless entity_type.eql?(:group)
607
615
  define_action_method(%i[admin group search members]) do |group_urn:, **|
@@ -614,7 +622,7 @@ module Aspera
614
622
  # directory_id is a URN — must be percent-encoded in the URL path segment.
615
623
  define_action_method(%i[admin directory show]) do |directory_id:, **|
616
624
  enc = URI.encode_www_form_component(directory_id)
617
- Result::SingleObject.new(@api_shares_admin.read("directories/#{enc}"))
625
+ Cli::Result::SingleObject.new(@api_shares_admin.read("directories/#{enc}"))
618
626
  end
619
627
 
620
628
  define_action_method(%i[admin directory users]) do |directory_id:, **|
@@ -629,13 +637,13 @@ module Aspera
629
637
 
630
638
  # admin > authenticate
631
639
  define_action_method(%i[admin authenticate]) do |credentials:, **|
632
- Result::SingleObject.new(@api_shares_admin.create('authenticate', credentials))
640
+ Cli::Result::SingleObject.new(@api_shares_admin.create('authenticate', credentials))
633
641
  end
634
642
 
635
643
  # share > event > create
636
644
  define_action_method(%i[share event create]) do |share_id:, event:, **|
637
645
  basic_auth_api(ADMIN_API_PATH).create("shares/#{share_id}/events", event)
638
- Result::Status.new('event created')
646
+ Cli::Result::Status.new('event created')
639
647
  end
640
648
  end
641
649
  end
@@ -0,0 +1,10 @@
1
+ name: shares
2
+ title: IBM Aspera Shares
3
+ depends:
4
+ - node
5
+ commands: true
6
+ schemas:
7
+ - key: shares
8
+ file: schemas/IBM_Aspera_Shares.yaml
9
+ source:
10
+ url: https://raw.githubusercontent.com/laurent-martin/aspera-api-examples/refs/heads/main/openapi/IBM_Aspera_Shares.yaml
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: IBM Corp.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ require_relative '../../oauth/client/web'
7
+ require_relative '../../oauth/client/factory'
8
+ require_relative '../../sealed_hash'
9
+ require_relative '../../cli/info'
10
+ require_relative '../../prompt'
11
+ require 'securerandom'
12
+
13
+ module Aspera
14
+ module Plugins
15
+ module Shares
16
+ # Authentication of a SAML user of Aspera Shares using a Web browser.
17
+ #
18
+ # Shares has no OAuth authorization endpoint: the OAuth tokens of the user (same as those of `<url>/auth/oauth2/token`) are given by the SAML login page
19
+ # (`<url>/auth/saml`), once the user is authenticated. The way depends on option `ui.web_auth`:
20
+ # - `port` (default): `RelayState` is the loopback URL, Shares redirects the browser to it with the tokens in the query. It is automatic.
21
+ # - `paste`: `RelayState` is `aspera://device-code?state=<state>`, Shares shows a code that the user pastes in the terminal.
22
+ # No local port is used, the browser can be on any system.
23
+ # The refresh token received (in the URL, or in the code) is immediately exchanged for a new token: the tokens that went through the browser are not valid any more.
24
+ class SharesWeb < OAuth::Web
25
+ # `RelayState` that tells Shares to show the code (`paste`)
26
+ DEVICE_CODE_RELAY_STATE = 'aspera://device-code?state='
27
+
28
+ # @param redirect_uri [String] Loopback URL that receives the tokens (`port`)
29
+ # @param path_authorize [String] Path to the SAML login page, from the base URL
30
+ # @param base_params [Hash] Parameters for base class: `base_url` is `<url>/auth`, `path_token` is `oauth2/token`
31
+ def initialize(redirect_uri:, path_authorize: 'saml', **base_params)
32
+ # Shares needs a path in the loopback URL, and the local server expects it
33
+ uri = URI.parse(redirect_uri)
34
+ uri.path = '/' if uri.path.empty?
35
+ super(redirect_uri: uri.to_s, path_authorize: path_authorize, path_token: 'oauth2/token', **base_params)
36
+ end
37
+
38
+ def create_token
39
+ # state is returned unchanged by Shares: it ties the answer to this login
40
+ random_state = SecureRandom.uuid
41
+ received_params =
42
+ case Environment.instance.web_auth
43
+ when :paste then receive_code(random_state)
44
+ when :port then receive_on_loopback(random_state)
45
+ else Aspera.error_unexpected_value(Environment.instance.web_auth) { 'ui.web_auth' }
46
+ end
47
+ Aspera.assert(random_state.eql?(received_params['state'])) { 'wrong received state' }
48
+ refresh_token = received_params['refresh_token'].to_s
49
+ Aspera.assert(!refresh_token.empty?) { 'No token received: does this Shares have the login patch for ascli?' }
50
+ Secret::Hider.instance.add_secret_values(refresh_token, received_params['access_token'].to_s)
51
+ create_token_base(grant_type: 'refresh_token', refresh_token: refresh_token)
52
+ end
53
+
54
+ private
55
+
56
+ # `port`: the browser is redirected to the loopback URL, which has the state in its query
57
+ # @return [Hash{String=>String}] Query received
58
+ def receive_on_loopback(state)
59
+ login_page_url = login_page(Rest.build_uri(@redirect_uri, state: state).to_s)
60
+ # the page shows where the user is logged in
61
+ login_receiver = WebAuth.receiver(@redirect_uri, [OAuth::Web.additional_info, URI.parse(api.base_url).host].compact.join(' - '))
62
+ Environment.instance.open_uri(login_page_url)
63
+ login_receiver.received_request
64
+ end
65
+
66
+ # `paste`: Shares shows a code, to paste in the terminal
67
+ # The prompt shows if the code is valid, and asks again if not.
68
+ # @return [Hash{String=>String}] Content of the code
69
+ def receive_code(state)
70
+ Environment.instance.open_uri(login_page("#{DEVICE_CODE_RELAY_STATE}#{state}"))
71
+ Log.log.warn { 'USER ACTION: Log in with the web browser, then copy the code displayed by Shares and paste it in the prompt below.' }
72
+ code = Aspera::Prompt.prompt_user_input('Code', sensitive: true, validate: ->(text) { unseal_code(text, state) })
73
+ unseal_code(code, state)
74
+ end
75
+
76
+ # The state is part of the key of the code: the code is not readable without it
77
+ # @param text [String] Pasted by the user
78
+ # @param state [String] State of this login
79
+ # @return [Hash{String=>String}] Content of the code
80
+ # @raise [ParameterError] if the text is not a valid code of this login (or it is expired)
81
+ def unseal_code(text, state)
82
+ Aspera.assert(SealedHash.sealed?(text), type: ParameterError) { 'Not a code: copy the code displayed by Shares after login' }
83
+ SealedHash.unseal(text, secret: state, base_key: Cli::Info::CMD_NAME)
84
+ end
85
+
86
+ # @param relay_state [String] Where Shares sends the result
87
+ # @return [String] URL of the SAML login page
88
+ def login_page(relay_state)
89
+ url = Rest.build_uri("#{api.base_url}/#{@path_authorize}", RelayState: relay_state)
90
+ Log.log.debug { "login_page_url=#{url}" }
91
+ url
92
+ end
93
+ end
94
+ OAuth::Factory.instance.register_token_creator(SharesWeb)
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,258 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: IBM Corp.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ require_relative '../../agent/base'
7
+ require_relative '../../bundle_registry'
8
+ require_relative '../../log'
9
+ require_relative '../../transfer/error'
10
+ require_relative '../../transfer/spec'
11
+ begin
12
+ require_relative 'api'
13
+ rescue LoadError => e
14
+ # The optional gem grpc is not a gem of the bundle: the commands `install`, `list` and `service` work without it
15
+ raise unless e.path.eql?('grpc')
16
+ raise Aspera::BundleRegistry::Unavailable, 'agent transferd requires gem grpc: gem install grpc'
17
+ end
18
+ require_relative 'client'
19
+ require_relative 'product'
20
+ require 'json'
21
+ require 'uri'
22
+
23
+ module Aspera
24
+ module Plugins
25
+ module Transferd
26
+ # Transfers with a Transfer Daemon (`transferd`): an external one, or one started here (`Product`).
27
+ # Calls to a running daemon: `Api`.
28
+ class Agent < Aspera::Agent::Base
29
+ # https://github.com/grpc/grpc/blob/master/doc/naming.md
30
+ # https://grpc.io/docs/guides/custom-name-resolution/
31
+ PORT_SEP = ':'
32
+ # port zero means select a random available high port
33
+ AUTO_LOCAL_TCP_PORT = "#{PORT_SEP}0".freeze
34
+ # Seconds to wait for a daemon started here to answer
35
+ START_TIMEOUT_SEC = 10
36
+ # Seconds between two connection attempts to a daemon started here
37
+ START_RETRY_SEC = 0.2
38
+
39
+ # Daemon addresses that run on the local host (loopback or wildcard bind): a daemon there is started or attached to locally
40
+ LOCAL_DAEMON_HOSTS = ['127.0.0.1', 'localhost', '::1', '0.0.0.0', '::'].freeze
41
+
42
+ private_constant :PORT_SEP, :AUTO_LOCAL_TCP_PORT, :LOCAL_DAEMON_HOSTS, :START_TIMEOUT_SEC, :START_RETRY_SEC
43
+
44
+ class << self
45
+ # A daemon started here, or attached to on the local host, runs on the local host: refused at level `high` (see `Cli::Security`).
46
+ # A daemon on a remote host is provided and controlled by the user: allowed at any level.
47
+ # @param options [Hash] agent parameters (`url` is the daemon endpoint, default: a local daemon)
48
+ # @return [Symbol, nil] `:medium` for a local daemon, `nil` (any level) for a remote one
49
+ def required_security_level(options)
50
+ remote_daemon?(options[:url]) ? nil : :medium
51
+ end
52
+
53
+ # @param url [String, nil] daemon endpoint `<address>:<port>` (or `:<port>`, or absent: a local daemon)
54
+ # @return [Boolean] `true` if the daemon is on a remote host
55
+ def remote_daemon?(url)
56
+ return false if url.nil?
57
+ host = url.to_s.sub(%r{\A\w+://}, '')
58
+ host = host[0...host.rindex(':')] if host.include?(':')
59
+ !host.empty? && !LOCAL_DAEMON_HOSTS.include?(host.downcase)
60
+ end
61
+
62
+ # @param stub [Transferd::Api::TransferService::Stub] gRPC client of a daemon
63
+ # @return [Client] Calls to this daemon with plain Ruby arguments
64
+ def wrap_client(stub)
65
+ Client.new(stub)
66
+ end
67
+
68
+ # @param name [Symbol] see `Client.empty_message`
69
+ # @return [Google::Protobuf::AbstractMessage] empty gRPC message
70
+ def empty_message(name)
71
+ Client.empty_message(name)
72
+ end
73
+
74
+ # Re-query a previously started transfer: see `Api.transfer_status`
75
+ # @param transfer_id [String] Identifier of transfer, given by the daemon (`transfer_id`)
76
+ # @param agent_params [Hash] `url`: endpoint of the daemon; optional `timeout`: seconds, `api_key`, `ca_file`
77
+ # @return [Hash] Normalized status
78
+ def transfer_status(transfer_id, agent_params)
79
+ Api.transfer_status(transfer_id, agent_params)
80
+ end
81
+
82
+ # Stop a transfer: see `Api.transfer_cancel`
83
+ # @param transfer_id [String] Identifier of transfer, given by the daemon
84
+ # @param agent_params [Hash] `url`: endpoint of the daemon; optional `timeout`: seconds, `api_key`, `ca_file`
85
+ # @return [Boolean] `true`: stopped
86
+ # @raise [Aspera::Transfer::Error] The daemon did not stop it: unknown or terminated transfer
87
+ def transfer_cancel(transfer_id, agent_params)
88
+ Api.transfer_cancel(transfer_id, agent_params)
89
+ end
90
+ end
91
+
92
+ # Connect to the daemon of `url`, and start it if it does not answer (unless `start` is `false`)
93
+ # @param url [String] URL of the transfer manager daemon, e.g. `127.0.0.1:55002`, or only its port (address `127.0.0.1`)
94
+ # @param start [Boolean] If `false`, expect that an external daemon is already running
95
+ # @param stop [Boolean] If `false`, do not shutdown daemon on exit
96
+ # @param api_key [String, nil] API key of the daemon: of an external daemon with `authentication` enabled, or of the daemon started here (else a random one)
97
+ # @param ca_file [String, nil] Certificate authority (PEM file) of an external daemon with `tls` enabled
98
+ # @param base [Hash] Base class options
99
+ # @raise [Aspera::Transfer::Error] The daemon started here does not answer within `START_TIMEOUT_SEC`
100
+ def initialize(
101
+ url: AUTO_LOCAL_TCP_PORT,
102
+ start: true,
103
+ stop: true,
104
+ api_key: nil,
105
+ ca_file: nil,
106
+ **base
107
+ )
108
+ super(**base)
109
+ @transfer_id = nil
110
+ @stop = stop
111
+ is_local_auto_port = url.eql?(AUTO_LOCAL_TCP_PORT)
112
+ Aspera.assert(!(is_local_auto_port && (!@stop || !start)), type: ParameterError) { 'Cannot set options `stop` or `start` to false with port zero' }
113
+ # daemon started here, kept for optional shutdown
114
+ @daemon = nil
115
+ # no address: local address
116
+ @daemon_endpoint = Api.endpoint(url)
117
+ Log.dump(:daemon_endpoint, @daemon_endpoint)
118
+ begin
119
+ connect(api_key, ca_file)
120
+ Log.log.warn('Attached to existing daemon') if start && @stop
121
+ # `shutdown` is registered with `at_exit` only when the daemon is started here:
122
+ # a long-running process (e.g. Orchestrator) that attaches to an external daemon for each transfer would accumulate them
123
+ rescue GRPC::Unavailable => e
124
+ # if transferd is external: do not start it, or other error
125
+ raise if !start || !e.message.include?('failed to connect')
126
+ start_daemon(api_key, ca_file, auto_port: is_local_auto_port)
127
+ end
128
+ end
129
+
130
+ # Actual endpoint the daemon is listening on (resolved after connect, e.g. when port 0 was used)
131
+ attr_reader :daemon_endpoint
132
+ # gRPC client of the daemon
133
+ attr_reader :transfer_client
134
+
135
+ # @return [Client] Calls to the daemon with plain Ruby arguments
136
+ def client
137
+ @client ||= Client.new(@transfer_client)
138
+ end
139
+
140
+ # @return [Hash] `url`: actual endpoint of the daemon, for `transfer_status` and `transfer_cancel` (`transfer_id` is given by the daemon)
141
+ def async_params
142
+ {'url' => @daemon_endpoint}
143
+ end
144
+
145
+ # :reek:UnusedParameters token_regenerator
146
+ def start_transfer(transfer_spec, token_regenerator: nil)
147
+ Aspera::Transfer::Spec.fix_transferd_resume_policy(transfer_spec)
148
+ # create a transfer request
149
+ transfer_request = ::Transferd::Api::TransferRequest.new(
150
+ transferType: ::Transferd::Api::TransferType::FILE_REGULAR, # transfer type (file/stream)
151
+ config: ::Transferd::Api::TransferConfig.new, # transfer configuration
152
+ transferSpec: transfer_spec.to_json
153
+ ) # transfer definition
154
+ # send start transfer request to the transfer manager daemon
155
+ start_response = @transfer_client.start_transfer(transfer_request)
156
+ Aspera.assert(!start_response.status.eql?(:FAILED), type: Aspera::Transfer::Error) { start_response.error.description }
157
+ Log.log.debug { "start transfer response #{start_response}" }
158
+ @transfer_id = start_response.transferId
159
+ Log.log.debug { "transfer started with id #{@transfer_id}" }
160
+ end
161
+
162
+ def wait_for_transfers_completion
163
+ # set to true when we know the total size of the transfer
164
+ session_started = false
165
+ bytes_expected = nil
166
+ # monitor transfer status
167
+ @transfer_client.monitor_transfers(::Transferd::Api::RegistrationRequest.new(transferId: [@transfer_id])) do |response|
168
+ Log.dump(:response, response.to_h)
169
+ # Log.log.debug{"#{response.sessionInfo.preTransferBytes} #{response.transferInfo.bytesTransferred}"}
170
+ case response.status
171
+ when :RUNNING
172
+ if !session_started
173
+ notify_progress(:session_start, session_id: @transfer_id)
174
+ session_started = true
175
+ end
176
+ if bytes_expected.nil? &&
177
+ !response.sessionInfo.preTransferBytes.eql?(0)
178
+ bytes_expected = response.sessionInfo.preTransferBytes
179
+ notify_progress(:session_size, session_id: @transfer_id, info: bytes_expected)
180
+ end
181
+ notify_progress(:transfer, session_id: @transfer_id, info: response.transferInfo.bytesTransferred)
182
+ when :COMPLETED
183
+ notify_progress(:transfer, session_id: @transfer_id, info: bytes_expected) if bytes_expected
184
+ notify_progress(:session_end, session_id: @transfer_id)
185
+ break
186
+ when :FAILED, :CANCELED
187
+ notify_progress(:session_end, session_id: @transfer_id)
188
+ raise Aspera::Transfer::Error, JSON.parse(response.message)['Description']
189
+ when :QUEUED, :UNKNOWN_STATUS, :PAUSED, :ORPHANED
190
+ notify_progress(:sessions_init, info: response.status.to_s.downcase)
191
+ else
192
+ Log.log.error { "unknown status#{response.status}" }
193
+ end
194
+ end
195
+ # TODO: return status
196
+ return []
197
+ end
198
+
199
+ def shutdown
200
+ @daemon&.stop if @stop
201
+ end
202
+
203
+ private
204
+
205
+ # Create the client of the daemon of `@daemon_endpoint`, and get its information: the actual connection
206
+ # @param api_key [String, nil] API key of the daemon
207
+ # @param ca_file [String, nil] Certificate authority (PEM file) of the daemon
208
+ # @param deadline [Time, nil] Time limit of the call, `nil`: none
209
+ # @raise [GRPC::BadStatus] The daemon does not answer
210
+ def connect(api_key, ca_file, deadline: nil)
211
+ # Create stub: API key of the daemon (given, or the one of the daemon started here)
212
+ @transfer_client = Api.create_client(@daemon_endpoint, api_key: api_key, ca_file: ca_file)
213
+ get_info_response = @transfer_client.get_info(::Transferd::Api::InstanceInfoRequest.new, deadline: deadline)
214
+ Log.log.debug { "Daemon info: #{get_info_response}" }
215
+ end
216
+
217
+ # Start a daemon on `@daemon_endpoint`, then connect to it: it may need some time before it listens (e.g. first start of its executable)
218
+ # @param api_key [String, nil] API key given by the user (see `Product.daemon_api_key`)
219
+ # @param ca_file [String, nil] Certificate authority (PEM file) of the daemon
220
+ # @param auto_port [Boolean] `true` if started with port zero: the port is read from its port file or its log (see `Product#listen_port`)
221
+ # @raise [Aspera::Transfer::Error] The daemon does not answer within `START_TIMEOUT_SEC`
222
+ def start_daemon(api_key, ca_file, auto_port:)
223
+ # Expected for the first execution when the daemon is left running
224
+ Log.log.public_send(@stop ? :warn : :info, 'no daemon present, starting daemon...')
225
+ # transferd only supports local ip and port
226
+ daemon_uri = URI.parse("ipv4://#{@daemon_endpoint}")
227
+ Aspera.assert(!daemon_uri.host.to_s.empty? && !daemon_uri.port.nil?, type: ParameterError) { "Invalid address of daemon: #{@daemon_endpoint}, expecting <ADDRESS>:<PORT> or :<PORT>" }
228
+ @daemon = Product.new(address: daemon_uri.host, port: daemon_uri.port, api_key: api_key, stop: @stop)
229
+ at_exit { shutdown }
230
+ deadline = Time.now + START_TIMEOUT_SEC
231
+ # Only a daemon that does not listen yet is waited for: other errors (e.g. several port files) fail at once
232
+ loop do
233
+ # Port written once it listens, in its port file or its log (if auto high port was requested)
234
+ port = @daemon.listen_port if auto_port
235
+ if auto_port && port.nil?
236
+ reason = 'port not found in its port file or log'
237
+ else
238
+ @daemon_endpoint = Api.endpoint("#{PORT_SEP}#{port}") if auto_port
239
+ begin
240
+ # API key of the daemon started here
241
+ connect(@daemon.api_key, ca_file, deadline: deadline)
242
+ return
243
+ rescue GRPC::Unavailable, GRPC::DeadlineExceeded => e
244
+ reason = "#{e.class.name.split('::').last}: #{e.details}"
245
+ end
246
+ end
247
+ Aspera.assert(Time.now < deadline, type: Aspera::Transfer::Error) do
248
+ "Transfer daemon started with PID #{@daemon.pid} does not answer on #{@daemon_endpoint} after #{START_TIMEOUT_SEC} seconds (#{reason}). " \
249
+ "Check files: #{@daemon.log_files.join(' and ')}"
250
+ end
251
+ Log.log.debug { "Daemon does not answer yet: #{reason}" }
252
+ sleep(START_RETRY_SEC)
253
+ end
254
+ end
255
+ end
256
+ end
257
+ end
258
+ end