lmcadm 0.15.0 → 0.16.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44c6d0a6cd45c6c772311396c13646899f7db20675004254fc70cb1821620d3c
4
- data.tar.gz: 93484873efe2767cb5c7911d00e72be3937cc7fbed2e29dfd3cbaeeb4d634d1d
3
+ metadata.gz: 2fa137bc6b37c1d4b8ad21a83b634fb19fd6403dcff6b23005da7a467aab9d70
4
+ data.tar.gz: 8a5f93e98b4f8248c9395e6a5980ae8c3ebc738dd45518295e781d165a0e715c
5
5
  SHA512:
6
- metadata.gz: d9790f5e3e28fcd2fc3b4a8633b47019b3190e166bc15e9e926ee552620a6ad9a1edb4364f2355c9c4a0cc523db6997f042bccbcdf8f07d781611d1fdf4759ee
7
- data.tar.gz: 92ed71b779d0bb817035a51965f4c308ce76cff89c4ddc86f8b06faf940766242e513260164eec6fb62b9c198fbb1e722072a8dc9c65e1be2f475070221d01f8
6
+ metadata.gz: 67a59f6513b13f9619c28b7319ebc5902d53bcae865570681be86b6842cf3155021850f3b6d32973c9eeb23bf66316c0d1954ac54e389883d1eb8e9b7a8316b4
7
+ data.tar.gz: 226c8ee80ed5519c3009fa8415abfbb0d9e5a566e52d44abb4ec6c112c48951647c4135e2fe68f521e9352b811b9521b98920c6fac6a93c33d2a1cf103e7c970
data/exe/lmcadm CHANGED
@@ -85,6 +85,9 @@ module LMCAdm
85
85
  ::LMC::Cloud.verify_tls = global["verify-tls"]
86
86
  ::LMC::Cloud.use_tls = global["use-tls"]
87
87
  LMCAdm::ProgressVisualizer.take_time = global["take-time"]
88
+ # let table_print print wide columns
89
+ tp.set :max_width, 50
90
+
88
91
  true
89
92
  end
90
93
 
@@ -26,7 +26,7 @@ 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
32
  puts account.summary
@@ -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
 
@@ -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
@@ -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
+
@@ -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.15.0'
2
+ VERSION = '0.16.0'
3
3
  end
data/lmcadm.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
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.13.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.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - erpel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-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
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.13.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.13.0
82
+ version: 0.14.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: gli
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -177,6 +177,7 @@ files:
177
177
  - lib/lmcadm/device_commands.rb
178
178
  - lib/lmcadm/helpers/args_helpers.rb
179
179
  - lib/lmcadm/helpers/device_helpers.rb
180
+ - lib/lmcadm/helpers/find_helpers.rb
180
181
  - lib/lmcadm/helpers/password_helper.rb
181
182
  - lib/lmcadm/helpers/string_helpers.rb
182
183
  - lib/lmcadm/version.rb