lmcadm 0.9.2 → 0.13.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
- SHA1:
3
- metadata.gz: a990a6d39e05d589b58671231dfc4f2464dba593
4
- data.tar.gz: d1846b40cd26efd2b231e6d086d8ae4d50073ea2
2
+ SHA256:
3
+ metadata.gz: e4ec85a8b1a7d9fe63c2f27ec1016310c0e029f878ab430063cdf8305d84b56e
4
+ data.tar.gz: 4538b2bb9b9c212e3e58cf13badc5720b7480622eb3b02006c60e8c5a61d5f65
5
5
  SHA512:
6
- metadata.gz: e70f755c9fc4cde186e8a822fbcad76120e195a35771235af04ac37a310d1c458cadc39f1bf7fd6a7c2f576022784553607c6803a1531aabad4f77327f5db596
7
- data.tar.gz: b779db3ee64def14c157619917248a39f62ad778851c1dd209906882a0091e87a63d59ef03f7ae1b7baa97a466bc09bb11d8417db49b540a8996006c2c208b7c
6
+ metadata.gz: 81cf76346a7cb4e017f0db92ba785a3805b348bfb9d041d28361a63ba7dffd87a8363c9cc4c937b9e1f62b514780b81227c4e5b2a61f99ed8c2658f66013b77e
7
+ data.tar.gz: b361f098338b6827a2ef76ba3d3680afade12ea06c8dcb00d3f04f5b86dff10110a59288517b0a829f3859fb4bd8a8b8654ab6bcc316af566e1d67b92e96514f
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
5
+ </profile>
6
+ </component>
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
3
  <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
4
+ <mapping directory="" vcs="Git" />
5
5
  </component>
6
6
  </project>
@@ -1 +1 @@
1
- 2.4.1
1
+ 2.7.1
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/exe/lmcadm CHANGED
@@ -60,7 +60,7 @@ module LMCAdm
60
60
  # chosen command
61
61
  # Use skips_pre before a command to skip this block
62
62
  # on that command only
63
- if global[:password] == ""
63
+ if command.name != :completion && global[:password] == ""
64
64
  global[:password] = Helpers::read_pw "Enter password for #{global[:user]}:"
65
65
  end
66
66
  ::LMC::Cloud.cloud_host = global[:cloud_host]
