lmc 0.10.0 → 0.13.0
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 +5 -3
- data/.ruby-version +1 -1
- data/Rakefile +4 -3
- data/coverage/.last_run.json +1 -1
- data/lib/lmc.rb +16 -3
- data/lib/lmc/Account.rb +21 -5
- data/lib/lmc/Cloud.rb +34 -15
- data/lib/lmc/config/device_config.rb +3 -2
- data/lib/lmc/entity.rb +2 -2
- data/lib/lmc/logger.rb +1 -1
- data/lib/lmc/mixins/service_resource.rb +0 -7
- data/lib/lmc/preferences/preferences.rb +24 -0
- data/lib/lmc/version.rb +1 -1
- data/lmc.gemspec +2 -2
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ea7050b8975d248f8f6c341c900a0987fea13b061ab262d87ab1862aa2a9d169
|
4
|
+
data.tar.gz: 00d0fe53b221e06a8f1185c6eca7b48387038d95fb271d466f3b48f5e0761790
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83ef7581a5c3ea7efbfa7245b7238b29a060acca4544c5157074609671dfb4c61e2c1100a1bcf769722a70f870cccb91df56c8ad83baf98db183cb74dd5ee093
|
7
|
+
data.tar.gz: f9e91e63ff73a690108bb62cb046d8d342e7017e5edd9e6cdb2715f112b0b8df9a0320ab8ab5cf70cbeb73e5070f1aeda18852d2afad649b6f80b1a771391d2e
|
@@ -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
@@ -1,6 +1,8 @@
|
|
1
|
-
Layout/
|
1
|
+
Layout/TrailingEmptyLines:
|
2
2
|
EnforcedStyle: final_blank_line
|
3
|
-
Layout/
|
3
|
+
Layout/FirstHashElementIndentation:
|
4
4
|
IndentationWidth: 4
|
5
|
-
|
5
|
+
Layout/LineLength:
|
6
6
|
Max: 110
|
7
|
+
Style/IfUnlessModifier:
|
8
|
+
Enabled: false
|
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
|
data/coverage/.last_run.json
CHANGED
data/lib/lmc.rb
CHANGED
@@ -5,10 +5,23 @@ require 'restclient'
|
|
5
5
|
|
6
6
|
module LMC
|
7
7
|
SERVICELIST = ['cloud-service-auth',
|
8
|
+
'cloud-service-backstage',
|
9
|
+
'cloud-service-config',
|
8
10
|
'cloud-service-devices',
|
11
|
+
'cloud-service-devicetunnel',
|
12
|
+
'cloud-service-dyndns',
|
13
|
+
'cloud-service-fields',
|
14
|
+
'cloud-service-geolocation',
|
15
|
+
'cloud-service-hotspot',
|
16
|
+
'cloud-service-jobs',
|
9
17
|
'cloud-service-monitoring',
|
10
|
-
'cloud-service-
|
11
|
-
'cloud-service-
|
18
|
+
'cloud-service-messaging',
|
19
|
+
'cloud-service-notification',
|
20
|
+
'cloud-service-licenses',
|
21
|
+
'cloud-service-logging',
|
22
|
+
'cloud-service-preferences',
|
23
|
+
'cloud-service-uf-translator'
|
24
|
+
]
|
12
25
|
|
13
26
|
def self.useful
|
14
27
|
true
|
@@ -23,7 +36,7 @@ Dir.glob(File.expand_path('../lmc/*.rb', __FILE__)).each do |file|
|
|
23
36
|
require file
|
24
37
|
end
|
25
38
|
|
26
|
-
['exceptions', 'auth', 'config', 'monitoring'].each do |folder|
|
39
|
+
['exceptions', 'auth', 'config', 'monitoring', 'preferences'].each do |folder|
|
27
40
|
Dir.glob(File.expand_path("../lmc/#{folder}/*.rb", __FILE__)).each do |file|
|
28
41
|
require file
|
29
42
|
end
|
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
|
@@ -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
|
data/lib/lmc/Cloud.rb
CHANGED
@@ -7,22 +7,24 @@ require 'restclient'
|
|
7
7
|
module LMC
|
8
8
|
class Cloud
|
9
9
|
class << self
|
10
|
-
attr_accessor :cloud_host, :user, :password, :verbose, :debug, :verify_tls, :use_tls
|
10
|
+
attr_accessor :cloud_host, :user, :password, :code, :verbose, :debug, :verify_tls, :use_tls
|
11
11
|
Cloud.use_tls = true
|
12
12
|
Cloud.verify_tls = true
|
13
|
+
Cloud.code = nil
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.instance(opts = { authorize: true })
|
16
|
-
@@inst ||= new(@cloud_host, @user, @password, opts[:authorize])
|
17
|
+
@@inst ||= new(@cloud_host, @user, @password, @code, opts[:authorize])
|
17
18
|
end
|
18
19
|
|
19
20
|
attr_reader :auth_ok, :cloud_host, :user, :password
|
20
21
|
|
21
|
-
def initialize(cloud_host, user,
|
22
|
+
def initialize(cloud_host, user, password, code = nil, auth = true)
|
22
23
|
@auth_ok = false
|
23
24
|
@cloud_host = cloud_host
|
24
25
|
@user = user
|
25
|
-
@password =
|
26
|
+
@password = password
|
27
|
+
@code = code
|
26
28
|
@verify_tls = Cloud.verify_tls
|
27
29
|
@last_authorized_account_ids = nil
|
28
30
|
@logger ||= ::LMC::Logger.new(STDOUT) if Cloud.debug
|
@@ -31,7 +33,7 @@ module LMC
|
|
31
33
|
authorize if auth
|
32
34
|
end
|
33
35
|
|
34
|
-
# hide
|
36
|
+
# hide secret fields from being displayed in dumps
|
35
37
|
def inspect
|
36
38
|
"#<Cloud:#{object_id}, #{build_url}>"
|
37
39
|
end
|
@@ -63,6 +65,11 @@ module LMC
|
|
63
65
|
post ['cloud-service-auth', 'accounts', account_id, 'members'], body
|
64
66
|
end
|
65
67
|
|
68
|
+
# @param section Array of String to indicate section to access. Example: ['principal', 'self', 'ui']
|
69
|
+
def preferences(section)
|
70
|
+
LMC::Preferences.new cloud: self, section: section
|
71
|
+
end
|
72
|
+
|
66
73
|
def get(path, params = nil)
|
67
74
|
prepared_headers = headers
|
68
75
|
prepared_headers[:params] = params
|
@@ -74,31 +81,37 @@ module LMC
|
|
74
81
|
execute_request args
|
75
82
|
end
|
76
83
|
|
77
|
-
def put(path, body_object)
|
84
|
+
def put(path, body_object, params = nil)
|
85
|
+
prepared_headers = headers
|
86
|
+
prepared_headers[:params] = params
|
78
87
|
args = {
|
79
88
|
:method => :put,
|
80
89
|
:url => build_url(path),
|
81
|
-
:payload => body_object.to_json
|
82
|
-
|
90
|
+
:payload => body_object.to_json,
|
91
|
+
:headers => prepared_headers
|
83
92
|
}
|
84
93
|
execute_request args
|
85
94
|
end
|
86
95
|
|
87
|
-
def post(path, body_object)
|
96
|
+
def post(path, body_object, params=nil )
|
97
|
+
prepared_headers = headers
|
98
|
+
prepared_headers[:params] = params
|
88
99
|
args = {
|
89
100
|
:method => :post,
|
90
101
|
:url => build_url(path),
|
91
|
-
:payload => body_object.to_json
|
102
|
+
:payload => body_object.to_json,
|
103
|
+
:headers => prepared_headers
|
92
104
|
}
|
93
105
|
execute_request args
|
94
106
|
end
|
95
107
|
|
96
|
-
def delete(path,
|
108
|
+
def delete(path, params = nil)
|
109
|
+
prepared_headers = headers
|
110
|
+
prepared_headers[:params] = params
|
97
111
|
args = {
|
98
112
|
:method => :delete,
|
99
113
|
:url => build_url(path),
|
100
|
-
:
|
101
|
-
:headers => headers
|
114
|
+
:headers => prepared_headers
|
102
115
|
}
|
103
116
|
execute_request args
|
104
117
|
end
|
@@ -142,7 +155,12 @@ module LMC
|
|
142
155
|
}
|
143
156
|
if account_ids != @last_authorized_account_ids
|
144
157
|
begin
|
145
|
-
reply = post(['cloud-service-auth', 'auth'],
|
158
|
+
reply = post(['cloud-service-auth', 'auth'],
|
159
|
+
name: @user,
|
160
|
+
password: @password,
|
161
|
+
code: @code,
|
162
|
+
accountIds: account_ids,
|
163
|
+
termsOfUse: tos)
|
146
164
|
@last_authorized_account_ids = account_ids
|
147
165
|
@auth_token = reply
|
148
166
|
@auth_ok = true
|
@@ -151,6 +169,7 @@ module LMC
|
|
151
169
|
if response['code'] == 100
|
152
170
|
raise LMC::OutdatedTermsOfUseException.new(response)
|
153
171
|
end
|
172
|
+
raise e
|
154
173
|
end
|
155
174
|
end
|
156
175
|
end
|
@@ -180,7 +199,7 @@ module LMC
|
|
180
199
|
internal_args.merge! args
|
181
200
|
begin
|
182
201
|
resp = RestClient::Request.execute internal_args
|
183
|
-
|
202
|
+
LMCResponse.new(resp)
|
184
203
|
rescue RestClient::ExceptionWithResponse => e
|
185
204
|
if Cloud.debug
|
186
205
|
puts 'EXCEPTION: ' + e.to_s
|
@@ -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
|
|
data/lib/lmc/entity.rb
CHANGED
data/lib/lmc/logger.rb
CHANGED
@@ -5,7 +5,7 @@ module LMC
|
|
5
5
|
class Logger < ::Logger
|
6
6
|
@cloud = nil
|
7
7
|
attr_accessor :cloud
|
8
|
-
@@header_token_re = /"Authorization"=>"Bearer ([\S
|
8
|
+
@@header_token_re = /"Authorization"=>"Bearer ([\S]*)"/
|
9
9
|
def <<(line)
|
10
10
|
value_found = @@header_token_re.match line
|
11
11
|
if value_found
|
@@ -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
|
@@ -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/version.rb
CHANGED
data/lmc.gemspec
CHANGED
@@ -32,13 +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
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.13.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:
|
11
|
+
date: 2021-01-15 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
|
@@ -150,7 +150,7 @@ dependencies:
|
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '2.0'
|
153
|
-
description:
|
153
|
+
description:
|
154
154
|
email:
|
155
155
|
- philipp@copythat.de
|
156
156
|
executables: []
|
@@ -195,16 +195,17 @@ 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
|
201
202
|
- lmc.gemspec
|
202
203
|
- misc/debug_log_experiment.rb
|
203
|
-
homepage:
|
204
|
+
homepage:
|
204
205
|
licenses:
|
205
206
|
- BSD-3-Clause
|
206
207
|
metadata: {}
|
207
|
-
post_install_message:
|
208
|
+
post_install_message:
|
208
209
|
rdoc_options: []
|
209
210
|
require_paths:
|
210
211
|
- lib
|
@@ -219,9 +220,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
220
|
- !ruby/object:Gem::Version
|
220
221
|
version: '0'
|
221
222
|
requirements: []
|
222
|
-
|
223
|
-
|
224
|
-
signing_key:
|
223
|
+
rubygems_version: 3.1.2
|
224
|
+
signing_key:
|
225
225
|
specification_version: 4
|
226
226
|
summary: Library for interacting with LMC cloud instances
|
227
227
|
test_files: []
|