asperalm 0.7 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eebbf027278210f5440f0690eff3736ccc3fce906c8357f5090890313d630721
4
- data.tar.gz: 5d6b168fc415ac5a3c865f67233b49fe0adce433bc131bf5f624819fee218786
3
+ metadata.gz: 99e591610a66186e966bdea1c05e26e078fcdaef32fa3a6859a36bdf2f8c7907
4
+ data.tar.gz: 54f69bc925ff702987e5a75128a0628a58fe4472f8888a8c3b6f8489eec22233
5
5
  SHA512:
6
- metadata.gz: 630813906c8d9e4fa9e36aed683d365791b8d9a27c2cb6803efdda773facd88859622ac837ad1a811262b86f47f210c035c58d05171116528dc9b56c9fbaa891
7
- data.tar.gz: 385ccbf995af7f26c1e4eccac56f0f7e2201b59542310767c6d8566365595fdbea3352e291f678b3b36626aff281718aa85f50d63d8ceb06b9e8f3ffc4eb1ebb
6
+ metadata.gz: eb068c890240586a2f3b30e4748af52a6dae17095a5ba52300ba6ed2e7e6c3a54795f6fdd761d61484bbda5fe9cd83b6741d9a75a51b8d95f9d75b699e765084
7
+ data.tar.gz: 02a034132b73fb82960777158aa92a3230a0f492f64c9065a6aa7430cc696a8bbc6b82953c42c7226c3669223133458771d34918a8eb250163c22f6a3ec05114
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Asperalm - Laurent's Aspera Command Line Interface and Ruby Library
2
2
 
3
- Version : 0.7
3
+ Version : 0.7.1
4
4
 
5
5
 
6
6
  _Laurent/2016-2018_
@@ -34,7 +34,7 @@ Once the gem is installed, the `aslmcli` shall be accessible:
34
34
 
35
35
  ```bash
36
36
  $ aslmcli --version
37
- 0.7
37
+ 0.7.1
38
38
 
39
39
  ```
40
40
 
@@ -784,6 +784,10 @@ aslmcli aspera admin ats cluster list
784
784
  aslmcli aspera admin ats cluster show --cloud=aws --region=eu-west-1
785
785
  aslmcli aspera admin ats cluster show --id=1f412ae7-869a-445c-9c05-02ad16813be2
786
786
  aslmcli aspera admin events
787
+ aslmcli aspera admin resource node --name=eudemo --secret=my_secret_here do access_key create --value=@json:'{"id":"testsub1","storage":{"path":"/folder1"}}'
788
+ aslmcli aspera admin resource node --name=eudemo --secret=my_secret_here do access_key delete --eid=testsub1
789
+ aslmcli aspera admin resource node --name=eudemo --secret=my_secret_here do delete /folder1
790
+ aslmcli aspera admin resource node --name=eudemo --secret=my_secret_here do mkdir /folder1
787
791
  aslmcli aspera admin resource node --name=eudemo do browse / --secret=my_secret_here
788
792
  aslmcli aspera admin resource workspace list
789
793
  aslmcli aspera admin set_client_key ERuzXGuPA @file:$(APIKEY)
@@ -884,7 +888,7 @@ aslmcli shares2 userinfo
884
888
  ```bash
885
889
  $ aslmcli -h
886
890
  NAME
887
- aslmcli -- a command line tool for Aspera Applications (v0.7)
891
+ aslmcli -- a command line tool for Aspera Applications (v0.7.1)
888
892
 
889
893
  SYNOPSIS
890
894
  aslmcli COMMANDS [OPTIONS] [ARGS]
@@ -918,7 +922,7 @@ OPTIONS: global
918
922
  -N, --no-default do not load default configuration
919
923
  -v, --version display version
920
924
  --ui=ENUM method to start browser: text, graphical
921
- --log-level=ENUM Log level: fatal, unknown, debug, info, warn, error
925
+ --log-level=ENUM Log level: warn, error, fatal, unknown, debug, info
922
926
  --logger=ENUM log method: stderr, stdout, syslog
923
927
  --format=ENUM output format: table, ruby, json, jsonpp, yaml, csv
924
928
  --transfer=ENUM type of transfer: direct, connect, node
@@ -934,6 +938,7 @@ OPTIONS: global
934
938
  --use-product=VALUE which local product to use for ascp
935
939
  --insecure=ENUM do not validate HTTPS certificate: yes, no
936
940
  --flat-hash=ENUM display hash values as additional keys: yes, no
941
+ --override=ENUM override existing value: yes, no
937
942
 
938
943
  COMMAND: shares
939
944
  SUBCOMMANDS: repository, admin
@@ -948,147 +953,8 @@ OPTIONS:
948
953
  --url=VALUE URL of application, e.g. https://org.asperafiles.com
949
954
  --username=VALUE username to log in
950
955
  --password=VALUE user's password
951
- --value=VALUE extended value for create, update, list filter
952
- --validator=VALUE identifier of validator (optional for central)
953
- --id=VALUE entity identifier for update, show, and modify
954
-
955
- COMMAND: orchestrator
956
- SUBCOMMANDS: info, workflow, plugins, processes
957
- OPTIONS:
958
- --url=VALUE URL of application, e.g. https://org.asperafiles.com
959
- --username=VALUE username to log in
960
- --password=VALUE user's password
961
- --params=VALUE parameters hash table, use @json:{"param":"value"}
962
- --result=VALUE specify result value as: 'work step:parameter'
963
- --id=VALUE workflow identifier
964
- --synchronous=ENUM work step:parameter expected as result: yes, no
965
-
966
- COMMAND: aspera
967
- SUBCOMMANDS: packages, files, faspexgw, admin, user
968
- OPTIONS:
969
- --ats-id=VALUE ATS key identifier (ats_xxx)
970
- --params=VALUE Parameters access key creation (@json:)
971
- --cloud=VALUE Cloud provider
972
- --region=VALUE Cloud region
973
- --download-mode=ENUM download mode: fasp, node_http
974
- --auth=ENUM type of Oauth authentication: basic, web, jwt, url_token
975
- --bulk=ENUM bulk operation: yes, no
976
- --url=VALUE URL of application, e.g. http://org.asperafiles.com
977
- --username=VALUE username to log in
978
- --password=VALUE user's password
979
- --client-id=VALUE API client identifier in application
980
- --client-secret=VALUE API client passcode
981
- --redirect-uri=VALUE API client redirect URI
982
- --private-key=VALUE RSA private key PEM value for JWT (prefix file path with @val:@file:)
983
- --workspace=VALUE name of workspace
984
- --recipient=VALUE package recipient
985
- --title=VALUE package title
986
- --note=VALUE package note
987
- --secret=VALUE access key secret for node
988
- --query=VALUE list filter (extended value: encode_www_form)
989
- --id=VALUE resource identifier
990
- --name=VALUE resource name
991
- --link=VALUE link to shared resource
992
-
993
- COMMAND: xnode
994
- SUBCOMMANDS: postprocess, cleanup, forward
995
- OPTIONS:
996
- --url=VALUE URL of application, e.g. https://org.asperafiles.com
997
- --username=VALUE username to log in
998
- --password=VALUE user's password
999
- --filter-transfer=VALUE Ruby expression for filter at transfer level (cleanup)
1000
- --filter-file=VALUE Ruby expression for filter at file level (cleanup)
1001
- --persistency=VALUE persistency file (cleanup,forward)
1002
-
1003
- COMMAND: ats
1004
- SUBCOMMANDS: cluster, access_key
1005
- OPTIONS:
1006
- --id=VALUE Access key identifier, or server id, or api key id
1007
- --secret=VALUE Access key secret
1008
- --ats-id=VALUE ATS key identifier (ats_xxx)
1009
- --params=VALUE Parameters access key creation (@json:)
1010
- --cloud=VALUE Cloud provider
1011
- --region=VALUE Cloud region
1012
-
1013
- COMMAND: client
1014
- SUBCOMMANDS: current, available, connect
1015
- OPTIONS:
1016
-
1017
- COMMAND: faspex
1018
- SUBCOMMANDS: package, dropbox, recv_publink, source, me
1019
- OPTIONS:
1020
- --url=VALUE URL of application, e.g. https://org.asperafiles.com
1021
- --username=VALUE username to log in
1022
- --password=VALUE user's password
1023
- --recipient=VALUE package recipient
1024
- --title=VALUE package title
1025
- --note=VALUE package note
1026
- --metadata=VALUE package metadata hash value (use @json:)
1027
- --source-name=VALUE create package from remote source (by name)
1028
- --box=ENUM package box: inbox, sent, archive
1029
-
1030
- COMMAND: shares2
1031
- SUBCOMMANDS: repository, organization, project, team, share, appinfo, userinfo
1032
- OPTIONS:
1033
- --url=VALUE URL of application, e.g. https://org.asperafiles.com
1034
- --username=VALUE username to log in
1035
- --password=VALUE user's password
1036
- --organization=VALUE organization
1037
- --project=VALUE project
1038
- --share=VALUE share
1039
-
1040
- COMMAND: preview
1041
- SUBCOMMANDS: scan, events, folder, check, test
1042
- OPTIONS:
1043
- --url=VALUE URL of application, e.g. https://org.asperafiles.com
1044
- --username=VALUE username to log in
1045
- --password=VALUE user's password
1046
- --file-access=ENUM how to read and write files in repository: local, remote
1047
- --skip-types=VALUE skip types in comma separated list
1048
- --overwrite=ENUM when to generate preview file: always, never, mtime
1049
- --previews-folder=VALUE preview folder in files
1050
- --iteration-file=VALUE path to iteration memory file
1051
- --folder-reset-cache=ENUM reset folder cache: no, header, read
1052
- --temp-folder=VALUE path to temp folder
1053
- --skip-folders=VALUE list of folder to skip
1054
- --video=ENUM method to generate video: reencode, clips, preview
1055
- --vid-offset-seconds=VALUE generation parameter
1056
- --vid-size=VALUE generation parameter
1057
- --vid-framecount=VALUE generation parameter
1058
- --vid-blendframes=VALUE generation parameter
1059
- --vid-framepause=VALUE generation parameter
1060
- --vid-fps=VALUE generation parameter
1061
- --vid-mp4-size-reencode=VALUE
1062
- generation parameter
1063
- --clips-offset-seconds=VALUE generation parameter
1064
- --clips-size=VALUE generation parameter
1065
- --clips-length=VALUE generation parameter
1066
- --clips-count=VALUE generation parameter
1067
- --thumb-mp4-size=VALUE generation parameter
1068
- --thumb-img-size=VALUE generation parameter
1069
- --thumb-offset-fraction=VALUE
1070
- generation parameter
1071
- --validate-mime=ENUM use magic number validation: yes, no
1072
- --check-extension=ENUM check extra file extensions: yes, no
1073
-
1074
- COMMAND: server
1075
- SUBCOMMANDS: nodeadmin, userdata, configurator, download, upload, browse, delete, rename, ls, rm, mv, du, info, mkdir, cp, df, md5sum
1076
- OPTIONS:
1077
- --url=VALUE URL of application, e.g. https://org.asperafiles.com
1078
- --username=VALUE username to log in
1079
- --password=VALUE user's password
1080
- --ssh-keys=VALUE PATH_ARRAY is @json:'["path1","path2"]'
1081
-
1082
- COMMAND: console
1083
- SUBCOMMANDS: transfer
1084
- OPTIONS:
1085
- --url=VALUE URL of application, e.g. https://org.asperafiles.com
1086
- --username=VALUE username to log in
1087
- --password=VALUE user's password
1088
- --filter-from=DATE only after date
1089
- --filter-to=DATE only before date
1090
-
1091
- Documentation : http://www.rubydoc.info/gems/asperalm
956
+ ERROR: Other: INTERNAL ERROR: option id already declared. only accessor can be redeclared and ignored
957
+ Use '--log-level=debug' to get more details.
1092
958
 
1093
959
 
1094
960
  ```