@@ -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
@@ -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({ "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
@@ -159,126 +159,26 @@ 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|
162
+ tp members, [{:id => {:width => 36}}, :name, :type, :state, :invitationState, :principalState,
163
+ :authorities => {:display_method => lambda {|m|
164
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
 
171
- # Commented out due to bad quality at the moment.
172
- # This code is untested after the gem split.
173
- =begin
174
- c.desc 'Modify account members'
175
- c.command :memberupdate do |memberupdate|
176
- memberupdate.desc 'Account UUID'
177
- memberupdate.flag :a, "account-uuid", :required => true
178
-
179
- memberupdate.desc 'Principal UUID'
180
- memberupdate.flag :u, :uuid, :required => true
181
-
182
- memberupdate.desc 'Authority'
183
- memberupdate.flag :authority
184
-
185
- memberupdate.action do |global_options, options, args|
186
- account = LMCAccount.get options[:a]
187
-
188
- account_authorities = account.authorities
189
- puts account_authorities.inspect if global_options[:debug]
190
- authority = account_authorities.find {|auth| auth["name"] == options[:authority]}
191
- puts authority if global_options[:debug]
192
- puts "authority id: #{authority["id"]}" if global_options[:debug]
193
-
194
- resp = account.update_member options[:u], {:authorities => [authority["id"]]}
195
- puts "response: #{resp.inspect}"
196
- if resp.code == 200
197
- puts "Updated success"
198
-
199
- else
200
- loggerr.error "ERROR: #{resp.code} #{resp.body.message}"
201
- end
202
-
203
- end
204
- end
205
-
206
- c.arg_name "email address", [:optional, :multiple]
207
- c.desc 'Invite members, requires an account type'
208
- c.command :invite do |account_invite|
209
-
210
- account_invite.desc "File with email addresses; one address per line"
211
- account_invite.flag :file
212
- #account_invite.desc "Email address to invite"
213
- #account_invite.flag :
214
- account_invite.desc 'Account name'
215
- account_invite.flag :account_name, :A, :required => true
216
-
217
- account_invite.desc 'Member type'
218
- account_invite.default_value "MEMBER"
219
- account_invite.flag :member_type
220
-
221
- account_invite.desc 'Authority'
222
- account_invite.default_value "PROJECT_VIEWER"
223
- account_invite.flag :authority
224
-
225
- account_invite.desc 'Do not make changes'
226
- account_invite.switch :n, :dry
227
-
228
- account_invite.desc "Send emails (deprecated)"
229
- account_invite.default_value false
230
- account_invite.switch :e, "send-mail", "send-email"
231
-
232
- account_invite.default_value false
233
- account_invite.switch "show-csv"
234
-
235
- account_invite.action do |global_options, options, args|
236
-
237
- puts "ARGS:" + args.inspect if global_options[:debug]
238
- lmcen = Cloud.new(global_options[:cloud_host], global_options[:user], global_options[:password])
239
- t = ProgressVisualizer.new "Getting account"
240
- account = lmcen.get_account options[:account_name], options[GLI::Command::PARENT][:account_type]
241
- t.done
242
-
243
- am = AccountManager.new(options, global_options)
244
- if options[:file]
245
- t = ProgressVisualizer.new "Inviting from file"
246
- File.foreach(options[:file]) do |line|
247
- if nil != am.invite(lmcen, account, line, options[:member_type], options[:authority])
248
- t.dot
249
- else
250
- t.X
251
- end
252
- end
253
- t.done
254
- end
255
- if not args.empty?
256
- t = ProgressVisualizer.new "Inviting from arguments"
257
- args.each do |line|
258
- if nil != am.invite(lmcen, account, line, options[:member_type], options[:authority])
259
- t.dot
260
- else
261
- t.X
262
- end
263
- end
264
- t.done
265
- end
266
- loggerr.info am.errors unless am.errors.empty?
267
-
268
- end
269
- end
270
- =end
271
171
  c.arg_name '"Account name"|UUID', [:required]
272
172
  c.desc 'List authorities'
273
173
  c.command :authorities do |auth|
274
-
275
- auth.action do |g, o, args|
174
+ auth.action do |_g, _o, args|
276
175
  account = LMC::Account.get_by_uuid_or_name args.first
277
176
  authorities = account.authorities
278
177
  max = Helpers::longest_in_collection(authorities.map {|a| a.name})
279
- tp authorities, [{ :id => { :width => 36 } }, { :name => { :width => max } }, :visibility, :type]
178
+ tp authorities, [{:id => {:width => 36}}, {:name => {:width => max}}, :visibility, :type]
280
179
  end
281
180
  end
181
+
282
182
  c.desc 'Manage authorities'
283
183
  c.command :authority do |auth|
284
184
  auth.arg_name 'Authority name', [:required]
@@ -287,7 +187,7 @@ module LMCAdm
287
187
  create.flag :A, :required => true
288
188
  create.action do |_global_options, options, _args|
289
189
  account = LMC::Account.get_by_uuid_or_name options[:A]
290
- auth = LMC::Authority.new({ 'name' => _args.first, 'visibility' => 'PRIVATE' }, account)
190
+ auth = LMC::Authority.new({'name' => _args.first, 'visibility' => 'PRIVATE'}, account)
291
191
  puts auth.save
292
192
  end
293
193
  end
@@ -307,13 +207,12 @@ module LMCAdm
307
207
  cloud.invite_user_to_account email, account.id, options[:type], chosen_authorities
308
208
  end
309
209
  end
310
-
311
210
  end
312
211
 
313
212
  c.desc 'Leave account'
314
213
  c.arg_name "Account id"
315
214
  c.command :leave do |leave|
316
- leave.action do |global_options, options, args|
215
+ leave.action do |_global_options, _options, args|
317
216
  account = LMC::Account.get_by_uuid(args[0])
318
217
  puts "Leave account \"#{account.name}\""
319
218
  puts account.remove_membership_self
@@ -324,7 +223,7 @@ module LMCAdm
324
223
  c.desc 'Add Member'
325
224
  c.command :memberadd do |ma|
326
225
  ma.flag :A, :account, :required => true
327
- ma.action do |global_options, options, args|
226
+ ma.action do |_global_options, options, args|
328
227
  target_account = LMC::Account.get_by_uuid_or_name options[:account]
329
228
  membership = LMC::Membership.new
330
229
  membership.name = args.first
@@ -343,7 +242,7 @@ module LMCAdm
343
242
  c.desc 'Remove member from account'
344
243
  c.command :memberremove do |memberremove|
345
244
  memberremove.flag :A, :account, :required => true
346
- memberremove.action do |global_options, options, args|
245
+ memberremove.action do |_global_options, options, args|
347
246
  account = LMC::Account.get_by_uuid_or_name(options[:account])
348
247
  membership = account.find_member_by_name args.first
349
248
  puts "Leave account \"#{account.name}\""
@@ -357,7 +256,7 @@ module LMCAdm
357
256
  update.flag :A, :account, :required => true
358
257
  update.desc 'authority id'
359
258
  update.flag 'add-authority'
360
- update.action do |global_options, options, args|
259
+ update.action do |_global_options, options, args|
361
260
  account = LMC::Account.get_by_uuid_or_name(options[:account])
362
261
  membership = account.find_member_by_name args.first
363
262
  puts membership
@@ -376,22 +275,13 @@ module LMCAdm
376
275
  # POST /accounts/{accountId}/members/{principalId}
377
276
  cloud = LMC::Cloud.instance
378
277
  cloud.auth_for_account account
379
- res = cloud.post ['cloud-service-auth', 'accounts', account.id, 'members', membership.id], { 'authorities' => authority_ids }
278
+ res = cloud.post ['cloud-service-auth', 'accounts', account.id, 'members', membership.id], {'authorities' => authority_ids}
380
279
  puts res
381
280
  end
382
281
  end
383
282
  end
384
283
 
385
284
 
386
- # IF the special flag is set, do weird license magic for ninden
387
- # * Für alle unterliegenden Organisationen
388
- # -> POST /accounts/{accountId}/conditions/device-operation
389
- # -> "templateAllowTestAllocation": true,
390
- # -> "templateTestDuration": 30
391
- # * Für alle unterliegenden Projekte
392
- # -> POST /accounts/{accountId}/conditions/device-operation
393
- # -> "allowTestAllocation": true,
394
- # -> "testDuration": 30
395
285
  c.desc 'List account children'
396
286
  c.arg_name 'UUID|Name'
397
287
  c.command :children do |children|
@@ -400,31 +290,6 @@ module LMCAdm
400
290
  account = LMC::Account.get_by_uuid_or_name args.first
401
291
  cloud = LMC::Cloud.instance
402
292
 
403
- # def recurse_print_children(root_acc, account, options, cloud)
404
- # children = root_acc.children_for_account_id account.id
405
- # children.each do |child|
406
- # puts "\n#{child["name"]} #{child["id"]} #{child["type"]}"
407
- # if options[:special] == "read"
408
- # puts cloud.get ["cloud-service-licenses", "accounts", child["id"], "conditions"]
409
- # end
410
- # if options[:special] == "write"
411
- # if child["type"] == "ORGANIZATION"
412
- # #puts cloud.get ["cloud-service-licenses", "accounts", child["id"], "conditions", "device-operation"]
413
- # puts cloud.post ["cloud-service-licenses", "accounts", child["id"], "conditions", "device-operation"], {"templateAllowTestAllocation" => true, "templateTestDuration": 30}
414
- # end
415
- # if child["type"] == "PROJECT"
416
- # #puts cloud.get ["cloud-service-licenses", "accounts", child["id"], "conditions", "device-operation"]
417
- # puts cloud.post ["cloud-service-licenses", "accounts", child["id"], "conditions", "device-operation"], {"allowTestAllocation" => true, "testDuration": 30}
418
- # end
419
- #
420
- # end
421
- # end
422
- # children.each do |child|
423
- # childacc = LMCAccount.new(child)
424
- # recurse_print_children(childacc, childacc, options, cloud)
425
- # end
426
- # end
427
- #recurse_print_children(account, account, options, cloud)
428
293
  def recurse_childen account, indent_level
429
294
  children = account.children
430
295
  children.each do |child|
@@ -7,27 +7,37 @@ 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
 
14
- maintenance.arg_name 'UUID'
14
+ maintenance.arg_name 'UUID', [:required]
15
15
  maintenance.desc 'Enable scripting for an account'
16
16
  maintenance.command :scripting do |scr|
17
+ scr.desc 'Change the state of scripting'
17
18
  scr.switch :enable
19
+ scr.desc 'Get the state of scripting'
20
+ scr.switch :get
18
21
  scr.action do |global_options, options, args|
22
+ raise "No account UUID specified" if args.length < 1
19
23
  root_account = LMC::Account.get LMC::Account::ROOT_ACCOUNT_UUID
20
24
  cloud = LMC::Cloud.instance
21
25
  cloud.auth_for_account root_account
22
- result = cloud.put ['cloud-service-config', 'configroot', 'accounts', args.first, 'scriptauthority'], options[:enable]
23
- raise "error - unexpected result" unless result.body == options[:enable]
26
+ if options[:get]
27
+ result = cloud.get ['cloud-service-config', 'configroot', 'accounts', args.first, 'scriptauthority']
28
+ puts result.body
29
+ else
30
+ result = cloud.put ['cloud-service-config', 'configroot', 'accounts', args.first, 'scriptauthority'], options[:enable]
31
+ raise "error - unexpected result" unless result.body == options[:enable]
32
+ end
24
33
  end
25
34
  end
26
35
 
27
- maintenance.arg_name 'UUID', required: true
36
+ maintenance.arg_name 'UUID'
28
37
  maintenance.desc 'Exempt user from brute force blocking'
29
38
  maintenance.command :whitelist do |wl|
30
39
  wl.action do |_g, _o, args|
40
+ Helpers.ensure_arg args, kind: 'user uuid'
31
41
  cloud = LMC::Cloud.instance
32
42
  root_account = LMC::Account.get LMC::Account::ROOT_ACCOUNT_UUID
33
43
  cloud.auth_for_account root_account
@@ -36,5 +46,20 @@ module LMCAdm
36
46
  cloud.post url_components, {}
37
47
  end
38
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
39
64
  end
40
65
  end
@@ -10,16 +10,7 @@ module LMCAdm
10
10
  cloud.auth_for_account root_account
11
11
  pw = Helpers::read_pw "Enter new password for #{args.first}:"
12
12
  principal = LMC::Principal.new({ 'name' => args.first, 'password' => pw, 'type' => options[:type] })
13
- puts principal.save.inspect
14
- begin
15
- rescue Exception => e
16
- puts e.inspect
17
- puts e.message.inspect
18
- puts e.response
19
- puts e.response.message
20
- end
21
-
22
-
13
+ puts principal.save
23
14
  end
24
15
  end
25
16
 
@@ -40,7 +31,6 @@ module LMCAdm
40
31
  c = LMC::Cloud.instance
41
32
  c.auth_for_account LMC::Account.get LMC::Account::ROOT_ACCOUNT_UUID
42
33
  c.delete ['cloud-service-auth', 'principals', args.first]
43
-
44
34
  end
45
35
  end
46
36
  end
@@ -0,0 +1,110 @@
1
+ require 'websocket-eventmachine-client'
2
+ require 'io/console'
3
+ require 'date'
4
+ module LMCAdm
5
+
6
+ class KeyboardHandler < EM::Connection
7
+ def receive_data(data)
8
+ if data == "\C-c"
9
+ EventMachine::stop_event_loop
10
+ end
11
+ LMCAdm::getWS.send '1' + data, type: 'binary'
12
+
13
+ end
14
+ #include EM::Protocols::LineText2
15
+
16
+ #def receive_line(data)
17
+ # LMCAdm::getWS.send '1' + data.strip + "\r", type: 'binary'
18
+ #end
19
+ end
20
+
21
+ def self.getWS
22
+ @ws
23
+ end
24
+
25
+ arg_name "device"
26
+ desc "Open terminal"
27
+ command :terminal do |t|
28
+ t.desc "Account name|UUID"
29
+ t.flag :account, :A, :required => true
30
+
31
+ t.action do |g, o, args|
32
+ account = LMC::Account.get_by_uuid_or_name o[:account]
33
+ device = Helpers::find_device account.devices, name: args.first, id: args.first
34
+ account.cloud.auth_for_account account
35
+ payload = {type: 'TERMINAL',
36
+ deviceIds: [device.id]}
37
+ sessionInfo = account.cloud.post ['cloud-service-devicetunnel', 'accounts', account.id, 'terminal'], payload
38
+
39
+
40
+ if g['use-tls']
41
+ url = 'wss://'
42
+ else
43
+ url = 'ws://'
44
+ end
45
+ url += g[:cloud_host]
46
+ url += '/cloud-service-devicetunnel/session'
47
+ headers_hash = {
48
+ 'Sec-WebSocket-Protocol' => "TYPE_TERMINAL, REQU_USER, IDEN_#{sessionInfo.body.first['id']}, ACCT_#{account.id}, DEVC_#{device.id}"
49
+ }
50
+ begin
51
+ EventMachine.epoll
52
+ EventMachine.run do
53
+ trap("TERM") { stop g[:debug]}
54
+ trap("INT") { stop g[:debug]}
55
+ IO.console.raw!
56
+ EventMachine.open_keyboard(LMCAdm::KeyboardHandler)
57
+ @ws = WebSocket::EventMachine::Client.connect({uri: url, headers: headers_hash})
58
+ closing = false
59
+
60
+ @ws.onopen do
61
+ print "Connected to #{device.name} (#{device.id}):\r\n"
62
+ end
63
+
64
+ @ws.onmessage do |msg, type|
65
+ print "##{msg.length}##{msg.inspect}#" if g[:debug]
66
+ if msg.start_with? "1"
67
+ print msg[1..-1].gsub("\n","\r\n")
68
+ else
69
+ print msg if g[:debug]
70
+ end
71
+ print DateTime.now.to_s if g[:debug]
72
+ if msg.include? "\n\nGoodbye\n\n"
73
+ stop g[:debug]
74
+ closing = true
75
+ end
76
+ end
77
+
78
+ @ws.onclose do
79
+ print DateTime.now.to_s if g[:debug]
80
+ print "Disconnected\r\n"
81
+ stop g[:debug] unless closing
82
+ end
83
+
84
+ @ws.onerror do |e|
85
+ puts "Error: #{e}"
86
+ end
87
+
88
+ @ws.onping do |msg|
89
+ puts "Received ping: #{msg}" if g[:verbose]
90
+ end
91
+
92
+ @ws.onpong do |msg|
93
+ puts "Received pong: #{msg}" if g[:verbose]
94
+ end
95
+
96
+ def stop(debug=false)
97
+ print DateTime.now.to_s if debug
98
+ print "Terminating connection\r\n"
99
+ EventMachine.stop
100
+ end
101
+ end
102
+ ensure
103
+ IO.console.cooked!
104
+ 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']}"]
108
+ end
109
+ end
110
+ end
@@ -33,45 +33,56 @@ module LMCAdm
33
33
  end
34
34
  end
35
35
 
36
- c.arg_name "device uuid", [:multiple]
36
+ c.arg_name "<device uuid|name>", [:multiple, :required]
37
37
  c.desc 'Show device config'
38
38
  c.command :config do |device_config|
39
39
  device_config.desc 'Account UUID|Name'
40
40
  device_config.flag :A, :account
41
41
 
42
+ device_config.desc 'Output descriptive identifiers, overrides filter oid and lcf format'
43
+ device_config.switch :d, :descriptive
44
+
45
+ device_config.desc 'Output lcf file, overrides filter oid'
46
+ device_config.switch :lcf
47
+
42
48
  device_config.desc 'Write to files'
43
49
  device_config.switch :w
50
+
44
51
  device_config.desc 'Prefix for files'
45
52
  device_config.default_value 'config'
46
53
  device_config.flag :p, :prefix
47
54
 
48
- device_config.desc "Filter OID"
55
+ device_config.desc "Filter OID, incompatible with descriptive identifiers"
49
56
  device_config.flag :filter_oid, "filter-oid"
50
57
 
51
58
  device_config.action do |global_options, options, args|
59
+ raise "No devices specified" if args.length < 1
52
60
  account = LMC::Account.get_by_uuid_or_name options[:account]
53
61
  all_devices = LMC::Device.get_for_account(account)
54
62
  devices = all_devices.select do |device|
55
- args.include? device.id
63
+ (args.include? device.id) || (args.include? device.name)
56
64
  end
65
+ file_extension = 'json'
57
66
  devices.each do |device|
58
- full_config = device.get_config_for_account(account)
59
- result_config = full_config
60
- if options[:filter_oid]
61
- result_config = full_config["items"].select do |item|
62
- item == options[:filter_oid]
63
- end
67
+ config = device.config
68
+ if options[:descriptive]
69
+ result_config = config.descriptive_confighash
70
+ elsif options[:lcf]
71
+ pretty = config.lcf
72
+ file_extension = 'lcf'
73
+ elsif options[:filter_oid]
74
+ puts config.confighash
75
+ result_config = config.confighash[options[:filter_oid]]
76
+ else
77
+ result_config = config.confighash
64
78
  end
65
- puts "result_config class: " + result_config.class.to_s if global_options[:debug]
66
- puts "result_config class: " + result_config.body_object.class.to_s if global_options[:debug]
67
- pretty = JSON.pretty_generate(result_config)
79
+ pretty ||= JSON.pretty_generate(result_config)
68
80
  if options[:w]
69
- IO.write(options[:prefix] + "-" + device.name + '-' + device.id + ".json", pretty)
81
+ IO.write("#{options[:prefix]}-#{device.name}-#{device.id}.#{file_extension}", pretty)
70
82
  else
71
83
  puts pretty
72
84
  end
73
85
  end
74
-
75
86
  end
76
87
 
77
88
  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
+
@@ -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
@@ -1,3 +1,3 @@
1
1
  module LMCAdm
2
- VERSION = '0.9.2'
2
+ VERSION = '0.13.0'
3
3
  end
data/lmcadm CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/bin/sh
2
2
  #wrapper script
3
3
  #set -x
4
- GLI_DEBUG=true bundle exec exe/lmcadm "$@"
4
+ GLI_DEBUG=false bundle exec exe/lmcadm "$@"
@@ -20,12 +20,13 @@ 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.8.0'
27
+ spec.add_runtime_dependency 'lmc', '~> 0.11.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'
31
+ spec.add_runtime_dependency 'websocket-eventmachine-client', '~> 1.3.0'
31
32
  end
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.9.2
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - erpel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-25 00:00:00.000000000 Z
11
+ date: 2020-06-03 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.8.0
75
+ version: 0.11.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.8.0
82
+ version: 0.11.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: gli
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: websocket-eventmachine-client
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.3.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.3.0
125
139
  description:
126
140
  email:
127
141
  - philipp@copythat.de
@@ -132,6 +146,7 @@ extra_rdoc_files: []
132
146
  files:
133
147
  - ".gitignore"
134
148
  - ".idea/encodings.xml"
149
+ - ".idea/inspectionProfiles/Project_Default.xml"
135
150
  - ".idea/vcs.xml"
136
151
  - ".ruby-version"
137
152
  - Gemfile
@@ -155,8 +170,11 @@ files:
155
170
  - lib/lmcadm/commands/principal.rb
156
171
  - lib/lmcadm/commands/privatecloud.rb
157
172
  - lib/lmcadm/commands/rights.rb
173
+ - lib/lmcadm/commands/terminal.rb
158
174
  - lib/lmcadm/config_commands.rb
159
175
  - lib/lmcadm/device_commands.rb
176
+ - lib/lmcadm/helpers/args_helpers.rb
177
+ - lib/lmcadm/helpers/device_helpers.rb
160
178
  - lib/lmcadm/helpers/password_helper.rb
161
179
  - lib/lmcadm/helpers/string_helpers.rb
162
180
  - lib/lmcadm/version.rb
@@ -181,8 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
199
  - !ruby/object:Gem::Version
182
200
  version: '0'
183
201
  requirements: []
184
- rubyforge_project:
185
- rubygems_version: 2.6.11
202
+ rubygems_version: 3.1.2
186
203
  signing_key:
187
204
  specification_version: 4
188
205
  summary: lmcadm is a command line client for LMC