lmcadm 0.12.0 → 0.16.0

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: 77cf9b8cd93328770c7b0c0972ccd1dc3883caba497eee0f97ed26bbe5976680
4
- data.tar.gz: cd5023a45af514136f7d82162e07e9901016aebd01f1ccf9762dfb530e609ac9
3
+ metadata.gz: 2fa137bc6b37c1d4b8ad21a83b634fb19fd6403dcff6b23005da7a467aab9d70
4
+ data.tar.gz: 8a5f93e98b4f8248c9395e6a5980ae8c3ebc738dd45518295e781d165a0e715c
5
5
  SHA512:
6
- metadata.gz: b29cf69f6ff585537667174b14164f3dfdad88016ef724242e4dcbc7876a22b75a17953d3860b50d36dc7a49295797127215fca6572bd7f1dda3920185190926
7
- data.tar.gz: 5d0a07f656a6bb3c0c1dc7b9b410c340f2256294ac14fdece08cd417c4979b9742eb064dfefd48aaeef7b0604e7f0a935431fe396d7481321c74b4ba23b34fe3
6
+ metadata.gz: 67a59f6513b13f9619c28b7319ebc5902d53bcae865570681be86b6842cf3155021850f3b6d32973c9eeb23bf66316c0d1954ac54e389883d1eb8e9b7a8316b4
7
+ data.tar.gz: 226c8ee80ed5519c3009fa8415abfbb0d9e5a566e52d44abb4ec6c112c48951647c4135e2fe68f521e9352b811b9521b98920c6fac6a93c33d2a1cf103e7c970
data/README.md CHANGED
@@ -8,6 +8,12 @@ Install via rubygems:
8
8
 
9
9
  $ gem install lmcadm
10
10
 
11
+ ### Requirements
12
+ Building native extensions for certain dependencies require ruby headers or source code to be present.
13
+ These can usually be installed the same way ruby was installed.
14
+
15
+ On Ubuntu for example, installing the `ruby-dev` via the package manager is sufficient.
16
+
11
17
  ## Usage
12
18
 
13
19
  The primary usage documentation is in the help output of lmcadm:
data/Rakefile CHANGED
@@ -1,10 +1,15 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
+ require 'rdoc/task'
3
4
 
4
5
  Rake::TestTask.new(:test) do |t|
5
6
  t.libs << "test"
6
7
  t.libs << "lib"
7
8
  t.test_files = FileList["test/**/*_test.rb"]
8
9
  end
9
-
10
+ RDoc::Task.new do |rdoc|
11
+ rdoc.rdoc_dir = 'doc'
12
+ #rdoc.main = "README.rdoc"
13
+ #rdoc.rdoc_files.include("lib/lmcadm/helpers/args_helpers.rb")
14
+ end
10
15
  task :default => :test
data/dev_lmcadm ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ #wrapper script
3
+ #set -x
4
+ LMCADM_PATH_DEP=1 GLI_DEBUG=false bundle exec exe/lmcadm "$@"
data/exe/lmcadm CHANGED
@@ -25,7 +25,7 @@ module LMCAdm
25
25
  commands_from "lmcadm/commands"
26
26
 
27
27
  desc 'Be verbose'
28
- switch [:v, :verbose]
28
+ switch :verbose, :v
29
29
 
30
30
  desc 'debug'
31
31
  switch [:debug]
@@ -33,9 +33,9 @@ module LMCAdm
33
33
  desc 'Measure time taken for operations'
34
34
  switch "take-time"
35
35
 
36
- desc 'cloud host'
36
+ desc 'LMC host, may include a port number'
37
37
  default_value "cloud.lancom.de"
38
- flag :C, :cloud_host
38
+ flag :cloud_host, :C
39
39
 
40
40
  desc 'Use encrypted connection'
41
41
  default_value true
@@ -46,13 +46,16 @@ module LMCAdm
46
46
  switch "verify-tls"
47
47
 
48
48
  desc 'username'
49
- default_value "admin"
50
- flag :U, :user
49
+ default_value ""
50
+ flag :user, :U
51
51
 
52
52
  desc 'password'
53
53
  default_value ""
54
- flag [:P, :password], :mask => true
54
+ flag [:password, :P], :mask => true
55
55
 
56
+ desc 'Use 2FA code'
57
+ default_value false
58
+ switch [:code, 'F']
56
59
 
57
60
  pre do |global, command, options, args|
