lmcadm 0.9.1 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.idea/encodings.xml +4 -0
- data/.idea/inspectionProfiles/Project_Default.xml +6 -0
- data/.idea/vcs.xml +1 -1
- data/.ruby-version +1 -1
- data/README.md +0 -2
- data/exe/lmcadm +1 -1
- data/lib/lmcadm/account_commands.rb +12 -147
- data/lib/lmcadm/cloud_commands.rb +24 -10
- data/lib/lmcadm/commands/maintenance.rb +12 -3
- data/lib/lmcadm/commands/principal.rb +1 -11
- data/lib/lmcadm/commands/terminal.rb +110 -0
- data/lib/lmcadm/device_commands.rb +25 -14
- data/lib/lmcadm/helpers/device_helpers.rb +14 -0
- data/lib/lmcadm/version.rb +1 -1
- data/lmcadm +1 -1
- data/lmcadm.gemspec +5 -12
- metadata +31 -15
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4f055f406fb215892883880ea00a3cc41facb3a166e64ffba07fc91b73999780
|
4
|
+
data.tar.gz: 944777b89bab8c1315d06704b83e74201738f2ddeef44f8033e4fa801e797db3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b557768748a73c485983f0458c40f09d52cc32c9dfee053cd1652945971331f64f2a3299939f3b847558e02d6b48e71da890045c15aaa58ed43a94ee3613227
|
7
|
+
data.tar.gz: 7ce7cbe01436e2e521dbd91b4247b97232e4b884e228c93c59f42b5e417ac8d1a35355665ac0755b4a173b032ac9ba6aa16af589c8cee8f1546df7a726ef7185
|
data/.idea/encodings.xml
ADDED
data/.idea/vcs.xml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.1
|
data/README.md
CHANGED
@@ -20,8 +20,6 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
20
20
|
|
21
21
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
22
22
|
|
23
|
-
### Branching
|
24
|
-
To avoid immediate chaos, a branching model of "create a branch for new versions aka v0.6.1" has been adpoted until further notice.
|
25
23
|
### Using a local version of the lmc gem
|
26
24
|
|
27
25
|
Set the environment variable LMCADM\_PATH\_DEP to 1 to use the _lmc_ gem from ../ruby-lmc.
|
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]
|
@@ -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
|
-
|
87
|
-
|
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
|
@@ -117,7 +117,7 @@ module LMCAdm
|
|
117
117
|
exit unless STDIN.gets.chomp == 'yes'
|
118
118
|
t = ProgressVisualizer.new "Deleting accounts"
|
119
119
|
matched_accounts.each do |a|
|
120
|
-
a.delete
|
120
|
+
a.delete!
|
121
121
|
t.dot
|
122
122
|
end
|
123
123
|
t.done
|
@@ -160,125 +160,25 @@ module LMCAdm
|
|
160
160
|
account = LMC::Account.get_by_uuid_or_name args.first
|
161
161
|
members = account.members
|
162
162
|
tp members, [{:id => {:width => 36}}, :name, :type, :state, :invitationState, :principalState,
|
163
|
-
:authorities => lambda {|m|
|
163
|
+
:authorities => {:display_method => lambda {|m|
|
164
164
|
m.authorities.map {|a|
|
165
165
|
a['name']
|
166
166
|
}.join(',')
|
167
|
-
}]
|
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
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]
|
@@ -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 |
|
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 |
|
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 |
|
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 |
|
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
|
@@ -383,15 +282,6 @@ module LMCAdm
|
|
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|
|
@@ -21,9 +21,9 @@ module LMCAdm
|
|
21
21
|
#account = cloud.get_account(nil, 'ROOT')
|
22
22
|
#puts account.inspect
|
23
23
|
#cloud.auth_for_accounts([account.id])
|
24
|
-
backstage_infos = cloud.get_backstage_serviceinfos.body.map {|info| {'serviceId' => info.serviceId,
|
25
|
-
|
26
|
-
|
24
|
+
backstage_infos = cloud.get_backstage_serviceinfos.body.map {|info| { 'serviceId' => info.serviceId,
|
25
|
+
'instanceCount' => info.instanceCount,
|
26
|
+
'versions' => info.versionInfoList.map {|vil| vil['version']}.uniq.join(",")
|
27
27
|
}}
|
28
28
|
tp backstage_infos
|
29
29
|
puts '---'
|
@@ -50,12 +50,12 @@ module LMCAdm
|
|
50
50
|
begin
|
51
51
|
cloud = LMC::Cloud.instance
|
52
52
|
rescue LMC::OutdatedTermsOfUseException => e
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
matched_tos = e.missing.select do |missingtos|
|
54
|
+
args.include? missingtos['name']
|
55
|
+
end
|
56
|
+
cloud = LMC::Cloud.instance authorize: false
|
57
|
+
puts "Accepting TOS #{matched_tos.to_s}"
|
58
|
+
cloud.accept_tos matched_tos
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -75,5 +75,19 @@ module LMCAdm
|
|
75
75
|
user.update(global_options[:password])
|
76
76
|
end
|
77
77
|
end
|
78
|
+
|
79
|
+
c.arg_name 'account'#, :multiple => true # no support for multiple accounts until the auth_for_accounts api is fixed
|
80
|
+
c.desc 'Request auth token'
|
81
|
+
c.command :token do |get_token|
|
82
|
+
get_token.action do |_g, _o, args|
|
83
|
+
accounts = args.map { |a|
|
84
|
+
LMC::Account.get_by_uuid_or_name a
|
85
|
+
}
|
86
|
+
accounts.each { |a|
|
87
|
+
a.cloud.auth_for_account a
|
88
|
+
puts a.cloud.session_token
|
89
|
+
}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
78
93
|
end
|
79
|
-
end
|
@@ -11,16 +11,25 @@ module LMCAdm
|
|
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
|
-
|
23
|
-
|
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
|
|
@@ -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
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
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]
|
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,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
|
+
|
data/lib/lmcadm/version.rb
CHANGED
data/lmcadm
CHANGED
data/lmcadm.gemspec
CHANGED
@@ -12,14 +12,6 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.summary = %q{lmcadm is a command line client for LMC}
|
13
13
|
spec.license = "BSD-3-Clause"
|
14
14
|
|
15
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
16
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
17
|
-
if spec.respond_to?(:metadata)
|
18
|
-
else
|
19
|
-
raise "RubyGems 2.0 or newer is required to protect against " \
|
20
|
-
"public gem pushes."
|
21
|
-
end
|
22
|
-
|
23
15
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
24
16
|
f.match(%r{^(test|spec|features)/})
|
25
17
|
end
|
@@ -27,13 +19,14 @@ Gem::Specification.new do |spec|
|
|
27
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
20
|
spec.require_paths = ["lib"]
|
29
21
|
|
30
|
-
spec.add_development_dependency "bundler", "~>
|
31
|
-
spec.add_development_dependency "rake", "~>
|
22
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
23
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
32
24
|
spec.add_development_dependency "minitest", "~> 5.0"
|
33
25
|
spec.add_development_dependency "pry-nav", "0.2.4"
|
34
26
|
|
35
|
-
spec.add_runtime_dependency 'lmc', '~> 0.
|
27
|
+
spec.add_runtime_dependency 'lmc', '~> 0.11.0'
|
36
28
|
spec.add_runtime_dependency 'gli', '~> 2.17'
|
37
29
|
spec.add_runtime_dependency 'table_print', '~> 1.5'
|
38
|
-
spec.add_runtime_dependency 'colorize'
|
30
|
+
spec.add_runtime_dependency 'colorize', '~> 0.8'
|
31
|
+
spec.add_runtime_dependency 'websocket-eventmachine-client', '~> 1.3.0'
|
39
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.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- erpel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
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: '
|
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.
|
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.
|
82
|
+
version: 0.11.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: gli
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,16 +112,30 @@ dependencies:
|
|
112
112
|
name: colorize
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
117
|
+
version: '0.8'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
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
|
+
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
138
|
+
version: 1.3.0
|
125
139
|
description:
|
126
140
|
email:
|
127
141
|
- philipp@copythat.de
|
@@ -131,9 +145,10 @@ extensions: []
|
|
131
145
|
extra_rdoc_files: []
|
132
146
|
files:
|
133
147
|
- ".gitignore"
|
148
|
+
- ".idea/encodings.xml"
|
149
|
+
- ".idea/inspectionProfiles/Project_Default.xml"
|
134
150
|
- ".idea/vcs.xml"
|
135
151
|
- ".ruby-version"
|
136
|
-
- ".travis.yml"
|
137
152
|
- Gemfile
|
138
153
|
- LICENSE.txt
|
139
154
|
- README.md
|
@@ -155,8 +170,10 @@ 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/device_helpers.rb
|
160
177
|
- lib/lmcadm/helpers/password_helper.rb
|
161
178
|
- lib/lmcadm/helpers/string_helpers.rb
|
162
179
|
- lib/lmcadm/version.rb
|
@@ -181,8 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
198
|
- !ruby/object:Gem::Version
|
182
199
|
version: '0'
|
183
200
|
requirements: []
|
184
|
-
|
185
|
-
rubygems_version: 2.6.11
|
201
|
+
rubygems_version: 3.1.2
|
186
202
|
signing_key:
|
187
203
|
specification_version: 4
|
188
204
|
summary: lmcadm is a command line client for LMC
|