lmc 0.10.0 → 0.13.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
- SHA1:
3
- metadata.gz: 00ee8363416f6202be68b106dcf805e7e6166c03
4
- data.tar.gz: ef7c4be2c2dd0e9dc38294f9062c02f1a5b3f1df
2
+ SHA256:
3
+ metadata.gz: ea7050b8975d248f8f6c341c900a0987fea13b061ab262d87ab1862aa2a9d169
4
+ data.tar.gz: 00d0fe53b221e06a8f1185c6eca7b48387038d95fb271d466f3b48f5e0761790
5
5
  SHA512:
6
- metadata.gz: 74a1b17a56e44a69de7f726bedb1f8779c4125f96c67483b1c9b0a8a35ef555a5e33208b0d4c3f6d8f87d2343c46adacaeacaf80db1cbd0b6be7d61e40b752d3
7
- data.tar.gz: 8f51ec09ad3a76c781c3755421fad500c16a977311a94ac14a3990e0d513a90d7ba3dc6a6ad68351bfe5769382f41a8824bb8bed894ec09e375d08e77bb415c0
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="true" level="WARNING" enabled_by_default="true">
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">
@@ -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,6 +1,8 @@
1
- Layout/TrailingBlankLines:
1
+ Layout/TrailingEmptyLines:
2
2
  EnforcedStyle: final_blank_line
3
- Layout/IndentFirstHashElement:
3
+ Layout/FirstHashElementIndentation:
4
4
  IndentationWidth: 4
5
- Metrics/LineLength:
5
+ Layout/LineLength:
6
6
  Max: 110
7
+ Style/IfUnlessModifier:
8
+ Enabled: false
@@ -1 +1 @@
1
- 2.4.1
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/TrailingBlankLines',
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
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "result": {
3
- "covered_percent": 90.74
3
+ "covered_percent": 91.6
4
4
  }
5
5
  }
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-config',
11
- 'cloud-service-licenses']
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
@@ -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
- return accounts[0]
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
- members.find { |m| m.name == name }
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([id, ROOT_ACCOUNT_UUID])
120
- response = @cloud.get ['cloud-service-auth', 'accounts', id, 'children']
121
- response.map { |child| Account.new @cloud, child }
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
@@ -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, pass, auth = true)
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 = pass
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 password from dumps
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, body_object = nil)
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
- :payload => body_object.to_json,
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'], name: @user, password: @password, accountIds: account_ids, termsOfUse: tos)
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
- return LMCResponse.new(resp)
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 'Too many attempts' if attempts > tries
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 0.5
185
+ sleep wait_seconds * attempts
185
186
  end
186
187
  end
187
188
 
@@ -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
- return get_by_uuid term
8
+ get_by_uuid term
9
9
  rescue RestClient::BadRequest, URI::InvalidURIError
10
- return get_by_name term
10
+ get_by_name term
11
11
  end
12
12
  end
13
13
 
@@ -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
+
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LMC
4
- VERSION = '0.10.0'
4
+ VERSION = '0.13.0'
5
5
  end
6
6
 
@@ -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', '~> 10.0'
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.0'
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.10.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: 2019-11-24 00:00:00.000000000 Z
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: '10.0'
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: '10.0'
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.0'
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.0'
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
- rubyforge_project:
223
- rubygems_version: 2.6.11
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: []