opennebula-cli 5.6.2 → 5.7.80.pre

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.
data/bin/oneuser CHANGED
@@ -16,16 +16,16 @@
16
16
  # limitations under the License. #
17
17
  #--------------------------------------------------------------------------- #
18
18
 
19
- ONE_LOCATION=ENV["ONE_LOCATION"]
19
+ ONE_LOCATION = ENV['ONE_LOCATION']
20
20
 
21
21
  if !ONE_LOCATION
22
- RUBY_LIB_LOCATION="/usr/lib/one/ruby"
22
+ RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
23
23
  else
24
- RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
24
+ RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
25
25
  end
26
26
 
27
- $: << RUBY_LIB_LOCATION
28
- $: << RUBY_LIB_LOCATION+"/cli"
27
+ $LOAD_PATH << RUBY_LIB_LOCATION
28
+ $LOAD_PATH << RUBY_LIB_LOCATION + '/cli'
29
29
 
30
30
  require 'command_parser'
31
31
  require 'one_helper/oneuser_helper'
@@ -33,8 +33,8 @@ require 'one_helper/onequota_helper'
33
33
 
34
34
  require 'uri'
35
35
 
36
- cmd=CommandParser::CmdParser.new(ARGV) do
37
- usage "`oneuser` <command> [<args>] [<options>]"
36
+ CommandParser::CmdParser.new(ARGV) do
37
+ usage '`oneuser` <command> [<args>] [<options>]'
38
38
  version OpenNebulaHelper::ONE_VERSION
39
39
 
40
40
  helper = OneUserHelper.new
@@ -43,7 +43,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
43
43
  if ![:key].include?(@comm_name)
44
44
  begin
45
45
  helper.set_client(options)
46
- rescue Exception => e
46
+ rescue StandardError => e
47
47
  STDERR.puts e.message
48
48
 
49
49
  if e.message != OpenNebula::Client::NO_ONE_AUTH_ERROR
@@ -58,149 +58,149 @@ cmd=CommandParser::CmdParser.new(ARGV) do
58
58
  ########################################################################
59
59
  # Global Options
60
60
  ########################################################################
61
- set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
61
+ set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
62
62
 
63
63
  list_options = CLIHelper::OPTIONS
64
64
  list_options << OpenNebulaHelper::XML
65
65
  list_options << OpenNebulaHelper::NUMERIC
66
66
  list_options << OpenNebulaHelper::DESCRIBE
67
67
 