58
61
  # Pre logic here
@@ -60,17 +63,31 @@ module LMCAdm
60
63
  # chosen command
61
64
  # Use skips_pre before a command to skip this block
62
65
  # on that command only
63
- if command.name != :completion && global[:password] == ""
64
- global[:password] = Helpers::read_pw "Enter password for #{global[:user]}:"
66
+ if command.name != :completion
67
+ if global[:user] == ""
68
+ print "Enter user:"
69
+ global[:user] = STDIN.gets.chomp
70
+ end
71
+ if global[:password] == ""
72
+ global[:password] = Helpers::read_pw "Enter password for #{global[:user]}:"
73
+ end
74
+ twofactor_code = nil
75
+ if global[:code]
76
+ twofactor_code = Helpers::read_pw "Enter 2FA code:"
77
+ end
65
78
  end
66
79
  ::LMC::Cloud.cloud_host = global[:cloud_host]
67
80
  ::LMC::Cloud.user = global[:user]
68
81
  ::LMC::Cloud.password = global[:password]
82
+ ::LMC::Cloud.code = twofactor_code
69
83
  ::LMC::Cloud.verbose = global[:verbose]
70
84
  ::LMC::Cloud.debug = global[:debug]
71
85
  ::LMC::Cloud.verify_tls = global["verify-tls"]
72
86
  ::LMC::Cloud.use_tls = global["use-tls"]
73
87
  LMCAdm::ProgressVisualizer.take_time = global["take-time"]
88
+ # let table_print print wide columns
89
+ tp.set :max_width, 50
90
+
74
91
  true
75
92
  end
76
93
 
data/lib/lmcadm.rb CHANGED
@@ -1,7 +1,3 @@
1
- #require "lmcadm/version"
2
- #require 'lmcadm/account_commands'
3
- #require 'lmcadm/test_command_container'
4
-
5
1
  Dir.glob(File.expand_path("../lmcadm/*.rb", __FILE__)).each do |file|
6
2
  require file
7
3
  end
@@ -16,7 +16,7 @@ module LMCAdm
16
16
  account_list.switch :l, :long
17
17
  account_list.action do |global_options, options, args|
18
18
  t = ProgressVisualizer.new "Cloud login"
19
- lmcen = LMC::Cloud.new(global_options[:cloud_host], global_options[:user], global_options[:password])
19
+ lmcen = LMC::Cloud.instance
20
20
  t.done
21
21
  t = ProgressVisualizer.new "Getting accounts"
22
22
  accounts = lmcen.get_accounts_objects
@@ -26,12 +26,12 @@ module LMCAdm
26
26
  a["type"] == options[:account_type]
27
27
  end
28
28
  end
29
- accounts.sort {|a, b| a["name"] <=> b["name"]}.each do |account|
29
+ accounts.sort { |a, b| a["name"] <=> b["name"] }.each do |account|
30
30
  puts account.inspect if global_options[:v]
31
31
  if options[:l]
32
- puts account["name"] + " (" + account["type"] + ") ID: " + account["id"]
32
+ puts account.summary
33
33
  else
34
- puts account["name"] + " (" + account["type"] + ")"
34
+ puts "\"#{account}\" (#{account["type"]})"
35
35
  end
36
36
  end
37
37
  puts accounts.length.to_s + " Accounts found"
@@ -82,9 +82,9 @@ module LMCAdm
82
82
  account_create.action do |global_options, options, args|
83
83
  parent = LMC::Account.get_by_uuid_or_name options[:p]
84
84
  t = ProgressVisualizer.new "Creating object"
85
- a = LMC::Account.new(LMC::Cloud.instance, {"name" => args.first,
86
- "type" => options[GLI::Command::PARENT][:account_type],
87
- "parent" => parent.id})
85
+ a = LMC::Account.new(LMC::Cloud.instance, { "name" => args.first,
86
+ "type" => options[GLI::Command::PARENT][:account_type],
87
+ "parent" => parent.id })
88
88
  t.done
89
89
  t = ProgressVisualizer.new "Saving #{a.name}"
90
90
  result = a.save
@@ -106,13 +106,13 @@ module LMCAdm
106
106
  t = ProgressVisualizer.new "Getting accounts"
107
107
  if options[:e]
108
108
  accounts = LMC::Cloud.instance.get_accounts_objects
