lmc 0.9.0 → 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/inspectionProfiles/Project_Default.xml +1 -1
- data/.idea/vcs.xml +1 -1
- data/.rubocop.yml +6 -2
- data/.ruby-version +1 -1
- data/Rakefile +5 -3
- data/coverage/.last_run.json +1 -1
- data/lib/lmc.rb +2 -1
- data/lib/lmc/Account.rb +23 -6
- data/lib/lmc/Cloud.rb +26 -17
- data/lib/lmc/Configstates.rb +1 -0
- data/lib/lmc/Device.rb +1 -0
- data/lib/lmc/Response.rb +1 -0
- data/lib/lmc/Site.rb +1 -0
- data/lib/lmc/User.rb +1 -0
- data/lib/lmc/account_manager.rb +1 -0
- data/lib/lmc/auth/auth_action.rb +1 -0
- data/lib/lmc/authority.rb +1 -0
- data/lib/lmc/config/device_config.rb +4 -2
- data/lib/lmc/config/device_dsc_ui.rb +1 -0
- data/lib/lmc/device_config_state.rb +1 -0
- data/lib/lmc/entity.rb +3 -2
- data/lib/lmc/exceptions/lmc_outdated_terms_of_use_exception.rb +1 -0
- data/lib/lmc/logger.rb +8 -1
- data/lib/lmc/membership.rb +1 -0
- data/lib/lmc/mixins/json_able.rb +1 -0
- data/lib/lmc/mixins/service_resource.rb +1 -7
- data/lib/lmc/monitoring/monitoring_record.rb +1 -0
- data/lib/lmc/preferences/preferences.rb +24 -0
- data/lib/lmc/principal.rb +1 -0
- data/lib/lmc/uuid.rb +2 -1
- data/lib/lmc/version.rb +2 -1
- data/lmc.gemspec +3 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cfd78ebb37da9e527f2da6cdf0d7297994c49031cef7af9ce0534f86d2d66b01
|
4
|
+
data.tar.gz: bada57081f44bbdd303ebf2ebedee80c0e6c21be9e354614ba976ca96d4bc627
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ada15e1c15fedb1553b6f04334dee02bbcdad709c75b2750487932abd162245ab845b476be3f2d3d71cb43133df1800c2c4fc5b264ee1ba2b9bef339607c083
|
7
|
+
data.tar.gz: 1d08d68450769836432be5f38e16791de5dbf5bbbbedae30bd8eefd36d3a87aab5982bd0ed64080e30fb30ff673ddc84c8d8e0fec84b714f92276003adef2632
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<component name="InspectionProjectProfileManager">
|
2
2
|
<profile version="1.0">
|
3
3
|
<option name="myName" value="Project Default" />
|
4
|
-
<inspection_tool class="Rubocop" enabled="
|
4
|
+
<inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="true">
|
5
5
|
<scope name="Tests" level="ERROR" enabled="true" />
|
6
6
|
</inspection_tool>
|
7
7
|
<inspection_tool class="RubyInstanceMethodNamingConvention" enabled="true" level="WARNING" enabled_by_default="true">
|
data/.idea/vcs.xml
CHANGED
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.1
|
data/Rakefile
CHANGED
@@ -21,15 +21,16 @@ RuboCop::RakeTask.new(:autocop) do |t|
|
|
21
21
|
'Layout/SpaceAroundOperators',
|
22
22
|
'Layout/SpaceInsideBlockBraces',
|
23
23
|
'Layout/SpaceInsideHashLiteralBraces',
|
24
|
-
'Layout/
|
25
|
-
'Style/BracesAroundHashParameters',
|
24
|
+
'Layout/TrailingEmptyLines',
|
26
25
|
'Style/CommentAnnotation',
|
27
26
|
'Style/FrozenStringLiteralComment',
|
28
27
|
'Style/MethodDefParentheses',
|
29
28
|
'Style/RedundantSelf',
|
30
29
|
'Style/RedundantReturn',
|
31
30
|
'Style/StringLiterals',
|
32
|
-
'Style/StringLiteralsInInterpolation'
|
31
|
+
'Style/StringLiteralsInInterpolation',
|
32
|
+
'Style/StabbyLambdaParentheses',
|
33
|
+
]
|
33
34
|
t.options = ['--only', autofix.join(','), '--auto-correct', 'lib', 'test', 'Rakefile', 'lmc.gemspec']
|
34
35
|
end
|
35
36
|
task :default => :test
|
@@ -38,3 +39,4 @@ RDoc::Task.new do |rdoc|
|
|
38
39
|
rdoc.main = 'README.rdoc'
|
39
40
|
rdoc.rdoc_files.include('README.rdoc', 'lib/**/*.rb')
|
40
41
|
end
|
42
|
+
|
data/coverage/.last_run.json
CHANGED
data/lib/lmc.rb
CHANGED
@@ -23,8 +23,9 @@ Dir.glob(File.expand_path('../lmc/*.rb', __FILE__)).each do |file|
|
|
23
23
|
require file
|
24
24
|
end
|
25
25
|
|
26
|
-
['exceptions', 'auth', 'config', 'monitoring'].each do |folder|
|
26
|
+
['exceptions', 'auth', 'config', 'monitoring', 'preferences'].each do |folder|
|
27
27
|
Dir.glob(File.expand_path("../lmc/#{folder}/*.rb", __FILE__)).each do |file|
|
28
28
|
require file
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
data/lib/lmc/Account.rb
CHANGED
@@ -25,7 +25,7 @@ module LMC
|
|
25
25
|
(name.nil? || a.name == name) && (type.nil? || a.type == type)
|
26
26
|
end
|
27
27
|
if accounts.length == 1
|
28
|
-
|
28
|
+
accounts[0]
|
29
29
|
elsif accounts.length == 0
|
30
30
|
raise 'Did not find account'
|
31
31
|
else
|
@@ -83,7 +83,14 @@ module LMC
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def find_member_by_name(name)
|
86
|
-
|
86
|
+
if name.nil?
|
87
|
+
raise 'No member name given'
|
88
|
+
end
|
89
|
+
member = members.find { |m| m.name == name }
|
90
|
+
unless member
|
91
|
+
raise "Member named #{name} not found in account #{self}"
|
92
|
+
end
|
93
|
+
member
|
87
94
|
end
|
88
95
|
|
89
96
|
# def update_member(principal_id, data)
|
@@ -116,9 +123,14 @@ module LMC
|
|
116
123
|
end
|
117
124
|
|
118
125
|
def children
|
119
|
-
@cloud.auth_for_accounts([
|
120
|
-
|
121
|
-
|
126
|
+
@cloud.auth_for_accounts([ROOT_ACCOUNT_UUID])
|
127
|
+
# Projects can not have children, return empty map immediately as optimization
|
128
|
+
if type != "PROJECT"
|
129
|
+
response = @cloud.get ['cloud-service-auth', 'accounts', id, 'children']
|
130
|
+
response.map { |child| Account.new @cloud, child }
|
131
|
+
else
|
132
|
+
[]
|
133
|
+
end
|
122
134
|
end
|
123
135
|
|
124
136
|
def logs
|
@@ -132,7 +144,7 @@ module LMC
|
|
132
144
|
# private clouds can not have sites
|
133
145
|
return [] if @type == 'PRIVATE_CLOUD'
|
134
146
|
@cloud.auth_for_accounts([id])
|
135
|
-
response = @cloud.get ['cloud-service-devices', 'accounts', id, 'sites'],
|
147
|
+
response = @cloud.get ['cloud-service-devices', 'accounts', id, 'sites'], :select => :id
|
136
148
|
response.body.map { |data|
|
137
149
|
Site.new(UUID.new(data), self)
|
138
150
|
}
|
@@ -161,6 +173,10 @@ module LMC
|
|
161
173
|
"#{name}"
|
162
174
|
end
|
163
175
|
|
176
|
+
def summary
|
177
|
+
"\"#{@name}\" (#{@type}) ID: #{@id}"
|
178
|
+
end
|
179
|
+
|
164
180
|
private
|
165
181
|
|
166
182
|
## should be put into entity or such
|
@@ -178,3 +194,4 @@ module LMC
|
|
178
194
|
end
|
179
195
|
end
|
180
196
|
end
|
197
|
+
|
data/lib/lmc/Cloud.rb
CHANGED
@@ -63,6 +63,11 @@ module LMC
|
|
63
63
|
post ['cloud-service-auth', 'accounts', account_id, 'members'], body
|
64
64
|
end
|
65
65
|
|
66
|
+
# @param section Array of String to indicate section to access. Example: ['principal', 'self', 'ui']
|
67
|
+
def preferences(section)
|
68
|
+
LMC::Preferences.new cloud: self, section: section
|
69
|
+
end
|
70
|
+
|
66
71
|
def get(path, params = nil)
|
67
72
|
prepared_headers = headers
|
68
73
|
prepared_headers[:params] = params
|
@@ -74,31 +79,37 @@ module LMC
|
|
74
79
|
execute_request args
|
75
80
|
end
|
76
81
|
|
77
|
-
def put(path, body_object)
|
82
|
+
def put(path, body_object, params = nil)
|
83
|
+
prepared_headers = headers
|
84
|
+
prepared_headers[:params] = params
|
78
85
|
args = {
|
79
86
|
:method => :put,
|
80
87
|
:url => build_url(path),
|
81
|
-
:payload => body_object.to_json
|
82
|
-
|
88
|
+
:payload => body_object.to_json,
|
89
|
+
:headers => prepared_headers
|
83
90
|
}
|
84
91
|
execute_request args
|
85
92
|
end
|
86
93
|
|
87
|
-
def post(path, body_object)
|
94
|
+
def post(path, body_object, params=nil )
|
95
|
+
prepared_headers = headers
|
96
|
+
prepared_headers[:params] = params
|
88
97
|
args = {
|
89
98
|
:method => :post,
|
90
99
|
:url => build_url(path),
|
91
|
-
:payload => body_object.to_json
|
100
|
+
:payload => body_object.to_json,
|
101
|
+
:headers => prepared_headers
|
92
102
|
}
|
93
103
|
execute_request args
|
94
104
|
end
|
95
105
|
|
96
|
-
def delete(path,
|
106
|
+
def delete(path, params = nil)
|
107
|
+
prepared_headers = headers
|
108
|
+
prepared_headers[:params] = params
|
97
109
|
args = {
|
98
110
|
:method => :delete,
|
99
111
|
:url => build_url(path),
|
100
|
-
:
|
101
|
-
:headers => headers
|
112
|
+
:headers => prepared_headers
|
102
113
|
}
|
103
114
|
execute_request args
|
104
115
|
end
|
@@ -143,7 +154,6 @@ module LMC
|
|
143
154
|
if account_ids != @last_authorized_account_ids
|
144
155
|
begin
|
145
156
|
reply = post(['cloud-service-auth', 'auth'], name: @user, password: @password, accountIds: account_ids, termsOfUse: tos)
|
146
|
-
puts 'authorize reply ' + reply.inspect if Cloud.debug
|
147
157
|
@last_authorized_account_ids = account_ids
|
148
158
|
@auth_token = reply
|
149
159
|
@auth_ok = true
|
@@ -181,17 +191,16 @@ module LMC
|
|
181
191
|
internal_args.merge! args
|
182
192
|
begin
|
183
193
|
resp = RestClient::Request.execute internal_args
|
184
|
-
|
194
|
+
LMCResponse.new(resp)
|
185
195
|
rescue RestClient::ExceptionWithResponse => e
|
186
|
-
|
196
|
+
if Cloud.debug
|
197
|
+
puts 'EXCEPTION: ' + e.to_s
|
198
|
+
puts 'EX.response: ' + e.response.to_s
|
199
|
+
puts JSON.parse(e.response)['message']
|
200
|
+
end
|
187
201
|
raise e
|
188
202
|
end
|
189
203
|
end
|
190
|
-
|
191
|
-
def print_exception(execption)
|
192
|
-
puts 'EXCEPTION: ' + execption.to_s
|
193
|
-
puts 'EX.response: ' + execption.response.to_s
|
194
|
-
puts JSON.parse(execption.response)['message']
|
195
|
-
end
|
196
204
|
end
|
197
205
|
end
|
206
|
+
|
data/lib/lmc/Configstates.rb
CHANGED
data/lib/lmc/Device.rb
CHANGED
data/lib/lmc/Response.rb
CHANGED
data/lib/lmc/Site.rb
CHANGED
data/lib/lmc/User.rb
CHANGED
data/lib/lmc/account_manager.rb
CHANGED
data/lib/lmc/auth/auth_action.rb
CHANGED
data/lib/lmc/authority.rb
CHANGED
@@ -172,16 +172,17 @@ module LMC
|
|
172
172
|
end
|
173
173
|
|
174
174
|
def redeem_ticket(tries)
|
175
|
+
wait_seconds = 0.5
|
175
176
|
attempts = 1
|
176
177
|
until @response
|
177
|
-
raise
|
178
|
+
raise "Timeout waiting for config (#{attempts * wait_seconds}s)" if attempts > tries
|
178
179
|
attempts += 1
|
179
180
|
body = @cloud.get(url_ticket).body
|
180
181
|
unless body.respond_to? :ticketId
|
181
182
|
@ticket_id = nil
|
182
183
|
@response = body
|
183
184
|
end
|
184
|
-
sleep
|
185
|
+
sleep wait_seconds * attempts
|
185
186
|
end
|
186
187
|
end
|
187
188
|
|
@@ -190,3 +191,4 @@ module LMC
|
|
190
191
|
# end
|
191
192
|
end
|
192
193
|
end
|
194
|
+
|
data/lib/lmc/entity.rb
CHANGED
@@ -5,9 +5,9 @@ module LMC
|
|
5
5
|
def self.get_by_uuid_or_name(term)
|
6
6
|
raise 'Missing argument' if term.nil?
|
7
7
|
begin
|
8
|
-
|
8
|
+
get_by_uuid term
|
9
9
|
rescue RestClient::BadRequest, URI::InvalidURIError
|
10
|
-
|
10
|
+
get_by_name term
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -16,3 +16,4 @@ module LMC
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
data/lib/lmc/logger.rb
CHANGED
@@ -5,8 +5,15 @@ module LMC
|
|
5
5
|
class Logger < ::Logger
|
6
6
|
@cloud = nil
|
7
7
|
attr_accessor :cloud
|
8
|
+
@@header_token_re = /"Authorization"=>"Bearer ([\S]*)"/
|
8
9
|
def <<(line)
|
9
|
-
|
10
|
+
value_found = @@header_token_re.match line
|
11
|
+
if value_found
|
12
|
+
line.gsub! value_found[1], 'TOKEN REDACTED'
|
13
|
+
end
|
14
|
+
line.gsub! @cloud.password, '********'
|
15
|
+
super
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|
19
|
+
|
data/lib/lmc/membership.rb
CHANGED
data/lib/lmc/mixins/json_able.rb
CHANGED
@@ -9,9 +9,6 @@ module LMC
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
klass.class_exec do
|
12
|
-
def methodtest
|
13
|
-
puts("cloud-service-#{service_name}")
|
14
|
-
end
|
15
12
|
|
16
13
|
# method that wraps attr_accessor to keep the defined attrs in a class instance var for serializing
|
17
14
|
def self.resource_attrs(*attrs)
|
@@ -26,10 +23,6 @@ module LMC
|
|
26
23
|
end
|
27
24
|
end
|
28
25
|
|
29
|
-
def method_on_instance_of_class
|
30
|
-
puts("cloud-service-#{service_name} #{inspect}, #{@cloud}")
|
31
|
-
end
|
32
|
-
|
33
26
|
def collection_path
|
34
27
|
["cloud-service-#{service_name}", collection_name]
|
35
28
|
end
|
@@ -39,3 +32,4 @@ module LMC
|
|
39
32
|
end
|
40
33
|
end
|
41
34
|
end
|
35
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module LMC
|
3
|
+
class Preferences
|
4
|
+
def initialize(cloud:, section:)
|
5
|
+
@cloud = cloud
|
6
|
+
@section = section
|
7
|
+
end
|
8
|
+
|
9
|
+
def get(path)
|
10
|
+
response = @cloud.get build_url, { path: path }
|
11
|
+
response.body
|
12
|
+
end
|
13
|
+
|
14
|
+
def put(path, payload)
|
15
|
+
@cloud.put build_url, payload, { path: path }
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def build_url
|
20
|
+
['cloud-service-preferences'] + @section
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/lib/lmc/principal.rb
CHANGED
data/lib/lmc/uuid.rb
CHANGED
data/lib/lmc/version.rb
CHANGED
data/lmc.gemspec
CHANGED
@@ -32,12 +32,13 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
33
33
|
spec.add_development_dependency 'minitest', '~> 5.11'
|
34
34
|
spec.add_development_dependency 'minitest-reporters', '~> 1'
|
35
|
-
spec.add_development_dependency 'rake', '~>
|
35
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
36
36
|
spec.add_development_dependency 'recursive-open-struct', '~> 1.1'
|
37
37
|
spec.add_development_dependency 'simplecov', '~> 0.15'
|
38
38
|
spec.add_development_dependency 'pry-nav', '~> 0.2.4'
|
39
39
|
spec.add_development_dependency 'rubocop', '~> 0.58.1'
|
40
40
|
|
41
|
-
spec.add_runtime_dependency 'json', '~> 2.
|
41
|
+
spec.add_runtime_dependency 'json', '~> 2.3'
|
42
42
|
spec.add_runtime_dependency 'rest-client', '~> 2.0'
|
43
43
|
end
|
44
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lmc
|
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-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '12.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '12.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: recursive-open-struct
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '2.
|
131
|
+
version: '2.3'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '2.
|
138
|
+
version: '2.3'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: rest-client
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -195,6 +195,7 @@ files:
|
|
195
195
|
- lib/lmc/mixins/json_able.rb
|
196
196
|
- lib/lmc/mixins/service_resource.rb
|
197
197
|
- lib/lmc/monitoring/monitoring_record.rb
|
198
|
+
- lib/lmc/preferences/preferences.rb
|
198
199
|
- lib/lmc/principal.rb
|
199
200
|
- lib/lmc/uuid.rb
|
200
201
|
- lib/lmc/version.rb
|
@@ -219,8 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
220
|
- !ruby/object:Gem::Version
|
220
221
|
version: '0'
|
221
222
|
requirements: []
|
222
|
-
|
223
|
-
rubygems_version: 2.6.11
|
223
|
+
rubygems_version: 3.1.2
|
224
224
|
signing_key:
|
225
225
|
specification_version: 4
|
226
226
|
summary: Library for interacting with LMC cloud instances
|