@@ -1238,7 +1104,7 @@ JWT needs to be authorized in Aspera on Cloud. This can be done in two manners:
1238
1104
  <img src="docs/AuthJWT.png" alt="Files-admin-organization-apiclient-create"/>
1239
1105
 
1240
1106
  * Open a web browser, log to your instance: https://laurent.ibmaspera.com/
1241
- * Go to Admin View-Organization-API Clients
1107
+ * Go to Apps-Admin-Organization-Integrations
1242
1108
  * Click on the previously created application
1243
1109
  * select tab : "Authentication Options"
1244
1110
  * Modify options:
@@ -1382,6 +1248,14 @@ $ aslmcli aspera user workspaces
1382
1248
  :......:............................:
1383
1249
  ```
1384
1250
 
1251
+ * Create a sub access key in a "node"
1252
+
1253
+ Creation of a sub-access key is like creation of access key with the following difference: authentication to node API is made with accesskey (master access key) and only the path parameter is provided: it is relative to the storage root of the master key. (id and secret are optional)
1254
+
1255
+ ```
1256
+ $ aslmcli aspera admin resource node --name=_node_name_ --secret=_secret_ do access_key create --value=@json:'{"storage":{"path":"/folder1"}}'
1257
+ ```
1258
+
1385
1259
  ## Aspera Node (Transfer Server)
1386
1260
 
1387
1261
  ### Simple Operations
@@ -1 +1 @@
1
- 0.7
1
+ 0.7.1
@@ -9,6 +9,7 @@ require 'asperalm/fasp/listener_progress'
9
9
  require 'asperalm/open_application'
10
10
  require 'asperalm/log'
11
11
  require 'asperalm/oauth'
12
+ require 'asperalm/files_api'
12
13
  require 'text-table'
13
14
  require 'fileutils'
14
15
  require 'singleton'
@@ -92,6 +93,8 @@ module Asperalm
92
93
  # =============================================================
93
94
  # Parameter handlers
94
95
  #
96
+ attr_accessor :option_override
97
+
95
98
  def option_insecure; Rest.insecure ; end
96
99
 
97
100
  def option_insecure=(value); Rest.insecure = value; end
@@ -220,6 +223,7 @@ module Asperalm
220
223
  # local options
221
224
  def create_opt_mgr
222
225
  @opt_mgr=Manager.new(@@PROGRAM_NAME)
226
+ Plugin.set_refs(@opt_mgr,self)
223
227
  @opt_mgr.parser.banner = "NAME\n\t#{@@PROGRAM_NAME} -- a command line tool for Aspera Applications (v#{self.class.gem_version})\n\n"
224
228
  @opt_mgr.parser.separator "SYNOPSIS"
225
229
  @opt_mgr.parser.separator "\t#{@@PROGRAM_NAME} COMMANDS [OPTIONS] [ARGS]"
@@ -259,6 +263,7 @@ module Asperalm
259
263
  # handler must be set before declaration
260
264
  @opt_mgr.set_obj_attr(:log_level,Log.instance,:level)
261
265
  @opt_mgr.set_obj_attr(:insecure,self,:option_insecure,:no)
266
+ @opt_mgr.set_obj_attr(:override,self,:option_override,:no)
262
267
  @opt_mgr.set_obj_attr(:flat_hash,self,:option_flat_hash)
263
268
  @opt_mgr.set_obj_attr(:ts,self,:option_transfer_spec)
264
269
  @opt_mgr.set_obj_attr(:to_folder,self,:option_to_folder)
@@ -284,6 +289,7 @@ module Asperalm
284
289
  @opt_mgr.add_opt_simple(:use_product,"which local product to use for ascp")
285
290
  @opt_mgr.add_opt_boolean(:insecure,"do not validate HTTPS certificate")
286
291
  @opt_mgr.add_opt_boolean(:flat_hash,"display hash values as additional keys")
292
+ @opt_mgr.add_opt_boolean(:override,"override existing value")
287
293
 
288
294
  @opt_mgr.set_option(:ui,OpenApplication.default_gui_mode)
289
295
  @opt_mgr.set_option(:fields,FIELDS_DEFAULT)
@@ -296,9 +302,7 @@ module Asperalm
296
302
  def get_plugin_instance(plugin_name_sym)
297
303
  Log.log.debug("get_plugin_instance -> #{plugin_name_sym}")
298
304
  require @plugins[plugin_name_sym][:require_stanza]
299
- command_plugin=Object::const_get(@@PLUGINS_MODULE+'::'+plugin_name_sym.to_s.capitalize).new
300
- command_plugin.optmgr=@opt_mgr
301
- command_plugin.main=self
305
+ command_plugin=Object::const_get(@@PLUGINS_MODULE+'::'+plugin_name_sym.to_s.capitalize).new()
302
306
  # TODO: check that ancestor is Plugin?
303
307
  @opt_mgr.parser.separator "COMMAND: #{plugin_name_sym}"
304
308
  @opt_mgr.parser.separator "SUBCOMMANDS: #{command_plugin.action_list.map{ |p| p.to_s}.join(', ')}"
@@ -560,12 +564,19 @@ module Asperalm
560
564
 
561
565
  protected
562
566
 
563
- DEFAULT_PRESET='aspera_default'
567
+ def generate_new_key(key_filepath)
568
+ require 'net/ssh'
569
+ priv_key = OpenSSL::PKey::RSA.new(2048)
570
+ File.write(key_filepath,priv_key.to_s)
571
+ File.write(key_filepath+".pub",priv_key.public_key.to_s)
572
+ nil
573
+ end
574
+
564
575
  DEFAULT_REDIRECT='http://localhost:12345'
565
576
 
566
577
  # "config" plugin
567
578
  def execute_action
568
- action=@opt_mgr.get_next_argument('action',[:genkey,:plugins,:flush_tokens,:list,:overview,:open,:echo,:id,:documentation])
579
+ action=@opt_mgr.get_next_argument('action',[:genkey,:plugins,:flush_tokens,:list,:overview,:open,:echo,:id,:documentation,:quickstart])
569
580
  case action
570
581
  when :id
571
582
  config_name=@opt_mgr.get_next_argument('config name')
@@ -625,10 +636,7 @@ module Asperalm
625
636
  return Main.result_none
626
637
  when :genkey # generate new rsa key
627
638
  key_filepath=@opt_mgr.get_next_argument('private key file path')
628
- require 'net/ssh'
629
- priv_key = OpenSSL::PKey::RSA.new(2048)
630
- File.write(key_filepath,priv_key.to_s)
631
- File.write(key_filepath+".pub",priv_key.public_key.to_s)
639
+ generate_new_key(key_filepath)
632
640
  return Main.result_status('generated key: '+key_filepath)
633
641
  when :echo # display the content of a value given on command line
634
642
  result={:type=>:other_struct, :data=>@opt_mgr.get_next_argument("value")}
@@ -644,20 +652,54 @@ module Asperalm
644
652
  return {:data => @available_presets.keys, :type => :value_list, :name => 'name'}
645
653
  when :overview
646
654
  return {:type=>:hash_array,:data=>self.class.flatten_all_config(@available_presets)}
647
- when :aspera_setup # TODO
648
- @available_presets[@@CONFIG_FILE_KEY_DEFAULT]||=Hash.new
649
- raise CliError,"a default configuration already exists" if @available_presets[@@CONFIG_FILE_KEY_DEFAULT].has_key?(ASPERA_PLUGIN_S)
650
- raise CliError,"preset already exists: #{DEFAULT_PRESET}" if @available_presets.has_key?(DEFAULT_PRESET)
651
- @available_presets[@@CONFIG_FILE_KEY_DEFAULT][ASPERA_PLUGIN_S]=DEFAULT_PRESET
652
- @opt_mgr.set_option(:interactive,:yes)
653
- @opt_mgr.add_opt_simple(:url,"URL of application, e.g. http://org.asperafiles.com")
655
+ when :quickstart # TODO
656
+ # only one value, so no test, no switch for the time being
657
+ plugin_name=@opt_mgr.get_next_argument('plugin name',[:aspera])
658
+ require 'asperalm/cli/plugins/aspera'
659
+ files_plugin=Plugins::Aspera.new
660
+ files_plugin.declare_options
654
661
  @opt_mgr.parse_options!
655
- @available_presets[DEFAULT_PRESET]={
656
- :url.to_s=>@opt_mgr.get_option(:url,:mandatory),
657
- :redirect_uri.to_s=>DEFAULT_REDIRECT,
658
- :client_id.to_s=>@opt_mgr.get_option(:client_id,:mandatory),
662
+ @opt_mgr.set_option(:auth,:web)
663
+ #@opt_mgr.set_option(:client_id,FilesApi.random.first)
664
+ #@opt_mgr.set_option(:client_secret,FilesApi.random.last)
665
+ #@opt_mgr.set_option(:redirect_uri,'https://asperafiles.com/token')
666
+ @opt_mgr.set_option(:redirect_uri,DEFAULT_REDIRECT)
667
+ instance_url=@opt_mgr.get_option(:url,:mandatory)
668
+ organization,instance_domain=FilesApi.parse_url(instance_url)
669
+ aspera_preset_name='aoc_'+organization
670
+ @available_presets[@@CONFIG_FILE_KEY_DEFAULT]||=Hash.new
671
+ raise CliError,"a default configuration already exists (use --override=yes)" if @available_presets[@@CONFIG_FILE_KEY_DEFAULT].has_key?(ASPERA_PLUGIN_S) and !option_override
672
+ raise CliError,"preset already exists: #{aspera_preset_name} (use --override=yes)" if @available_presets.has_key?(aspera_preset_name) and !option_override
673
+ files_plugin.init_apis
674
+ myself=files_plugin.api_files_user.read('self')[:data]
675
+ if !myself['public_key'].empty?
676
+ Log.log.warn("public key is already set, overriding")
677
+ end
678
+ key_filepath=File.join(@config_folder,'aspera_on_cloud_key')
679
+ if File.exist?(key_filepath)
680
+ puts "key file already exists: #{key_filepath}"
681
+ else
682
+ puts "generating: #{key_filepath}"
683
+ generate_new_key(key_filepath)
684
+ end
685
+ puts "updating profile with new key"
686
+ files_plugin.api_files_user.update("users/#{myself['id']}",{'public_key'=>File.read(key_filepath+'.pub')})
687
+ puts "creating new config preset: #{aspera_preset_name}"
688
+ @available_presets[aspera_preset_name]={
689
+ :url.to_s =>@opt_mgr.get_option(:url),
690
+ :redirect_uri.to_s =>@opt_mgr.get_option(:redirect_uri),
691
+ :client_id.to_s =>@opt_mgr.get_option(:client_id),
692
+ :client_secret.to_s =>@opt_mgr.get_option(:client_secret),
693
+ :auth.to_s =>:jwt.to_s,
694
+ :private_key.to_s =>'@file:'+key_filepath,
695
+ :username.to_s =>myself['email'],
659
696
  }
660
- raise "todo"
697
+ puts "setting config preset as default for #{ASPERA_PLUGIN_S}"
698
+ @available_presets[@@CONFIG_FILE_KEY_DEFAULT][ASPERA_PLUGIN_S]=aspera_preset_name
699
+ puts "saving config file"
700
+ save_presets_to_config_file
701
+ return Main.result_status("Done. You can test with:\naslmcli aspera user info show")
702
+ # TODO: update documentation, enable JWT for the client_id
661
703
  end
662
704
  end
663
705
 
@@ -2,6 +2,11 @@ module Asperalm
2
2
  module Cli
3
3
  # base class for plugins modules
4
4
  class Plugin
5
+ def self.set_refs(optmgr,main)
6
+ @@optmgr=optmgr
7
+ @@main=main
8
+ end
9
+
5
10
  def self.result_none
6
11
  return {:type => :empty, :data => :nil }
7
12
  end
@@ -13,17 +18,16 @@ module Asperalm
13
18
  def self.result_success
14
19
  return result_status('complete')
15
20
  end
16
-
17
21
  GLOBAL_OPS=[:create,:list]
18
22
  INSTANCE_OPS=[:modify,:delete,:show]
19
23
  ALL_OPS=[GLOBAL_OPS,INSTANCE_OPS].flatten
20
24
 
21
25
  # implement generic rest operations on given resource path
22
- def self.entity_action(rest_api,res_class_path,display_fields)
26
+ def self.entity_action(rest_api,res_class_path,display_fields,id_symb)
23
27
  res_name=res_class_path.gsub(%r{.*/},'').gsub(%r{^s$},'').gsub('_',' ')
24
28
  command=Main.tool.options.get_next_argument('command',ALL_OPS)
25
29
  if INSTANCE_OPS.include?(command)
26
- one_res_id=Main.tool.options.get_option(:id,:mandatory)
30
+ one_res_id=Main.tool.options.get_option(id_symb,:mandatory)
27
31
  one_res_path="#{res_class_path}/#{one_res_id}"
28
32
  end
29
33
  if [:create,:modify].include?(command)
@@ -48,13 +52,13 @@ module Asperalm
48
52
  end
49
53
  end
50
54
 
51
- attr_accessor :optmgr
52
- attr_accessor :main
55
+ attr_reader :optmgr
56
+ attr_reader :main
53
57
 
54
- def initialize(ref=nil)
58
+ def initialize
55
59
  # main is used for .options
56
- @optmgr=ref.nil? ? nil : ref.optmgr
57
- @main=ref.nil? ? nil : ref.main
60
+ @optmgr=@@optmgr
61
+ @main=@@main
58
62
  end
59
63
 
60
64
  def declare_options
@@ -13,35 +13,36 @@ module Asperalm
13
13
 
14
14
  def declare_options
15
15
  @ats=Ats.new
16
- @ats.optmgr=self.optmgr
17
- @ats.main=self.main
18
16
  @ats.declare_options(true)
19
17
 
20
- @optmgr.add_opt_list(:download_mode,[:fasp, :node_http ],"download mode")
21
- @optmgr.add_opt_list(:auth,Oauth.auth_types,"type of Oauth authentication")
22
- @optmgr.add_opt_boolean(:bulk,"bulk operation")
23
- # @optmgr.add_opt_boolean(:long,"long display")
24
- @optmgr.add_opt_simple(:url,"URL of application, e.g. http://org.asperafiles.com")
25
- @optmgr.add_opt_simple(:username,"username to log in")
26
- @optmgr.add_opt_simple(:password,"user's password")
27
- @optmgr.add_opt_simple(:client_id,"API client identifier in application")
28
- @optmgr.add_opt_simple(:client_secret,"API client passcode")
29
- @optmgr.add_opt_simple(:redirect_uri,"API client redirect URI")
30
- @optmgr.add_opt_simple(:private_key,"RSA private key PEM value for JWT (prefix file path with @val:@file:)")
31
- @optmgr.add_opt_simple(:workspace,"name of workspace")
32
- @optmgr.add_opt_simple(:recipient,"package recipient")
33
- @optmgr.add_opt_simple(:title,"package title")
34
- @optmgr.add_opt_simple(:note,"package note")
35
- @optmgr.add_opt_simple(:secret,"access key secret for node")
36
- @optmgr.add_opt_simple(:query,"list filter (extended value: encode_www_form)")
37
- @optmgr.add_opt_simple(:id,"resource identifier")
38
- @optmgr.add_opt_simple(:name,"resource name")
39
- @optmgr.add_opt_simple(:link,"link to shared resource")
40
- @optmgr.set_option(:download_mode,:fasp)
41
- @optmgr.set_option(:bulk,:no)
42
- # @optmgr.set_option(:long,:no)
43
- @optmgr.set_option(:redirect_uri,'http://localhost:12345')
44
- @optmgr.set_option(:auth,:web)
18
+ self.optmgr.add_opt_list(:download_mode,[:fasp, :node_http ],"download mode")
19
+ self.optmgr.add_opt_list(:auth,Oauth.auth_types,"type of Oauth authentication")
20
+ self.optmgr.add_opt_boolean(:bulk,"bulk operation")
21
+ #self.optmgr.add_opt_boolean(:long,"long display")
22
+ self.optmgr.add_opt_simple(:url,"URL of application, e.g. http://org.asperafiles.com")
23
+ self.optmgr.add_opt_simple(:username,"username to log in")
24
+ self.optmgr.add_opt_simple(:password,"user's password")
25
+ self.optmgr.add_opt_simple(:client_id,"API client identifier in application")
26
+ self.optmgr.add_opt_simple(:client_secret,"API client passcode")
27
+ self.optmgr.add_opt_simple(:redirect_uri,"API client redirect URI")
28
+ self.optmgr.add_opt_simple(:private_key,"RSA private key PEM value for JWT (prefix file path with @val:@file:)")
29
+ self.optmgr.add_opt_simple(:workspace,"name of workspace")
30
+ self.optmgr.add_opt_simple(:recipient,"package recipient")
31
+ self.optmgr.add_opt_simple(:title,"package title")
32
+ self.optmgr.add_opt_simple(:note,"package note")
33
+ self.optmgr.add_opt_simple(:secret,"access key secret for node")
34
+ self.optmgr.add_opt_simple(:query,"list filter (extended value: encode_www_form)")
35
+ self.optmgr.add_opt_simple(:id,"resource identifier")
36
+ self.optmgr.add_opt_simple(:eid,"identifier")
37
+ self.optmgr.add_opt_simple(:name,"resource name")
38
+ self.optmgr.add_opt_simple(:link,"link to shared resource")
39
+ self.optmgr.add_opt_simple(:public_token,"token value of public link")
40
+ self.optmgr.add_opt_simple(:value,"extended value for create, update, list filter")
41
+ self.optmgr.set_option(:download_mode,:fasp)
42
+ self.optmgr.set_option(:bulk,:no)
43
+ #self.optmgr.set_option(:long,:no)
44
+ self.optmgr.set_option(:redirect_uri,'http://localhost:12345')
45
+ self.optmgr.set_option(:auth,:web)
45
46
  end
46
47
 
47
48
  # returns a node API for access key
@@ -49,11 +50,17 @@ module Asperalm
49
50
  # if secret present: use it
50
51
  def get_files_node_api(node_info,node_scope=nil)
51
52
  # if no scope, or secret provided on command line ...
52
- if node_scope.nil? or !@optmgr.get_option(:secret,:optional).nil?
53
- return Rest.new({:base_url=>node_info['url'],:auth_type=>:basic,:basic_username=>node_info['access_key'], :basic_password=>@optmgr.get_option(:secret,:mandatory),:headers=>{'X-Aspera-AccessKey'=>node_info['access_key']}})
53
+ if node_scope.nil? or !self.optmgr.get_option(:secret,:optional).nil?
54
+ return Rest.new({
55
+ :base_url =>node_info['url'],
56
+ :auth_type =>:basic,
57
+ :basic_username=>node_info['access_key'],
58
+ :basic_password=>self.optmgr.get_option(:secret,:mandatory),
59
+ :headers =>{'X-Aspera-AccessKey'=>node_info['access_key']
60
+ }})
54
61
  end
55
- Log.log.warn("ignoring secret, using bearer token") if !@optmgr.get_option(:secret,:optional).nil?
56
- return Rest.new(@api_files_user.params.merge!({
62
+ Log.log.warn("ignoring secret, using bearer token") if !self.optmgr.get_option(:secret,:optional).nil?
63
+ return Rest.new(@api_files_user.params.merge({
57
64
  :base_url => node_info['url'],
58
65
  :oauth_scope => FilesApi.node_scope(node_info['access_key'],node_scope),
59
66
  :headers => {'X-Aspera-AccessKey'=>node_info['access_key']}}))
@@ -108,7 +115,8 @@ module Asperalm
108
115
  end
109
116
 
110
117
  # generate a transfer spec from node information and file id
111
- # NOTE: important: transfer id must be unique: generate random id (using a non unique id results in discard of tags, and package is not finalized)
118
+ # NOTE: important: transfer id must be unique: generate random id
119
+ # (using a non unique id results in discard of tags, and package is not finalized)
112
120
  def info_to_tspec(app,direction,node_info,file_id)
113
121
  return {
114
122
  'direction' => direction,
@@ -126,16 +134,20 @@ module Asperalm
126
134
  PATH_SEPARATOR='/'
127
135
 
128
136
  def execute_node_action(home_node_id,home_file_id)
129
- command_repo=@optmgr.get_next_argument('command',[ :browse, :mkdir, :rename, :delete, :upload, :download, :node, :file ])
137
+ command_repo=self.optmgr.get_next_argument('command',[ :access_key, :browse, :mkdir, :rename, :delete, :upload, :download, :node, :file ])
130
138
  case command_repo
139
+ when :access_key
140
+ node_info,file_id = find_nodeinfo_and_fileid(home_node_id,home_file_id)
141
+ node_api=get_files_node_api(node_info,FilesApi::SCOPE_NODE_USER)
142
+ return Plugin.entity_action(node_api,'access_keys',['id','root_file_id','storage','license'],:eid)
131
143
  when :browse
132
- thepath=@optmgr.get_next_argument("path")
144
+ thepath=self.optmgr.get_next_argument("path")
133
145
  node_info,file_id = find_nodeinfo_and_fileid(home_node_id,home_file_id,thepath)
134
146
  node_api=get_files_node_api(node_info,FilesApi::SCOPE_NODE_USER)
135
147
  items=node_api.read("files/#{file_id}/files")[:data]
136
148
  return {:type=>:hash_array,:data=>items,:fields=>['name','type','recursive_size','size','modified_time','access_level']}
137
149
  when :mkdir
138
- thepath=@optmgr.get_next_argument("path")
150
+ thepath=self.optmgr.get_next_argument("path")
139
151
  containing_folder_path = thepath.split(PATH_SEPARATOR)
140
152
  new_folder=containing_folder_path.pop
141
153
  node_info,file_id = find_nodeinfo_and_fileid(home_node_id,home_file_id,containing_folder_path.join(PATH_SEPARATOR))
@@ -143,28 +155,28 @@ module Asperalm
143
155
  result=node_api.create("files/#{file_id}/files",{:name=>new_folder,:type=>:folder})[:data]
144
156
  return Plugin.result_status("created: #{result['name']} (id=#{result['id']})")
145
157
  when :rename
146
- thepath=@optmgr.get_next_argument("source path")
147
- newname=@optmgr.get_next_argument("new name")
158
+ thepath=self.optmgr.get_next_argument("source path")
159
+ newname=self.optmgr.get_next_argument("new name")
148
160
  node_info,file_id = find_nodeinfo_and_fileid(home_node_id,home_file_id,thepath)
149
161
  node_api=get_files_node_api(node_info,FilesApi::SCOPE_NODE_USER)
150
162
  result=node_api.update("files/#{file_id}",{:name=>newname})[:data]
151
163
  return Plugin.result_status("renamed #{thepath} to #{newname}")
152
164
  when :delete
153
- thepath=@optmgr.get_next_argument("path")
165
+ thepath=self.optmgr.get_next_argument("path")
154
166
  node_info,file_id = find_nodeinfo_and_fileid(home_node_id,home_file_id,thepath)
155
167
  node_api=get_files_node_api(node_info,FilesApi::SCOPE_NODE_USER)
156
168
  result=node_api.delete("files/#{file_id}")[:data]
157
169
  return Plugin.result_status("deleted: #{thepath}")
158
170
  when :upload
159
- filelist = @optmgr.get_next_argument("file list",:multiple)
171
+ filelist = self.optmgr.get_next_argument("file list",:multiple)
160
172
  Log.log.debug("file list=#{filelist}")
161
173
  node_info,file_id = find_nodeinfo_and_fileid(home_node_id,home_file_id,@main.destination_folder('send'))
162
174
  tspec=info_to_tspec('files','send',node_info,file_id)
163
175
  tspec['paths']=filelist.map { |i| {'source'=>i} }
164
176
  return @main.start_transfer(tspec,:node_gen4)
165
177
  when :download
166
- source_file=@optmgr.get_next_argument('source')
167
- case @optmgr.get_option(:download_mode,:mandatory)
178
+ source_file=self.optmgr.get_next_argument('source')
179
+ case self.optmgr.get_option(:download_mode,:mandatory)
168
180
  when :fasp
169
181
  file_path = source_file.split(PATH_SEPARATOR)
170
182
  file_name = file_path.pop
@@ -182,13 +194,13 @@ module Asperalm
182
194
  end # download_mode
183
195
  when :node
184
196
  # Note: other "common" actions are unauthorized with user scope
185
- command_legacy=@optmgr.get_next_argument('command',Node.simple_actions)
197
+ command_legacy=self.optmgr.get_next_argument('command',Node.simple_actions)
186
198
  # TODO: shall we support all methods here ? what if there is a link ?
187
199
  node_info=@api_files_user.read("nodes/#{home_node_id}")[:data]
188
200
  node_api=get_files_node_api(node_info,FilesApi::SCOPE_NODE_USER)
189
201
  return Node.new(self).execute_common(command_legacy,node_api)
190
202
  when :file
191
- fileid=@optmgr.get_next_argument("file id")
203
+ fileid=self.optmgr.get_next_argument("file id")
192
204
  node_info,file_id = find_nodeinfo_and_fileid(home_node_id,fileid)
193
205
  node_api=get_files_node_api(node_info,FilesApi::SCOPE_NODE_USER)
194
206
  items=node_api.read("files/#{file_id}")[:data]
@@ -196,77 +208,102 @@ module Asperalm
196
208
  end # command_repo
197
209
  end # def
198
210
 
211
+ attr_accessor :api_files_admn
212
+ attr_accessor :api_files_user
213
+
199
214
  # initialize apis and authentication
200
- # returns true if in default workspace
215
+ # set:
216
+ # @api_files_user
217
+ # @api_files_admn
218
+ # @default_workspace_id
219
+ # @workspace_name
220
+ # @workspace_id
221
+ # @user_id
222
+ # @home_file_id
223
+ # @home_node_id
224
+ # returns nil
201
225
  def init_apis
202
- public_link=@optmgr.get_option(:link,:optional)
203
-
204
- rest_params={}
226
+ public_link=self.optmgr.get_option(:link,:optional)
205
227
 
206
- # if auth is a public link
228
+ # if auth is a public link, option "link" is a shortcut for options: url, auth, public_token
207
229
  unless public_link.nil?
208
230
  uri=URI.parse(public_link)
209
- unless uri.path.eql?('/packages/public/receive')
210
- raise CliArgument,"only public package link is supported: /packages/public/receive"
231
+ public_link=nil
232
+ unless uri.path.eql?(FilesApi.PATH_PUBLIC_PACKAGE)
233
+ raise CliArgument,"only public package link is supported: #{FilesApi.PATH_PUBLIC_PACKAGE}"
211
234
  end
212
- rest_params[:oauth_url_token]=URI::decode_www_form(uri.query).select{|e|e.first.eql?('token')}.first
213
- if rest_params[:oauth_url_token].nil?
214
- raise CliArgument,"uri must have parameter token"
235
+ url_token_value=URI::decode_www_form(uri.query).select{|e|e.first.eql?('token')}.first
236
+ if url_token_value.nil?
237
+ raise CliArgument,"link option must be url with 'token' parameter"
215
238
  end
216
- random=FilesApi.random
217
- @optmgr.set_option(:url,'https://'+uri.host)
218
- @optmgr.set_option(:auth,:url_token)
219
- @optmgr.set_option(:client_id,random.first)
220
- @optmgr.set_option(:client_secret,random.last)
239
+ self.optmgr.set_option(:url,'https://'+uri.host)
240
+ self.optmgr.set_option(:public_token,url_token_value)
241
+ self.optmgr.set_option(:auth,:url_token)
242
+ self.optmgr.set_option(:client_id,FilesApi.random.first)
243
+ self.optmgr.set_option(:client_secret,FilesApi.random.last)
221
244
  end
222
245
 
223
- FilesApi.set_rest_params(@optmgr.get_option(:url,:mandatory),rest_params)
224
-
225
- rest_params[:auth_type] = :oauth2
226
- rest_params[:oauth_type] = @optmgr.get_option(:auth,:mandatory)
227
- rest_params[:oauth_client_id] = @optmgr.get_option(:client_id,:mandatory)
228
- rest_params[:oauth_client_secret] = @optmgr.get_option(:client_secret,:mandatory)
229
-
230
- case rest_params[:oauth_type]
246
+ # Connection paramaters (url and auth) to Aspera on Cloud
247
+ # pre populate rest parameters based on URL
248
+ aoc_rest_params=
249
+ FilesApi.base_rest_params(self.optmgr.get_option(:url,:mandatory)).merge!({
250
+ :oauth_type => self.optmgr.get_option(:auth,:mandatory),
251
+ :oauth_client_id => self.optmgr.get_option(:client_id,:mandatory),
252
+ :oauth_client_secret => self.optmgr.get_option(:client_secret,:mandatory)
253
+ })
254
+
255
+ # fill other auth parameters based on Oauth method
256
+ case aoc_rest_params[:oauth_type]
231
257
  when :basic
232
- rest_params.delete(:auth_type)
233
- rest_params[:basic_username]=@optmgr.get_option(:username,:mandatory)
234
- rest_params[:basic_password]=@optmgr.get_option(:password,:mandatory)
258
+ aoc_rest_params.merge!({
259
+ :oauth_basic_type => :www_body,
260
+ :oauth_basic_username => self.optmgr.get_option(:username,:mandatory),
261
+ :oauth_basic_password => self.optmgr.get_option(:password,:mandatory)
262
+ })
235
263
  when :web
236
- rest_params[:oauth_redirect_uri]=@optmgr.get_option(:redirect_uri,:mandatory)
237
- Log.log.info("redirect_uri=#{rest_params[:oauth_redirect_uri]}")
264
+ aoc_rest_params.merge!({
265
+ :oauth_redirect_uri => self.optmgr.get_option(:redirect_uri,:mandatory)
266
+ })
238
267
  when :jwt
239
- private_key_PEM_string=@optmgr.get_option(:private_key,:mandatory)
240
- rest_params[:oauth_jwt_private_key_obj]=OpenSSL::PKey::RSA.new(private_key_PEM_string)
241
- rest_params[:oauth_jwt_subject]=@optmgr.get_option(:username,:mandatory)
242
- Log.log.info("private_key=#{rest_params[:oauth_jwt_private_key_obj]}")
243
- Log.log.info("subject=#{rest_params[:oauth_jwt_subject]}")
268
+ private_key_PEM_string=self.optmgr.get_option(:private_key,:mandatory)
269
+ aoc_rest_params.merge!({
270
+ :oauth_jwt_subject => self.optmgr.get_option(:username,:mandatory),
271
+ :oauth_jwt_private_key_obj => OpenSSL::PKey::RSA.new(private_key_PEM_string)
272
+ })
244
273
  when :url_token
274
+ aoc_rest_params.merge!({
275
+ :oauth_url_token => self.optmgr.get_option(:public_token,:mandatory),
276
+ })
245
277
  else raise "ERROR"
246
278
  end
279
+ Log.log.debug("REST params=#{aoc_rest_params}")
247
280
 
248
281
  # create objects for REST calls to Aspera (user and admin scope)
249
- rest_params[:oauth_scope]=FilesApi::SCOPE_FILES_USER
250
- @api_files_user=Rest.new(rest_params)
251
- rest_params[:oauth_scope]=FilesApi::SCOPE_FILES_ADMIN
252
- @api_files_admin=Rest.new(rest_params)
282
+ @api_files_user=Rest.new(aoc_rest_params.merge!({:oauth_scope=>FilesApi::SCOPE_FILES_USER}))
283
+ @api_files_admn=Rest.new(aoc_rest_params.merge!({:oauth_scope=>FilesApi::SCOPE_FILES_ADMIN}))
253
284
 
254
- url_token_data=nil
255
- if public_link.nil?
256
- # get our user's default information
257
- @self_data=@api_files_user.read("self")[:data]
258
- else
285
+ if aoc_rest_params.has_key?(:oauth_url_token)
286
+ # "self" is not accessible for public links, so emulate it.
259
287
  org_data=@api_files_user.read("organization")[:data]
260
288
  url_token_data=@api_files_user.read("url_tokens")[:data].first
261
- @self_data={'default_workspace_id'=>url_token_data['data']['workspace_id']}
262
- #raise "OK"
289
+ @default_workspace_id=url_token_data['data']['workspace_id']
290
+ @user_id='todo'
291
+ self.optmgr.set_option(:id,url_token_data['data']['package_id'])
292
+ @home_node_id=url_token_data['data']['node_id']
293
+ @home_file_id=url_token_data['data']['file_id']
294
+ url_token_data=nil # no more needed
295
+ else
296
+ # get our user's default information
297
+ self_data=@api_files_user.read("self")[:data]
298
+ @default_workspace_id=self_data['default_workspace_id']
299
+ @user_id=self_data['id']
263
300
  end
264
301
 
265
- ws_name=@optmgr.get_option(:workspace,:optional)
302
+ ws_name=self.optmgr.get_option(:workspace,:optional)
266
303
  if ws_name.nil?
267
304
  # get default workspace
268
- @workspace_id=@self_data['default_workspace_id']
269
- @workspace_data=@api_files_user.read("workspaces/#{@workspace_id}")[:data]
305
+ @workspace_id=@default_workspace_id
306
+ workspace_data=@api_files_user.read("workspaces/#{@workspace_id}")[:data]
270
307
  else
271
308
  # lookup another workspace
272
309
  wss=@api_files_user.read("workspaces",{'q'=>ws_name})[:data]
@@ -275,23 +312,18 @@ module Asperalm
275
312
  when 0
276
313
  raise CliBadArgument,"no such workspace: #{ws_name}"
277
314
  when 1
278
- @workspace_data=wss[0]
279
- @workspace_id=@workspace_data['id']
315
+ workspace_data=wss.first
316
+ @workspace_id=workspace_data['id']
280
317
  else
281
318
  raise "unexpected case"
282
319
  end
283
320
  end
284
321
 
285
- unless public_link.nil?
286
- @workspace_data['home_node_id']=url_token_data['data']['node_id']
287
- @workspace_data['home_file_id']=url_token_data['data']['file_id']
288
- @optmgr.set_option(:id,url_token_data['data']['package_id'])
289
- end
290
-
291
- Log.log.debug("workspace_id=#{@workspace_id},workspace_data=#{@workspace_data}".red)
322
+ Log.log.debug("workspace_id=#{@workspace_id},workspace_data=#{workspace_data}".red)
292
323
 
293
- @home_node_id=@workspace_data['home_node_id']
294
- @home_file_id=@workspace_data['home_file_id']
324
+ @workspace_name||=workspace_data['name']
325
+ @home_node_id||=workspace_data['home_node_id']
326
+ @home_file_id||=workspace_data['home_file_id']
295
327
  raise "ERROR: assert" if @home_node_id.to_s.empty?
296
328
  raise "ERROR: assert" if @home_file_id.to_s.empty?
297
329
 
@@ -299,7 +331,7 @@ module Asperalm
299
331
  end
300
332
 
301
333
  def do_bulk_operation(params,success,&do_action)
302
- params=[params] unless @optmgr.get_option(:bulk)
334
+ params=[params] unless self.optmgr.get_option(:bulk)
303
335
  raise "expecting Array" unless params.is_a?(Array)
304
336
  result=[]
305
337
  params.each do |p|
@@ -313,45 +345,45 @@ module Asperalm
313
345
 
314
346
  def execute_action
315
347
  init_apis
316
- command=@optmgr.get_next_argument('command',action_list)
317
- if @optmgr.get_option(:format,:optional).eql?(:table) and !command.eql?(:admin)
318
- default_ws=@workspace_id == @self_data['default_workspace_id'] ? ' (default)' : ''
319
- puts "Current Workspace: #{@workspace_data['name'].red}#{default_ws}"
348
+ command=self.optmgr.get_next_argument('command',action_list)
349
+ if self.optmgr.get_option(:format,:optional).eql?(:table) and !command.eql?(:admin)
350
+ default_ws=@workspace_id == @default_workspace_id ? ' (default)' : ''
351
+ puts "Current Workspace: #{@workspace_name.red}#{default_ws}"
320
352
  end
321
353
 
322
354
  # display name of default workspace
323
- Log.log.info("current workspace is "+@workspace_data['name'].red)
355
+ Log.log.info("current workspace is "+@workspace_name.red)
324
356
 
325
357
  case command
326
358
  when :user
327
- command=@optmgr.get_next_argument('command',[ :workspaces,:info ])
359
+ command=self.optmgr.get_next_argument('command',[ :workspaces,:info ])
328
360
  case command
329
361
  when :workspaces
330
362
  return {:type=>:hash_array,:data=>@api_files_user.read("workspaces")[:data],:fields=>['id','name']}
331
363
  # when :settings
332
364
  # return {:type=>:hash_array,:data=>@api_files_user.read("client_settings/")[:data]}
333
365
  when :info
334
- resource_instance_path="users/#{@self_data['id']}"
335
- command=@optmgr.get_next_argument('command',[ :show,:modify ])
366
+ resource_instance_path="users/#{@user_id}"
367
+ command=self.optmgr.get_next_argument('command',[ :show,:modify ])
336
368
  case command
337
369
  when :show
338
- object=@api_files_admin.read(resource_instance_path)[:data]
370
+ object=@api_files_admn.read(resource_instance_path)[:data]
339
371
  return { :type=>:key_val_list, :data =>object }
340
372
  when :modify
341
- changes=@optmgr.get_next_argument('modified parameters (hash)')
342
- @api_files_admin.update(resource_instance_path,changes)
373
+ changes=self.optmgr.get_next_argument('modified parameters (hash)')
374
+ @api_files_admn.update(resource_instance_path,changes)
343
375
  return Plugin.result_status('modified')
344
376
  end
345
377
  end
346
378
  when :packages
347
- command_pkg=@optmgr.get_next_argument('command',[ :send, :recv, :list, :show ])
379
+ command_pkg=self.optmgr.get_next_argument('command',[ :send, :recv, :list, :show ])
348
380
  case command_pkg
349
381
  when :send
350
382
  # list of files to include in package
351
- filelist = @optmgr.get_next_argument("file list",:multiple)
383
+ filelist = self.optmgr.get_next_argument("file list",:multiple)
352
384
 
353
385
  # lookup users
354
- recipient_data=@optmgr.get_option(:recipient,:mandatory).split(',').map { |recipient|
386
+ recipient_data=self.optmgr.get_option(:recipient,:mandatory).split(',').map { |recipient|
355
387
  user_lookup=@api_files_user.read("contacts",{'current_workspace_id'=>@workspace_id,'q'=>recipient})[:data]
356
388
  raise CliBadArgument,"no such user: #{recipient}" unless !user_lookup.nil? and user_lookup.length == 1
357
389
  recipient_user_id=user_lookup.first
@@ -359,7 +391,7 @@ module Asperalm
359
391
  }
360
392
 
361
393
  # create a new package with one file
362
- the_package=@api_files_user.create("packages",{"workspace_id"=>@workspace_id,"name"=>@optmgr.get_option(:title,:mandatory),"file_names"=>filelist,"note"=>@optmgr.get_option(:note,:mandatory),"recipients"=>recipient_data})[:data]
394
+ the_package=@api_files_user.create("packages",{"workspace_id"=>@workspace_id,"name"=>self.optmgr.get_option(:title,:mandatory),"file_names"=>filelist,"note"=>self.optmgr.get_option(:note,:mandatory),"recipients"=>recipient_data})[:data]
363
395
 
364
396
  # get node information for the node on which package must be created
365
397
  node_info=@api_files_user.read("nodes/#{the_package['node_id']}")[:data]
@@ -372,7 +404,7 @@ module Asperalm
372
404
  tspec['paths']=filelist.map { |i| {'source'=>i} }
373
405
  return @main.start_transfer(tspec,:node_gen4)
374
406
  when :recv
375
- package_id=@optmgr.get_option(:id,:mandatory)
407
+ package_id=self.optmgr.get_option(:id,:mandatory)
376
408
  the_package=@api_files_user.read("packages/#{package_id}")[:data]
377
409
  node_info=@api_files_user.read("nodes/#{the_package['node_id']}")[:data]
378
410
  tspec=info_to_tspec('packages','receive',node_info,the_package['contents_file_id'])
@@ -380,9 +412,9 @@ module Asperalm
380
412
  tspec['paths']=[{'source'=>'.'}]
381
413
  return @main.start_transfer(tspec,:node_gen4)
382
414
  when :show
383
- package_id=@optmgr.get_next_argument('package ID')
415
+ package_id=self.optmgr.get_next_argument('package ID')
384
416
  the_package=@api_files_user.read("packages/#{package_id}")[:data]
385
- # if @optmgr.get_option(:long)
417
+ # if self.optmgr.get_option(:long)
386
418
  # node_info,file_id = find_nodeinfo_and_fileid(the_package['node_id'],the_package['contents_file_id'])
387
419
  # node_api=get_files_node_api(node_info,FilesApi::SCOPE_NODE_USER)
388
420
  # items=node_api.read("files/#{file_id}/files")[:data]
@@ -401,22 +433,22 @@ module Asperalm
401
433
  require 'asperalm/faspex_gw'
402
434
  FaspexGW.instance.start_server(@api_files_user,@workspace_id)
403
435
  when :admin
404
- command_admin=@optmgr.get_next_argument('command',[ :ats, :resource, :events, :set_client_key, :usage_reports, :search_nodes ])
436
+ command_admin=self.optmgr.get_next_argument('command',[ :ats, :resource, :events, :set_client_key, :usage_reports, :search_nodes ])
405
437
  case command_admin
406
438
  when :ats
407
- @ats.ats_api_public = @ats.ats_api_secure = Rest.new(@api_files_admin.params.clone.merge!({
408
- :base_url => @api_files_admin.params[:base_url]+'/admin/ats/pub/v1',
439
+ @ats.ats_api_public = @ats.ats_api_secure = Rest.new(@api_files_admn.params.clone.merge!({
440
+ :base_url => @api_files_admn.params[:base_url]+'/admin/ats/pub/v1',
409
441
  :oauth_scope => FilesApi::SCOPE_FILES_ADMIN_USER
410
442
  }))
411
443
 
412
444
  return @ats.execute_action_gen
413
445
  when :search_nodes
414
- ak=@optmgr.get_next_argument('access_key')
415
- nodes=@api_files_admin.read("search_nodes",{'q'=>'access_key:"'+ak+'"'})[:data]
446
+ ak=self.optmgr.get_next_argument('access_key')
447
+ nodes=@api_files_admn.read("search_nodes",{'q'=>'access_key:"'+ak+'"'})[:data]
416
448
  return {:type=>:other_struct,:data=>nodes}
417
449
  when :events
418
450
  # page=1&per_page=10&q=type:(file_upload+OR+file_delete+OR+file_download+OR+file_rename+OR+folder_create+OR+folder_delete+OR+folder_share+OR+folder_share_via_public_link)&sort=-date
419
- #events=@api_files_admin.read('events',{'q'=>'type:(file_upload OR file_download)'})[:data]
451
+ #events=@api_files_admn.read('events',{'q'=>'type:(file_upload OR file_download)'})[:data]
420
452
  #Log.log.info "events=#{JSON.generate(events)}"
421
453
  node_info=@api_files_user.read("nodes/#{@home_node_id}")[:data]
422
454
  # get access to node API, note the additional header
@@ -433,12 +465,12 @@ module Asperalm
433
465
  #transfers=api_node.make_request_ex({:operation=>'GET',:subpath=>'ops/transfers',:args=>{'count'=>25,'filter'=>'id'}})
434
466
  #transfers=api_node.read("events") # after_time=2016-05-01T23:53:09Z
435
467
  when :set_client_key
436
- the_client_id=@optmgr.get_next_argument('client_id')
437
- the_private_key=@optmgr.get_next_argument('private_key')
438
- @api_files_admin.update("clients/#{the_client_id}",{:jwt_grant_enabled=>true, :public_key=>OpenSSL::PKey::RSA.new(the_private_key).public_key.to_s})
468
+ the_client_id=self.optmgr.get_next_argument('client_id')
469
+ the_private_key=self.optmgr.get_next_argument('private_key')
470
+ @api_files_admn.update("clients/#{the_client_id}",{:jwt_grant_enabled=>true, :public_key=>OpenSSL::PKey::RSA.new(the_private_key).public_key.to_s})
439
471
  return Plugin.result_success
440
472
  when :resource
441
- resource_type=@optmgr.get_next_argument('resource',[:self,:user,:group,:client,:contact,:dropbox,:node,:operation,:package,:saml_configuration, :workspace, :dropbox_membership,:short_link])
473
+ resource_type=self.optmgr.get_next_argument('resource',[:self,:user,:group,:client,:contact,:dropbox,:node,:operation,:package,:saml_configuration, :workspace, :dropbox_membership,:short_link])
442
474
  resource_class_path=resource_type.to_s+case resource_type;when :dropbox;'es';when :self;'';else; 's';end
443
475
  singleton_object=[:self].include?(resource_type)
444
476
  global_operations=[:create,:list]
@@ -446,14 +478,14 @@ module Asperalm
446
478
  supported_operations.push(:modify,:delete,*global_operations) unless singleton_object
447
479
  supported_operations.push(:do) if resource_type.eql?(:node)
448
480
  supported_operations.push(:shared_folders) if resource_type.eql?(:workspace)
449
- command=@optmgr.get_next_argument('command',supported_operations)
481
+ command=self.optmgr.get_next_argument('command',supported_operations)
450
482
  # require identifier for non global commands
451
483
  if !singleton_object and !global_operations.include?(command)
452
- res_id=@optmgr.get_option(:id)
453
- res_name=@optmgr.get_option(:name)
484
+ res_id=self.optmgr.get_option(:id)
485
+ res_name=self.optmgr.get_option(:name)
454
486
  if res_id.nil?
455
487
  raise "Use either id or name" if res_name.nil?
456
- matching=@api_files_admin.read(resource_class_path,{:q=>res_name})[:data]
488
+ matching=@api_files_admn.read(resource_class_path,{:q=>res_name})[:data]
457
489
  raise CliError,"no resource match name" if matching.empty?
458
490
  raise CliError,"several resources match name" unless matching.length.eql?(1)
459
491
  res_id=matching.first['id']
@@ -465,10 +497,10 @@ module Asperalm
465
497
  resource_instance_path=resource_class_path if singleton_object
466
498
  case command
467
499
  when :create
468
- list_or_one=@optmgr.get_next_argument("creation data (Hash)")
500
+ list_or_one=self.optmgr.get_next_argument("creation data (Hash)")
469
501
  return do_bulk_operation(list_or_one,'created')do|params|
470
502
  raise "expecting Hash" unless params.is_a?(Hash)
471
- @api_files_admin.create(resource_class_path,params)[:data]
503
+ @api_files_admn.create(resource_class_path,params)[:data]
472
504
  end
473
505
  when :list
474
506
  default_fields=['id','name']
@@ -477,39 +509,39 @@ module Asperalm
477
509
  when :operation; default_fields=nil
478
510
  when :contact; default_fields=["email","name","source_id","source_type"]
479
511
  end
480
- query=@optmgr.get_option(:query,:optional)
512
+ query=self.optmgr.get_option(:query,:optional)
481
513
  Log.log.debug("Query=#{query}".bg_red)
482
514
  begin
483
515
  URI.encode_www_form(query) unless query.nil?
484
516
  rescue => e
485
517
  raise CliBadArgument,"query must be an extended value which can be encoded with URI.encode_www_form. Refer to manual. (#{e.message})"
486
518
  end
487
- return {:type=>:hash_array,:data=>@api_files_admin.read(resource_class_path,query)[:data],:fields=>default_fields}
519
+ return {:type=>:hash_array,:data=>@api_files_admn.read(resource_class_path,query)[:data],:fields=>default_fields}
488
520
  when :show
489
- object=@api_files_admin.read(resource_instance_path)[:data]
521
+ object=@api_files_admn.read(resource_instance_path)[:data]
490
522
  fields=object.keys.select{|k|!k.eql?('certificate')}
491
523
  return { :type=>:key_val_list, :data =>object, :fields=>fields }
492
524
  when :modify
493
- changes=@optmgr.get_next_argument('modified parameters (hash)')
494
- @api_files_admin.update(resource_instance_path,changes)
525
+ changes=self.optmgr.get_next_argument('modified parameters (hash)')
526
+ @api_files_admn.update(resource_instance_path,changes)
495
527
  return Plugin.result_status('modified')
496
528
  when :delete
497
529
  return do_bulk_operation(res_id,'deleted')do|one_id|
498
- @api_files_admin.delete("#{resource_class_path}/#{one_id.to_s}")
530
+ @api_files_admn.delete("#{resource_class_path}/#{one_id.to_s}")
499
531
  {'id'=>one_id}
500
532
  end
501
533
  when :do
502
- res_data=@api_files_admin.read(resource_instance_path)[:data]
534
+ res_data=@api_files_admn.read(resource_instance_path)[:data]
503
535
  api_node=get_files_node_api(res_data)
504
536
  ak_data=api_node.call({:operation=>'GET',:subpath=>"access_keys/#{res_data['access_key']}",:headers=>{'Accept'=>'application/json'}})[:data]
505
537
  return execute_node_action(res_id,ak_data['root_file_id'])
506
538
  when :shared_folders
507
- res_data=@api_files_admin.read("#{resource_class_path}/#{res_id}/permissions")[:data]
539
+ res_data=@api_files_admn.read("#{resource_class_path}/#{res_id}/permissions")[:data]
508
540
  return { :type=>:hash_array, :data =>res_data , :fields=>['id','node_name','file_id']} #
509
541
  else raise :ERROR
510
542
  end
511
543
  when :usage_reports
512
- return {:type=>:hash_array,:data=>@api_files_admin.read("usage_reports",{:workspace_id=>@workspace_id})[:data]}
544
+ return {:type=>:hash_array,:data=>@api_files_admn.read("usage_reports",{:workspace_id=>@workspace_id})[:data]}
513
545
  end
514
546
  end # action
515
547
  raise RuntimeError, "internal error"