68
- READ_FILE={
69
- :name => "read_file",
70
- :short => "-r",
71
- :large => "--read-file",
72
- :description => "Read password from file"
68
+ READ_FILE = {
69
+ :name => 'read_file',
70
+ :short => '-r',
71
+ :large => '--read-file',
72
+ :description => 'Read password from file'
73
73
  }
74
74
 
75
- SHA1={
76
- :name => "sha1",
77
- :large => "--sha1",
78
- :description => "The password will be hashed using the sha1\n"<<
79
- " "*31<<"algorithm"
75
+ SHA1 = {
76
+ :name => 'sha1',
77
+ :large => '--sha1',
78
+ :description => "The password will be hashed using the sha1\n" \
79
+ ' ' * 31 << 'algorithm'
80
80
  }
81
81
 
82
- SSH={
83
- :name => "ssh",
84
- :large => "--ssh",
85
- :description => "SSH Auth system",
86
- :proc => lambda { |o, options|
82
+ SSH = {
83
+ :name => 'ssh',
84
+ :large => '--ssh',
85
+ :description => 'SSH Auth system',
86
+ :proc => lambda {|_, options|
87
87
  options[:driver] = OpenNebula::User::SSH_AUTH
88
88
  }
89
89
  }
90
90
 
91
- X509={
92
- :name => "x509",
93
- :large => "--x509",
94
- :description => "x509 Auth system for x509 certificates",
95
- :proc => lambda { |o, options|
91
+ X509 = {
92
+ :name => 'x509',
93
+ :large => '--x509',
94
+ :description => 'x509 Auth system for x509 certificates',
95
+ :proc => lambda {|_, options|
96
96
  options[:driver] = OpenNebula::User::X509_AUTH
97
97
  }
98
98
  }
99
99
 
100
- X509_PROXY={
101
- :name => "x509_proxy",
102
- :large => "--x509_proxy",
103
- :description => "x509 Auth system based on x509 proxy certificates",
104
- :proc => lambda { |o, options|
100
+ X509_PROXY = {
101
+ :name => 'x509_proxy',
102
+ :large => '--x509_proxy',
103
+ :description => 'x509 Auth system based on x509 proxy certificates',
104
+ :proc => lambda {|_, options|
105
105
  options[:driver] = OpenNebula::User::X509_PROXY_AUTH
106
106
  }
107
107
  }
108
108
 
109
- KEY={
110
- :name => "key",
111
- :short => "-k path_to_private_key_pem",
112
- :large => "--key path_to_private_key_pem",
109
+ KEY = {
110
+ :name => 'key',
111
+ :short => '-k path_to_private_key_pem',
112
+ :large => '--key path_to_private_key_pem',
113
113
  :format => String,
114
- :description => "Path to the Private Key of the User"
114
+ :description => 'Path to the Private Key of the User'
115
115
  }
116
116
 
117
- CERT={
118
- :name => "cert",
119
- :short => "-c path_to_user_cert_pem",
120
- :large => "--cert path_to_user_cert_pem",
117
+ CERT = {
118
+ :name => 'cert',
119
+ :short => '-c path_to_user_cert_pem',
120
+ :large => '--cert path_to_user_cert_pem',
121
121
  :format => String,
122
- :description => "Path to the Certificate of the User"
122
+ :description => 'Path to the Certificate of the User'
123
123
  }
124
124
 
125
- PROXY={
126
- :name => "proxy",
127
- :large => "--proxy path_to_user_proxy_pem",
125
+ PROXY = {
126
+ :name => 'proxy',
127
+ :large => '--proxy path_to_user_proxy_pem',
128
128
  :format => String,
129
- :description => "Path to the user proxy certificate"
129
+ :description => 'Path to the user proxy certificate'
130
130
  }
131
131
 
132
- TIME={
133
- :name => "time",
134
- :large => "--time x",
132
+ TIME = {
133
+ :name => 'time',
134
+ :large => '--time x',
135
135
  :format => Integer,
136
- :description => "Token duration in seconds, defaults to 36000 (10 h). "\
137
- "To reset the token set time to 0." \
138
- "To generate a non-expiring token use -1"\
139
- " (not valid for ssh and x509 tokens). "\
136
+ :description => 'Token duration in seconds, defaults to 36000 (10 h). '\
137
+ 'To reset the token set time to 0.' \
138
+ 'To generate a non-expiring token use -1'\
139
+ ' (not valid for ssh and x509 tokens). '\
140
140
  }
141
141
 
142
- DRIVER={
143
- :name => "driver",
144
- :large => "--driver driver",
142
+ DRIVER = {
143
+ :name => 'driver',
144
+ :large => '--driver driver',
145
145
  :format => String,
146
- :description => "Driver to authenticate this user"
146
+ :description => 'Driver to authenticate this user'
147
147
  }
148
148
 
149
149
  FORCE = {
150
- :name => "force",
151
- :large => "--force" ,
152
- :description => "Force one_auth file rewrite"
150
+ :name => 'force',
151
+ :large => '--force',
152
+ :description => 'Force one_auth file rewrite'
153
153
  }
154
154
 
155
155
  TOKEN = {
156
- :name => "token",
157
- :large => "--token token_hint",
156
+ :name => 'token',
157
+ :large => '--token token_hint',
158
158
  :format => String,
159
- :description => "The Token to be loaded."
159
+ :description => 'The Token to be loaded.'
160
160
  }
161
161
 
162
162
  GROUP = {
163
- :name => "group",
164
- :large => "--group id|name" ,
165
- :description => "Effective GID to use with this token.",
163
+ :name => 'group',
164
+ :large => '--group id|name',
165
+ :description => 'Effective GID to use with this token.',
166
166
  :format => String,
167
- :proc => lambda { |o, options|
168
- OpenNebulaHelper.rname_to_id(o, "GROUP")
167
+ :proc => lambda {|o, _|
168
+ OpenNebulaHelper.rname_to_id(o, 'GROUP')
169
169
  }
170
170
  }
171
171
 
172
172
  GROUP_CREATE = {
173
- :name => "group",
174
- :large => "--group id|name" ,
175
- :description => "Comma-separated list of Groups for the new User. "\
176
- "The first Group will be the main one.",
173
+ :name => 'group',
174
+ :large => '--group id|name',
175
+ :description => 'Comma-separated list of Groups for the new User. '\
176
+ 'The first Group will be the main one.',
177
177
  :format => String,
178
- :proc => lambda { |o, options|
179
- gids = o.split(",").map { |g|
180
- id = OpenNebulaHelper.rname_to_id(g, "GROUP")
178
+ :proc => lambda {|o, _|
179
+ gids = o.split(',').map do |g|
180
+ id = OpenNebulaHelper.rname_to_id(g, 'GROUP')
181
181
 
182
- if (id[0] == -1)
182
+ if id[0] == -1
183
183
  puts id[1]
184
- exit -1
184
+ exit(-1)
185
185
  end
186
186
 
187
187
  id[1]
188
- }
188
+ end
189
189
 
190
190
  [0, gids]
191
191
  }
192
192
  }
193
193
 
194
194
  GLOBAL = {
195
- :name => "global",
196
- :large => "--global" ,
197
- :description => "Find a global Token."
195
+ :name => 'global',
196
+ :large => '--global',
197
+ :description => 'Find a global Token.'
198
198
  }
199
199
 
200
200
  STDIN_PASSWORD = {
201
- :name => "stdin_password",
202
- :large => "--stdin_password",
203
- :description => "enable stdin password"
201
+ :name => 'stdin_password',
202
+ :large => '--stdin_password',
203
+ :description => 'enable stdin password'
204
204
  }
205
205
 
206
206
  auth_options = [READ_FILE, SHA1, SSH, X509, KEY, CERT, DRIVER]
@@ -223,8 +223,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
223
223
  ########################################################################
224
224
  # Formatters for arguments
225
225
  ########################################################################
226
- set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
227
- OpenNebulaHelper.rname_to_id(arg, "GROUP")
226
+ set :format, :groupid, OpenNebulaHelper.rname_to_id_desc('GROUP') do |arg|
227
+ OpenNebulaHelper.rname_to_id(arg, 'GROUP')
228
228
  end
229
229
 
230
230
  set :format, :userid, OneUserHelper.to_id_desc do |arg|
@@ -255,15 +255,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
255
255
  EOT
256
256
 
257
257
  command :create, create_desc, :username, [:password, nil],
258
- :options=>create_options do
258
+ :options => create_options do
259
259
  if args[1]
260
260
  pass = args[1]
261
261
  else
262
262
  rc = helper.password(options)
263
- if rc.first == 0
263
+ if rc.first.zero?
264
264
  pass = rc[1]
265
265
  else
266
- exit_with_code *rc
266
+ exit_with_code(*rc)
267
267
  end
268
268
  end
269
269
 
@@ -282,8 +282,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
282
282
  EOT
283
283
 
284
284
  command :update, update_desc, :userid, [:file, nil],
285
- :options=>OpenNebulaHelper::APPEND do
286
- helper.perform_action(args[0],options,"modified") do |obj|
285
+ :options => OpenNebulaHelper::APPEND do
286
+ helper.perform_action(args[0], options, 'modified') do |obj|
287
287
  if options[:append]
288
288
  str = OpenNebulaHelper.append_template(args[0], obj, args[1])
289
289
  else
@@ -303,12 +303,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do
303
303
  EOT
304
304
 
305
305
  command :quota, quota_desc, :userid, [:file, nil] do
306
- helper.perform_action(args[0], options, "modified") do |user|
306
+ helper.perform_action(args[0], options, 'modified') do |user|
307
307
  rc = user.info
308
308
 
309
309
  if OpenNebula.is_error?(rc)
310
310
  puts rc.message
311
- exit -1
311
+ exit(-1)
312
312
  end
313
313
 
314
314
  str = OneQuotaHelper.set_quota(user, args[1])
@@ -316,11 +316,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
316
316
  helper.set_client(options)
317
317
  user = helper.retrieve_resource(user.id)
318
318
 
319
- rc = user.set_quota(str)
319
+ rc = user.set_quota(str)
320
320
 
321
321
  if OpenNebula.is_error?(rc)
322
322
  puts rc.message
323
- exit -1
323
+ exit(-1)
324
324
  end
325
325
  end
326
326
  end
@@ -334,8 +334,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
334
334
  [:file, nil] do
335
335
  batch_str = OneQuotaHelper.get_batch_quota(args[1])
336
336
 
337
- helper.set_client(options)
338
- helper.perform_actions(args[0], options, "modified") do |user|
337
+ helper.set_client(options)
338
+ helper.perform_actions(args[0], options, 'modified') do |user|
339
339
  str = OneQuotaHelper.merge_quota(user, batch_str)
340
340
 
341
341
  if OpenNebula.is_error?(str)
@@ -354,7 +354,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
354
354
  command :defaultquota, defaultquota_desc, [:file, nil] do
355
355
  system = System.new(OneUserHelper.get_client(options))
356
356
 
357
- default_quotas = system.get_user_quotas()
357
+ default_quotas = system.get_user_quotas
358
358
 
359
359
  if OpenNebula.is_error?(default_quotas)
360
360
  puts default_quotas.message
@@ -364,7 +364,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
364
364
  str = OneQuotaHelper.set_quota(default_quotas, args[0], true)
365
365
 
366
366
  system = System.new(OneUserHelper.get_client(options, true))
367
- rc = system.set_user_quotas(str)
367
+ rc = system.set_user_quotas(str)
368
368
 
369
369
  if OpenNebula.is_error?(rc)
370
370
  puts rc.message
@@ -385,21 +385,21 @@ cmd=CommandParser::CmdParser.new(ARGV) do
385
385
  EOT
386
386
 
387
387
  command :umask, umask_desc, [:range, :userid_list], [:mask, nil] do
388
- helper.perform_actions(args[0],options,
389
- "umask changed") do |user|
388
+ helper.perform_actions(args[0], options,
389
+ 'umask changed') do |user|
390
390
 
391
391
  rc = user.info
392
392
 
393
393
  if OpenNebula.is_error?(rc)
394
394
  puts rc.message
395
- exit -1
395
+ exit(-1)
396
396
  end
397
397
 
398
398
  user.delete_element('/USER/TEMPLATE/UMASK')
399
399
 
400
400
  tmp_str = user.template_str
401
401
 
402
- if !args[1].nil? && args[1] != ""
402
+ if !args[1].nil? && args[1] != ''
403
403
  tmp_str << "\nUMASK = #{args[1]}"
404
404
  end
405
405
 
@@ -411,7 +411,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
411
411
  Alias of token-create.
412
412
  EOT
413
413
 
414
- command :login, login_desc, [:username, nil], :options=>login_options do
414
+ command :login, login_desc, [:username, nil], :options => login_options do
415
415
  helper.token_create(args, options)
416
416
  end
417
417
 
@@ -420,15 +420,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
420
420
  for the SSH authentication mechanism.
421
421
  EOT
422
422
 
423
- command :key, key_desc, :options=>[KEY] do
423
+ command :key, key_desc, :options => [KEY] do
424
424
  require 'opennebula/ssh_auth'
425
425
 
426
- options[:key] ||= ENV['HOME']+'/.ssh/id_rsa'
426
+ options[:key] ||= ENV['HOME'] + '/.ssh/id_rsa'
427
427
 
428
428
  begin
429
- sshauth = SshAuth.new(:private_key=>options[:key])
430
- rescue Exception => e
431
- exit_with_code -1, e.message
429
+ sshauth = SshAuth.new(:private_key => options[:key])
430
+ rescue StandardError => e
431
+ exit_with_code(-1, e.message)
432
432
  end
433
433
 
434
434
  puts sshauth.password
@@ -440,7 +440,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
440
440
  EOT
441
441
 
442
442
  command :delete, delete_desc, [:range, :userid_list] do
443
- helper.perform_actions(args[0], options, "deleted") do |user|
443
+ helper.perform_actions(args[0], options, 'deleted') do |user|
444
444
  user.delete
445
445
  end
446
446
  end
@@ -450,19 +450,19 @@ cmd=CommandParser::CmdParser.new(ARGV) do
450
450
  EOT
451
451
 
452
452
  command :passwd, passwd_desc, [:userid], [:password, nil],
453
- :options=>auth_options do
453
+ :options => auth_options do
454
454
  if args[1]
455
455
  pass = args[1]
456
456
  else
457
457
  rc = helper.password(options)
458
- if rc.first == 0
458
+ if rc.first.zero?
459
459
  pass = rc[1]
460
460
  else
461
- exit_with_code *rc
461
+ exit_with_code(*rc)
462
462
  end
463
463
  end
464
464
 
465
- helper.perform_action(args[0],options,"Password changed") do |user|
465
+ helper.perform_action(args[0], options, 'Password changed') do |user|
466
466
  user.passwd(pass)
467
467
  end
468
468
  end
@@ -472,7 +472,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
472
472
  EOT
473
473
 
474
474
  command :chgrp, chgrp_desc, [:range, :userid_list], :groupid do
475
- helper.perform_actions(args[0],options,"Group changed") do |user|
475
+ helper.perform_actions(args[0], options, 'Group changed') do |user|
476
476
  user.chgrp(args[1].to_i)
477
477
  end
478
478
  end
@@ -484,8 +484,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
484
484
  command :addgroup, addgroup_desc, [:range, :userid_list], :groupid do
485
485
  gid = args[1]
486
486
 
487
- helper.perform_actions(args[0],options,"group added") do |user|
488
- user.addgroup( gid )
487
+ helper.perform_actions(args[0], options, 'group added') do |user|
488
+ user.addgroup(gid)
489
489
  end
490
490
  end
491
491
 
@@ -496,8 +496,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
496
496
  command :delgroup, delgroup_desc, [:range, :userid_list], :groupid do
497
497
  gid = args[1]
498
498
 
499
- helper.perform_actions(args[0],options,"group deleted") do |user|
500
- user.delgroup( gid )
499
+ helper.perform_actions(args[0], options, 'group deleted') do |user|
500
+ user.delgroup(gid)
501
501
  end
502
502
  end
503
503
 
@@ -513,29 +513,29 @@ cmd=CommandParser::CmdParser.new(ARGV) do
513
513
  EOT
514
514
 
515
515
  command :chauth, chauth_desc, :userid, [:auth, nil], [:password, nil],
516
- :options=>auth_options do
516
+ :options => auth_options do
517
517
  if options[:driver]
518
518
  driver = options[:driver]
519
519
  elsif args[1]
520
520
  driver = args[1]
521
521
  else
522
- exit_with_code 0, "An Auth driver should be specified"
522
+ exit_with_code 0, 'An Auth driver should be specified'
523
523
  end
524
524
 
525
525
  if args[2]
526
526
  pass = args[2]
527
527
  else
528
528
  rc = helper.password(options)
529
- if rc.first == 0
529
+ if rc.first.zero?
530
530
  pass = rc[1]
531
531
  else
532
- pass = ""
532
+ pass = ''
533
533
  end
534
534
  end
535
535
 
536
536
  helper.perform_action(args[0],
537
- options,
538
- "Auth driver and password changed") do |user|
537
+ options,
538
+ 'Auth driver and password changed') do |user|
539
539
  user.chauth(driver, pass)
540
540
  end
541
541
  end
@@ -544,7 +544,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
544
544
  Lists Users in the pool
545
545
  EOT
546
546
 
547
- command :list, list_desc, :options=>list_options do
547
+ command :list, list_desc, :options => list_options do
548
548
  helper.list_pool(options)
549
549
  end
550
550
 
@@ -553,9 +553,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
553
553
  EOT
554
554
 
555
555
  command :show, show_desc, [:userid, nil],
556
- :options=>OpenNebulaHelper::XML do
557
- user=args[0] || OpenNebula::User::SELF
558
- helper.show_resource(user,options)
556
+ :options => OpenNebulaHelper::XML do
557
+ user = args[0] || OpenNebula::User::SELF
558
+ helper.show_resource(user, options)
559
559
  end
560
560
 
561
561
  show_desc = <<-EOT.unindent
@@ -563,15 +563,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
563
563
  EOT
564
564
 
565
565
  command :encode, show_desc, :username, [:password, nil] do
566
- ar=args.compact
566
+ ar = args.compact
567
567
 
568
568
  if defined?(URI::Parser)
569
- parser=URI::Parser.new
569
+ parser = URI::DEFAULT_PARSER
570
570
  else
571
- parser=URI
571
+ parser = URI
572
572
  end
573
573
 
574
- puts ar.map{|a| parser.escape(a) }.join(':')
574
+ puts ar.map {|a| parser.escape(a) }.join(':')
575
575
 
576
576
  0
577
577
  end
@@ -582,9 +582,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do
582
582
  EOT
583
583
 
584
584
  command :passwdsearch, passwdsearch_desc, :driver, :password,
585
- :options=>[CLIHelper::CSV_OPT, OpenNebulaHelper::XML] do
585
+ :options => [CLIHelper::CSV_OPT, OpenNebulaHelper::XML] do
586
586
 
587
- options[:list] = ["ID", "NAME", "AUTH", "PASSWORD"]
587
+ options[:list] = %w[ID NAME AUTH PASSWORD]
588
588
  options[:filter] = ["AUTH=#{args[0]}", "PASSWORD=#{args[1]}"]
589
589
 
590
590
  helper.list_pool(options)
@@ -618,7 +618,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
618
618
  EOT
619
619
 
620
620
  command :"token-create", token_add_desc, [:username, nil],
621
- :options=>login_options do
621
+ :options => login_options do
622
622
 
623
623
  helper.token_create(args, options)
624
624
  end
@@ -648,13 +648,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
648
648
  EOT
649
649
 
650
650
  command :"token-set", token_set_desc, [:username, nil],
651
- :options=>login_options+set_options do
651
+ :options => login_options + set_options do
652
652
 
653
653
  username = args[0]
654
654
 
655
655
  if username
656
656
  if username =~ /^\d+$/
657
- exit_with_code 1, "The argument should be the username, not the ID."
657
+ exit_with_code(
658
+ 1,
659
+ 'The argument should be the username, not the ID.'
660
+ )
658
661
  end
659
662
 
660
663
  helper.client = helper.get_login_client(username, options)
@@ -679,14 +682,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
679
682
  token_hint = nil
680
683
  group = -1
681
684
  else
682
- exit_with_code 1, "One of these options must be supplied:\n" <<
683
- "[--token <token>] [--group <id|group>] [--global]"
685
+ exit_with_code(
686
+ 1,
687
+ "One of these options must be supplied:\n" \
688
+ '[--token <token>] [--group <id|group>] [--global]'
689
+ )
684
690
  end
685
691
 
686
692
  tokens = helper.find_token(user, token_hint, group, false)
687
693
 
688
- if tokens.length == 0
689
- exit_with_code 1, "No valid tokens found."
694
+ if tokens.length.zero?
695
+ exit_with_code 1, 'No valid tokens found.'
690
696
  end
691
697
 
692
698
  if token_hint && tokens.length > 1
@@ -694,25 +700,27 @@ cmd=CommandParser::CmdParser.new(ARGV) do
694
700
  exit_with_code 1, msg
695
701
  end
696
702
 
697
- token = tokens[0]["TOKEN"]
703
+ token = tokens[0]['TOKEN']
698
704
 
699
705
  egid = user["LOGIN_TOKEN[TOKEN='#{token}']/EGID"]
700
706
 
701
707
  auth_string = "#{user['NAME']}:#{token}"
702
708
  auth_file = helper.auth_file(auth_string)
703
709
 
710
+ # rubocop:disable HandleExceptions
704
711
  begin
705
712
  FileUtils.mkdir_p(File.dirname(auth_file))
706
713
  rescue Errno::EEXIST
707
714
  end
715
+ # rubocop:enable HandleExceptions
708
716
 
709
- file = File.open(auth_file, "w")
717
+ file = File.open(auth_file, 'w')
710
718
  file.write(auth_string)
711
719
  file.close
712
720
 
713
- File.chmod(0600, auth_file)
721
+ File.chmod(0o0600, auth_file)
714
722
 
715
- msg ="export ONE_AUTH=" + auth_file
723
+ msg = 'export ONE_AUTH=' + auth_file
716
724
  msg << "; export ONE_EGID=#{egid}" if egid
717
725
 
718
726
  exit_with_code 0, msg
@@ -723,7 +731,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
723
731
  EOT
724
732
 
725
733
  command :"token-delete", token_delete_desc, [:username, nil], :token,
726
- :options=>login_options do
734
+ :options => login_options do
727
735
 
728
736
  if args.length == 1
729
737
  token_hint = args[0]
@@ -746,12 +754,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
746
754
  token = helper.find_token(user, token_hint, nil, true)
747
755
 
748
756
  if token.count > 1
749
- exit_with_code 1, "More than one token starting with '#{token_hint}' found."
750
- elsif token.count == 0
751
- exit_with_code 1, "No tokens found."
757
+ exit_with_code(
758
+ 1,
759
+ "More than one token starting with '#{token_hint}' found."
760
+ )
761
+ elsif token.count.zero?
762
+ exit_with_code 1, 'No tokens found.'
752
763
  end
753
764
 
754
- token = token[0]["TOKEN"]
765
+ token = token[0]['TOKEN']
755
766
 
756
767
  rc = user.login(user['NAME'], token, 0)
757
768
 
@@ -759,17 +770,19 @@ cmd=CommandParser::CmdParser.new(ARGV) do
759
770
  puts rc.message
760
771
  exit_with_code 1, rc.message
761
772
  else
762
- puts "Token removed."
773
+ puts 'Token removed.'
763
774
  end
764
775
 
765
776
  auth_string = "#{user['NAME']}:#{token}"
766
777
  auth_file = helper.auth_file(auth_string)
767
778
 
779
+ # rubocop:disable HandleExceptions
768
780
  begin
769
781
  File.unlink(auth_file)
770
782
  puts "Removing #{auth_file}"
771
783
  rescue Errno::ENOENT
772
784
  end
785
+ # rubocop:enable HandleExceptions
773
786
 
774
787
  0
775
788
  end
@@ -780,16 +793,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
780
793
  EOT
781
794
 
782
795
  command :"token-delete-all", token_delete_all, :username,
783
- :options=>login_options do
796
+ :options => login_options do
784
797
 
785
798
  username = args[0]
786
799
 
787
800
  if username =~ /^\d+$/
788
- exit_with_code 1, "The argument should be the username, not the ID."
801
+ exit_with_code 1, 'The argument should be the username, not the ID.'
789
802
  end
790
803
 
791
- helper.perform_action(username, options, "Tokens expired") do |user|
792
- user.login(username, "", 0)
804
+ helper.perform_action(username, options, 'Tokens expired') do |user|
805
+ user.login(username, '', 0)
793
806
  end
794
807
  end
795
808
  end