109
- matched_accounts = accounts.select {|account| /#{args.first}/.match(account.name)}
109
+ matched_accounts = accounts.select { |account| /#{args.first}/.match(account.name) }
110
110
  else
111
111
  matched_accounts = [LMC::Account.get_by_uuid_or_name(args.first)]
112
112
  end
113
113
  t.done
114
114
  puts 'Accounts to delete:'
115
- puts matched_accounts.map {|a| "#{a.id} - #{a.name}"}.join("\n")
115
+ puts matched_accounts.map { |a| "#{a.id} - #{a.name}" }.join("\n")
116
116
  print('Type yes to confirm: ')
117
117
  exit unless STDIN.gets.chomp == 'yes'
118
118
  t = ProgressVisualizer.new "Deleting accounts"
@@ -159,12 +159,12 @@ module LMCAdm
159
159
  memberlist.action do |global_options, options, args|
160
160
  account = LMC::Account.get_by_uuid_or_name args.first
161
161
  members = account.members
162
- tp members, [{:id => {:width => 36}}, :name, :type, :state, :invitationState, :principalState,
163
- :authorities => {:display_method => lambda {|m|
164
- m.authorities.map {|a|
162
+ tp members, [{ :id => { :width => 36 } }, :name, :type, :state, :invitationState, :principalState,
163
+ :authorities => { :display_method => lambda { |m|
164
+ m.authorities.map { |a|
165
165
  a['name']
166
166
  }.join(',')
167
- }, :width => 128}]
167
+ }, :width => 128 }]
168
168
  end
169
169
  end
170
170
 
@@ -174,8 +174,8 @@ module LMCAdm
174
174
  auth.action do |_g, _o, args|
175
175
  account = LMC::Account.get_by_uuid_or_name args.first
176
176
  authorities = account.authorities
177
- max = Helpers::longest_in_collection(authorities.map {|a| a.name})
178
- tp authorities, [{:id => {:width => 36}}, {:name => {:width => max}}, :visibility, :type]
177
+ max = Helpers::longest_in_collection(authorities.map { |a| a.name })
178
+ tp authorities, [{ :id => { :width => 36 } }, { :name => { :width => max } }, :visibility, :type]
179
179
  end
180
180
  end
181
181
 
@@ -187,7 +187,7 @@ module LMCAdm
187
187
  create.flag :A, :required => true
188
188
  create.action do |_global_options, options, _args|
189
189
  account = LMC::Account.get_by_uuid_or_name options[:A]
190
- auth = LMC::Authority.new({'name' => _args.first, 'visibility' => 'PRIVATE'}, account)
190
+ auth = LMC::Authority.new({ 'name' => _args.first, 'visibility' => 'PRIVATE' }, account)
191
191
  puts auth.save
192
192
  end
193
193
  end
@@ -202,7 +202,7 @@ module LMCAdm
202
202
  account_invite.action do |global_options, options, args|
203
203
  account = LMC::Account.get_by_uuid_or_name options[:account]
204
204
  cloud = LMC::Cloud.instance
205
- chosen_authorities = account.authorities.select {|auth| auth.name == options[:role]}
205
+ chosen_authorities = account.authorities.select { |auth| auth.name == options[:role] }
206
206
  args.each do |email|
207
207
  cloud.invite_user_to_account email, account.id, options[:type], chosen_authorities
208
208
  end
@@ -256,28 +256,40 @@ module LMCAdm
256
256
  update.flag :A, :account, :required => true
257
257
  update.desc 'authority id'
258
258
  update.flag 'add-authority'
259
- update.action do |_global_options, options, args|
259
+ update.desc 'authority name|id'
260
+ update.flag 'remove-authority'
261
+ update.action do |global_options, options, args|
260
262
  account = LMC::Account.get_by_uuid_or_name(options[:account])
263
+ account.cloud.auth_for_account account
261
264
  membership = account.find_member_by_name args.first
262
- puts membership
265
+ puts "membership class: #{membership.class}"
266
+ puts "membership.authorities first class: #{membership.authorities.first.class}"
267
+
268
+ #real_membership = LMC::Membership.new membership
269
+ #puts real_membership.inspect
270
+
271
+
272
+ puts membership if global_options[:verbose]
273
+ authority_ids = membership.authorities.map do |a|
274
+ a.id
275
+ end
276
+ puts "Existing authority ids: #{authority_ids}"
263
277
  if options['add-authority']
264
- # new_authority = account.authorities.find do |a|
265
- # a.name == options['add-authority']
266
- # end
267
- puts membership.class
268
- puts membership.authorities.class
269
- authority_ids = membership.authorities.map do |a|
270
- a['id']
271
- end
272
- puts authority_ids
273
- authority_ids = authority_ids.concat [options['add-authority']]
274
- puts authority_ids
275
- # POST /accounts/{accountId}/members/{principalId}
276
- cloud = LMC::Cloud.instance
277
- cloud.auth_for_account account
278
- res = cloud.post ['cloud-service-auth', 'accounts', account.id, 'members', membership.id], {'authorities' => authority_ids}
279
- puts res
278
+ add_str = options['add-authority']
279
+ new_authority = Helpers::find_by_id_or_name membership.authorities, add_str
280
+ authority_ids = authority_ids.concat [new_authority.id]
281
+ puts "Adding #{authority_ids}"
282
+ end
283
+ if options['remove-authority']
284
+ remove_str = options['remove-authority']
285
+ deleting_authority = Helpers.find_by_id_or_name account.authorities, remove_str
286
+ puts "Removing #{deleting_authority}"
287
+ authority_ids = authority_ids - [deleting_authority.id]
280
288
  end
289
+ puts "New authority ids: #{authority_ids}"
290
+ # POST /accounts/{accountId}/members/{principalId}
291
+ res = account.cloud.post ['cloud-service-auth', 'accounts', account.id, 'members', membership.id], { 'authorities' => authority_ids }
292
+ puts res
281
293
  end
282
294
  end
283
295
 
@@ -288,16 +300,12 @@ module LMCAdm
288
300
  children.flag :special
289
301
  children.action do |global_options, options, args|
290
302
  account = LMC::Account.get_by_uuid_or_name args.first
291
- cloud = LMC::Cloud.instance
292
303
 
293
304
  def recurse_childen account, indent_level
294
305
  children = account.children
295
306
  children.each do |child|
296
307
  puts ' ' * indent_level + child.to_s
297
- begin
298
- recurse_childen child, indent_level + 1
299
- rescue RestClient::Forbidden => e
300
- end
308
+ recurse_childen child, indent_level + 1
301
309
  end
302
310
  end
303
311
 
@@ -8,13 +8,15 @@ module LMCAdm
8
8
  command :cloud do |c|
9
9
  c.desc 'Check cloud connectivity'
10
10
  c.action do |global_options|
11
- lmcen = LMC::Cloud.new(global_options[:cloud_host], global_options[:user], global_options[:password])
11
+ lmcen = LMC::Cloud.instance
12
12
  puts "Base URL: #{lmcen.build_url}"
13
13
  puts "Cloud connection OK" if lmcen.auth_ok
14
14
  if global_options[:v]
15
15
  puts "authentication token: " + lmcen.session_token
16
16
  end
17
17
  end
18
+
19
+ c.desc 'Display cloud version information'
18
20
  c.command :about do |cloud_about|
19
21
  cloud_about.action do |global_options|
20
22
  cloud = LMC::Cloud.instance
@@ -27,6 +29,7 @@ module LMCAdm
27
29
  }}
28
30
  tp backstage_infos
29
31
  puts '---'
32
+ puts "Base URL: #{cloud.build_url}"
30
33
  puts "Principal: #{LMC::Principal.get_self(cloud)}"
31
34
 
32
35
  end
@@ -7,7 +7,7 @@ module LMCAdm
7
7
  root_account = LMC::Account.get LMC::Account::ROOT_ACCOUNT_UUID
8
8
  cloud = LMC::Cloud.instance
9
9
  cloud.auth_for_account root_account
10
- result = cloud.post ['cloud-service-devices', 'maintenance', 'licenses', 'resync'], { 'accountId' => args[0] }
10
+ result = cloud.post ['cloud-service-devices', 'maintenance', 'licenses', 'resync'], {'accountId' => args[0]}
11
11
  end
12
12
  end
13
13
 
@@ -33,10 +33,11 @@ module LMCAdm
33
33
  end
34
34
  end
35
35
 
36
- maintenance.arg_name 'UUID', required: true
36
+ maintenance.arg_name 'UUID'
37
37
  maintenance.desc 'Exempt user from brute force blocking'
38
38
  maintenance.command :whitelist do |wl|
39
39
  wl.action do |_g, _o, args|
40
+ Helpers.ensure_arg args, kind: 'user uuid'
40
41
  cloud = LMC::Cloud.instance
41
42
  root_account = LMC::Account.get LMC::Account::ROOT_ACCOUNT_UUID
42
43
  cloud.auth_for_account root_account
@@ -45,5 +46,20 @@ module LMCAdm
45
46
  cloud.post url_components, {}
46
47
  end
47
48
  end
49
+
50
+ maintenance.arg_name 'UUID', required: true
51
+ maintenance.desc 'Remove entity from blacklist'
52
+ maintenance.command :unblacklist do |unbl|
53
+ unbl.flag 'entity-type', :t, desc: 'Entity type. Choose "principals" or "accounts".', required: true
54
+ unbl.flag 'process-type', :p, desc: 'Process type', default_value: 'CLAIMING'
55
+ unbl.action do |_g, o, args|
56
+ Helpers.ensure_arg args, kind: 'entity uuid'
57
+ cloud = LMC::Cloud.instance
58
+ root_account = LMC::Account.get LMC::Account::ROOT_ACCOUNT_UUID
59
+ cloud.auth_for_account root_account
60
+ url_components = ['cloud-service-devices', 'accesscontrol', o['process-type'], o['entity-type'], args.first]
61
+ cloud.delete url_components
62
+ end
63
+ end
48
64
  end
49
65
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LMCAdm #:nodoc:
4
+ desc 'Manipulate preferences'
5
+ command :preferences do |preferences|
6
+ preferences.desc 'Get last account data'
7
+ preferences.arg_name 'accounts'
8
+ preferences.command :lastaccounts do |la|
9
+ la.action do |g, _o, args|
10
+ cloud = LMC::Cloud.instance
11
+ self_ui = cloud.preferences [:principals, :self, :ui]
12
+ if args.empty?
13
+ ids = self_ui.get 'lastAccountIds'
14
+ accounts = ids.map do |id|
15
+ LMC::Account.get id
16
+ end
17
+ accounts.each { |a|
18
+ puts a.summary
19
+ }
20
+ else
21
+ account_ids = args.map { |arg|
22
+ LMC::Account.get_by_uuid_or_name(arg).id
23
+ }
24
+ puts account_ids
25
+ puts self_ui.put 'lastAccountIds', account_ids
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -15,7 +15,7 @@ module LMCAdm
15
15
  end
16
16
  rights.arg_name "rights"
17
17
  rights.command :assign do |assign|
18
- assign.flag :A
18
+ assign.flag :A, :account
19
19
  assign.flag :authority
20
20
  assign.flag :service
21
21
  assign.action do |_g, o, a |
@@ -23,9 +23,34 @@ module LMCAdm
23
23
  account = LMC::Account.get_by_uuid_or_name o[:A]
24
24
  c = LMC::Cloud.instance
25
25
  c.auth_for_account account
26
- c.post [o[:service], "accounts", account.id, 'authorities', o[:authority], 'rights' ], a
26
+ service_name = Helpers.complete_service_name o[:service]
27
+ c.post [service_name, "accounts", account.id, 'authorities', o[:authority], 'rights' ], a
27
28
 
28
29
  end
29
30
  end
31
+ rights.arg_name 'servicename account'
32
+ rights.desc 'example: lmcadm rights authorities messaging myproject'
33
+ rights.command :authorities do |authorities|
34
+ authorities.action do |_g, _o, a |
35
+ account = LMC::Account.get_by_uuid_or_name a[1]
36
+ account.cloud.auth_for_account account
37
+ authorities = account.cloud.get [Helpers.complete_service_name(a[0]), 'accounts', account.id, 'authorities']
38
+ tp authorities.body, [:name , :visibility, :type, :id]
39
+ end
40
+ end
41
+
42
+ rights.arg_name '<servicename> <account> <authority_id>'
43
+ rights.desc 'example: lmcadm rights show service-messaging myproject 5c244078-c937-4ff9-bb33-351f5253fe53'
44
+ rights.command :show do |show|
45
+ show.action do |_g, _o, a|
46
+ account = LMC::Account.get_by_uuid_or_name a[1]
47
+ account.cloud.auth_for_account account
48
+ service_name = Helpers.complete_service_name a[0]
49
+ authority = account.cloud.get([service_name, 'accounts', account.id, 'authorities', a[2]]).body
50
+ puts authority.to_h.to_s
51
+ rights = account.cloud.get([service_name, 'accounts', account.id, 'authorities', a[2], 'rights']).body
52
+ puts rights
53
+ end
54
+ end
30
55
  end
31
56
  end
@@ -30,7 +30,7 @@ module LMCAdm
30
30
 
31
31
  t.action do |g, o, args|
32
32
  account = LMC::Account.get_by_uuid_or_name o[:account]
33
- device = account.devices.find { |d| d.name == args.first }
33
+ device = Helpers::find_device account.devices, name: args.first, id: args.first
34
34
  account.cloud.auth_for_account account
35
35
  payload = {type: 'TERMINAL',
36
36
  deviceIds: [device.id]}
@@ -50,28 +50,36 @@ module LMCAdm
50
50
  begin
51
51
  EventMachine.epoll
52
52
  EventMachine.run do
53
- trap("TERM") { stop g[:debug]}
54
- trap("INT") { stop g[:debug]}
53
+ trap("TERM") { stop g[:debug] }
54
+ trap("INT") { stop g[:debug] }
55
55
  IO.console.raw!
56
56
  EventMachine.open_keyboard(LMCAdm::KeyboardHandler)
57
57
  @ws = WebSocket::EventMachine::Client.connect({uri: url, headers: headers_hash})
58
58
  closing = false
59
59
 
60
60
  @ws.onopen do
61
- puts "Connected"
61
+ print "Connected to #{device.name} (#{device.id}):\r\n"
62
+ remaining_args = args.drop(1)
63
+ if remaining_args.length > 0
64
+ @ws.send '1' + remaining_args.join(' ') + "\r", type: 'binary'
65
+ end
62
66
  end
63
67
 
64
68
  @ws.onmessage do |msg, type|
65
69
  print "##{msg.length}##{msg.inspect}#" if g[:debug]
70
+ # respond to custom keepalive
71
+ if msg.start_with? '0'
72
+ @ws.send '0', type: 'binary'
73
+ end
66
74
  if msg.start_with? "1"
67
- print msg[1..-1].gsub("\n","\r\n")
75
+ print msg[1..-1].gsub("\n", "\r\n")
68
76
  else
69
77
  print msg if g[:debug]
70
78
  end
71
79
  print DateTime.now.to_s if g[:debug]
72
80
  if msg.include? "\n\nGoodbye\n\n"
73
81
  stop g[:debug]
74
- closing = true
82
+ closing = true
75
83
  end
76
84
  end
77
85
 
@@ -93,7 +101,7 @@ module LMCAdm
93
101
  puts "Received pong: #{msg}" if g[:verbose]
94
102
  end
95
103
 
96
- def stop(debug=false)
104
+ def stop(debug = false)
97
105
  print DateTime.now.to_s if debug
98
106
  print "Terminating connection\r\n"
99
107
  EventMachine.stop
@@ -102,9 +110,9 @@ module LMCAdm
102
110
  ensure
103
111
  IO.console.cooked!
104
112
  end
105
- # disabled, getting 401 anyways
106
- #account.cloud.auth_for_account account
107
- #account.cloud.delete ['cloud-service-devicetunnel', 'accounts', account.id, "terminal?ids=#{sessionInfo.body.first['id']}"]
113
+ # disabled, getting 401 anyways
114
+ #account.cloud.auth_for_account account
115
+ #account.cloud.delete ['cloud-service-devicetunnel', 'accounts', account.id, "terminal?ids=#{sessionInfo.body.first['id']}"]
108
116
  end
109
117
  end
110
118
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ module LMCAdm
3
+ module Helpers
4
+ # Verifies that args contains at least one object.
5
+ # Raises RuntimeError with either the given message or an error explaining that kind is expected.
6
+ #
7
+ # @param [Object] args
8
+ # @param [String (frozen)] kind optional
9
+ # @param [Object] message optional
10
+ def self.ensure_arg(args, kind: 'argument', message: nil)
11
+ error = ""
12
+ if args.length < 1
13
+ error = "Argument missing: No #{kind} specified."
14
+ error = message if message
15
+ end
16
+ raise error unless error.empty?
17
+ return args
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module LMCAdm
3
+ module Helpers
4
+ def self.find_device(devices, name: '', id: '')
5
+ found = devices.select do |device|
6
+ (id == device.id) || (name == device.name)
7
+ end
8
+ raise "More than one device found for: #{name} #{id}" if found.length > 1
9
+ raise "Device not found: #{name} #{id}" if found.length < 1
10
+ return found.first
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ module LMCAdm
3
+ module Helpers
4
+ def self.find_by_id_or_name(list, search)
5
+ found = []
6
+ found += list.select do |item|
7
+ item.id == search
8
+ end
9
+ found += list.select do |item|
10
+ item.name == search
11
+ end
12
+ puts "More than one item found for: #{search}" if found.length > 1
13
+ raise "Not found: #{search}" if found.length < 1
14
+ return found.first
15
+ end
16
+ end
17
+ end
18
+
@@ -1,5 +1,5 @@
1
- require 'io/console'
2
1
  # frozen_string_literal: true
2
+ require 'io/console'
3
3
 
4
4
  module LMCAdm
5
5
  # This module includes helpers for shared functionality across the
@@ -7,5 +7,15 @@ module LMCAdm
7
7
  end
8
8
  return max
9
9
  end
10
+
11
+ def self.complete_service_name(name)
12
+ if name.start_with? 'cloud-service-'
13
+ return name
14
+ end
15
+ if name.start_with? 'service-'
16
+ return 'cloud-' + name
17
+ end
18
+ return'cloud-service-' + name
19
+ end
10
20
  end
11
21
  end
@@ -1,3 +1,3 @@
1
1
  module LMCAdm
2
- VERSION = '0.12.0'
2
+ VERSION = '0.16.0'
3
3
  end
data/lmcadm.gemspec CHANGED
@@ -20,11 +20,11 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 2.0"
23
- spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rake", "~> 13.0"
24
24
  spec.add_development_dependency "minitest", "~> 5.0"
25
25
  spec.add_development_dependency "pry-nav", "0.2.4"
26
26
 
27
- spec.add_runtime_dependency 'lmc', '~> 0.11.0'
27
+ spec.add_runtime_dependency 'lmc', '~> 0.14.0'
28
28
  spec.add_runtime_dependency 'gli', '~> 2.17'
29
29
  spec.add_runtime_dependency 'table_print', '~> 1.5'
30
30
  spec.add_runtime_dependency 'colorize', '~> 0.8'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lmcadm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - erpel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-15 00:00:00.000000000 Z
11
+ date: 2021-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.11.0
75
+ version: 0.14.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.11.0
82
+ version: 0.14.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: gli
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +136,7 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: 1.3.0
139
- description:
139
+ description:
140
140
  email:
141
141
  - philipp@copythat.de
142
142
  executables:
@@ -155,6 +155,7 @@ files:
155
155
  - Rakefile
156
156
  - bin/console
157
157
  - bin/setup
158
+ - dev_lmcadm
158
159
  - exe/lmcadm
159
160
  - lib/lmcadm.rb
160
161
  - lib/lmcadm/ColoredProgressVisualizer.rb
@@ -167,22 +168,26 @@ files:
167
168
  - lib/lmcadm/commands/completion.rb
168
169
  - lib/lmcadm/commands/maintenance.rb
169
170
  - lib/lmcadm/commands/monitor.rb
171
+ - lib/lmcadm/commands/preferences.rb
170
172
  - lib/lmcadm/commands/principal.rb
171
173
  - lib/lmcadm/commands/privatecloud.rb
172
174
  - lib/lmcadm/commands/rights.rb
173
175
  - lib/lmcadm/commands/terminal.rb
174
176
  - lib/lmcadm/config_commands.rb
175
177
  - lib/lmcadm/device_commands.rb
178
+ - lib/lmcadm/helpers/args_helpers.rb
179
+ - lib/lmcadm/helpers/device_helpers.rb
180
+ - lib/lmcadm/helpers/find_helpers.rb
176
181
  - lib/lmcadm/helpers/password_helper.rb
177
182
  - lib/lmcadm/helpers/string_helpers.rb
178
183
  - lib/lmcadm/version.rb
179
184
  - lmcadm
180
185
  - lmcadm.gemspec
181
- homepage:
186
+ homepage:
182
187
  licenses:
183
188
  - BSD-3-Clause
184
189
  metadata: {}
185
- post_install_message:
190
+ post_install_message:
186
191
  rdoc_options: []
187
192
  require_paths:
188
193
  - lib
@@ -198,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
203
  version: '0'
199
204
  requirements: []
200
205
  rubygems_version: 3.1.2
201
- signing_key:
206
+ signing_key:
202
207
  specification_version: 4
203
208
  summary: lmcadm is a command line client for LMC
204
209
  test_files: []