lmc 0.9.0 → 0.12.1

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: 4cf28191aafd359f60cc8d8d3eb7b9c4ffb4ff6a
4
- data.tar.gz: 109b27a7784b63820b94a63d04ca53174a59a687
2
+ SHA256:
3
+ metadata.gz: cfd78ebb37da9e527f2da6cdf0d7297994c49031cef7af9ce0534f86d2d66b01
4
+ data.tar.gz: bada57081f44bbdd303ebf2ebedee80c0e6c21be9e354614ba976ca96d4bc627
5
5
  SHA512:
6
- metadata.gz: 2ce921af5e82516e865bb5241719f7efb09b90dfac67d6d82402ffa06bc4b27bd108735784b25cccff56e0c2193e8c8c198ad879d443b9ea723353b93bb0a1bc
7
- data.tar.gz: db341afd04ed21951870cd9a982c27d0bf93eee1a9872dce292bc6c9f324e27d62ca66021709cb7d9a04a09d709f2ca1154bb7eec7cb18a22baece62f4775492
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="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,4 +1,8 @@
1
- Layout/IndentHash:
1
+ Layout/TrailingEmptyLines:
2
+ EnforcedStyle: final_blank_line
3
+ Layout/FirstHashElementIndentation:
2
4
  IndentationWidth: 4
3
- Metrics/LineLength:
5
+ Layout/LineLength:
4
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
@@ -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
+
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "result": {
3
- "covered_percent": 90.56
3
+ "covered_percent": 91.59
4
4
  }
5
5
  }
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
+
@@ -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
@@ -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'], {:select => :id}
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
+
@@ -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, body_object = nil)
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
- :payload => body_object.to_json,
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
- return LMCResponse.new(resp)
194
+ LMCResponse.new(resp)
185
195
  rescue RestClient::ExceptionWithResponse => e
186
- print_exception e if Cloud.debug
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
+
@@ -12,3 +12,4 @@ module LMC
12
12
  end
13
13
  end
14
14
  end
15
+
@@ -77,3 +77,4 @@ module LMC
77
77
  end
78
78
  end
79
79
  end
80
+
@@ -59,3 +59,4 @@ module LMC
59
59
  end
60
60
  end
61
61
  end
62
+
@@ -27,3 +27,4 @@ module LMC
27
27
  end
28
28
  end
29
29
  end
30
+
@@ -38,3 +38,4 @@ module LMC
38
38
  end
39
39
  end
40
40
  end
41
+
@@ -83,3 +83,4 @@ END
83
83
  end
84
84
  end
85
85
  end
86
+
@@ -20,3 +20,4 @@ module LMC
20
20
  end
21
21
  end
22
22
  end
23
+
@@ -52,3 +52,4 @@ module LMC
52
52
  end
53
53
  end
54
54
  end
55
+
@@ -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
 
@@ -190,3 +191,4 @@ module LMC
190
191
  # end
191
192
  end
192
193
  end
194
+
@@ -91,3 +91,4 @@ module LMC
91
91
  end
92
92
  end
93
93
  end
94
+
@@ -5,3 +5,4 @@ module LMC
5
5
  class DeviceConfigState < OpenStruct
6
6
  end
7
7
  end
8
+
@@ -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
 
@@ -16,3 +16,4 @@ module LMC
16
16
  end
17
17
  end
18
18
  end
19
+
@@ -20,3 +20,4 @@ module LMC
20
20
  end
21
21
  end
22
22
  end
23
+
@@ -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
- super line.gsub @cloud.password, '********'
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
+
@@ -14,3 +14,4 @@ module LMC
14
14
  end
15
15
  end
16
16
  end
17
+
@@ -14,3 +14,4 @@ module LMC::JSONAble
14
14
  end
15
15
  end
16
16
  end
17
+
@@ -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
+
@@ -31,3 +31,4 @@ module LMC
31
31
  end
32
32
  end
33
33
  end
34
+
@@ -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
+
@@ -52,3 +52,4 @@ module LMC
52
52
  end
53
53
  end
54
54
  end
55
+
@@ -13,4 +13,5 @@ module LMC
13
13
  @string
14
14
  end
15
15
  end
16
- end
16
+ end
17
+
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LMC
4
- VERSION = '0.9.0'
4
+ VERSION = '0.12.1'
5
5
  end
6
+
@@ -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', '~> 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
+
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.9.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: 2019-11-23 00:00:00.000000000 Z
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: '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
@@ -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
- rubyforge_project:
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