lmc 0.8.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LMC
4
+ class DeviceDSCUi
5
+ def initialize(device)
6
+ @device = device
7
+ @body = @device.cloud.get(url_dscui).body
8
+
9
+ @version = Version.new @body['versions']
10
+ end
11
+
12
+ def url_dscui
13
+ ['cloud-service-config', 'configdevice', 'accounts', @device.account.id, 'devices',
14
+ @device.id, 'dscui']
15
+ end
16
+
17
+ def item_by_id_map
18
+ item_map = {}
19
+ item_map.default = Item.dummy
20
+ @version.items.inject(item_map) do |acc, item|
21
+ acc.store(item.id, item)
22
+ acc
23
+ end
24
+ item_map
25
+ end
26
+
27
+ class Version
28
+ attr_reader :version_string, :sections
29
+
30
+ def initialize(v_hash)
31
+ keys = v_hash.keys
32
+ raise('More than one version key contained in dscui.') if keys.length > 1
33
+ @version_string = keys.first
34
+ @sections = v_hash[@version_string].map { |section_wrapper| Section.new section_wrapper }
35
+
36
+ end
37
+
38
+ def items
39
+ @sections.map {
40
+ |s| s.groups.map {
41
+ |g| g.items
42
+ }
43
+ }.flatten.compact
44
+ end
45
+ end
46
+
47
+ class Section
48
+ attr_reader :names, :groups
49
+
50
+ def initialize(section_wrapper)
51
+ section = section_wrapper['section']
52
+ @names = section['name']
53
+ members = section['members']
54
+ @groups = members.map { |group_wrapper|
55
+ Group.new group_wrapper unless group_wrapper['group'].nil?
56
+ }.compact
57
+
58
+ end
59
+ end
60
+
61
+ class Group
62
+ attr_reader :names, :items
63
+
64
+ def initialize(group_wrapper)
65
+ group = group_wrapper['group']
66
+ @names = group['name']
67
+ @items = group['members'].map { |item_wrapper| Item.new item_wrapper }
68
+ end
69
+ end
70
+
71
+ class Item
72
+ attr_reader :type, :id
73
+
74
+ def self.dummy
75
+ Item.new('dummy' => { 'description' => [] })
76
+ end
77
+
78
+ def initialize(item_wrapper)
79
+ keys = item_wrapper.keys
80
+ raise('More than one key contained in item wrapper') if keys.length > 1
81
+ @type = keys.first
82
+ item = item_wrapper[@type]
83
+ @id = item['id']
84
+ @descriptions = []
85
+ @descriptions << item['description']
86
+ end
87
+
88
+ def description
89
+ @descriptions.join(',')
90
+ end
91
+ end
92
+ end
93
+ end
94
+
@@ -3,6 +3,6 @@
3
3
  require 'ostruct'
4
4
  module LMC
5
5
  class DeviceConfigState < OpenStruct
6
-
7
6
  end
8
7
  end
8
+
@@ -2,18 +2,18 @@
2
2
 
3
3
  module LMC
4
4
  class Entity
5
- def self.get_by_uuid_or_name term
6
- raise "Missing argument" if term.nil?
5
+ def self.get_by_uuid_or_name(term)
6
+ raise 'Missing argument' if term.nil?
7
7
  begin
8
- return self.get_by_uuid term
8
+ get_by_uuid term
9
9
  rescue RestClient::BadRequest, URI::InvalidURIError
10
- return self.get_by_name term
10
+ get_by_name term
11
11
  end
12
12
  end
13
13
 
14
- def [] key
15
- self.send(key)
14
+ def [](key)
15
+ send(key)
16
16
  end
17
-
18
17
  end
19
- end
18
+ end
19
+
@@ -12,12 +12,12 @@ module LMC
12
12
  r += "Name: #{tos['name']}, Date #{tos['acceptance']}\n"
13
13
 
14
14
  end
15
- return r
15
+ r
16
16
  end
17
+
17
18
  def missing
18
19
  @response['details']['missing']
19
20
  end
20
21
  end
21
-
22
-
23
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
- end
18
+ end
19
+
@@ -6,12 +6,12 @@ module LMC
6
6
 
7
7
  def to_json(*a)
8
8
  {
9
- "name" => @name,
10
- "type" => @type,
11
- "state" => @state,
12
- "authorities" => @authorities
9
+ 'name' => @name,
10
+ 'type' => @type,
11
+ 'state' => @state,
12
+ 'authorities' => @authorities
13
13
  }.to_json(*a)
14
14
  end
15
-
16
15
  end
17
16
  end
17
+
@@ -6,11 +6,12 @@ module LMC::JSONAble
6
6
  def to_json
7
7
  hash = {}
8
8
  self.class.resource_attributes.each do |var|
9
- val = self.instance_variable_get "@#{var}"
9
+ val = instance_variable_get "@#{var}"
10
10
  hash[var] = val unless val.nil?
11
11
  end
12
12
  hash.to_json
13
13
  end
14
14
  end
15
15
  end
16
- end
16
+ end
17
+
@@ -9,32 +9,27 @@ 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
12
+
15
13
  # method that wraps attr_accessor to keep the defined attrs in a class instance var for serializing
16
14
  def self.resource_attrs(*attrs)
17
15
  @resource_attributes ||= []
18
16
  @resource_attributes.concat attrs
19
17
  attr_accessor(*attrs)
20
18
  end
19
+
21
20
  def self.resource_attributes
22
21
  @resource_attributes
23
22
  end
24
23
  end
25
24
  end
26
- def method_on_instance_of_class
27
- puts("cloud-service-#{service_name} #{self.inspect}, #{@cloud}")
28
- end
25
+
29
26
  def collection_path
30
27
  ["cloud-service-#{service_name}", collection_name]
31
28
  end
32
29
 
33
-
34
30
  def post
35
31
  @cloud.post collection_path, self
36
32
  end
37
-
38
-
39
33
  end
40
- end
34
+ end
35
+
@@ -15,19 +15,20 @@ module LMC
15
15
  @grouping = grouping
16
16
  end
17
17
 
18
- def scalar name, count, period
18
+ def scalar(name, count, period)
19
19
  fetch_data name, count, period, 'scalar'
20
20
  end
21
21
 
22
- def row name, count, period
22
+ def row(name, count, period)
23
23
  fetch_data name, count, period, 'row'
24
24
  end
25
25
 
26
26
  private
27
27
 
28
28
  def fetch_data(name, count, period, type, relative = 0)
29
- r = @cloud.get record_url, { count: count, group: @grouping.monitor_record_group, groupId: @grouping.id, name: name, period: period, relative: relative, type: type }
29
+ r = @cloud.get record_url, count: count, group: @grouping.monitor_record_group, groupId: @grouping.id, name: name, period: period, relative: relative, type: type
30
30
  r.body
31
31
  end
32
32
  end
33
- end
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
+
@@ -15,16 +15,16 @@ module LMC
15
15
  apply_data(data)
16
16
  end
17
17
 
18
- #returns itself, allows chaining
18
+ # returns itself, allows chaining
19
19
  def save
20
20
  response = if @id.nil?
21
- Cloud.instance.post ["cloud-service-auth", "principals"], self
21
+ Cloud.instance.post ['cloud-service-auth', 'principals'], self
22
22
  else
23
- raise "editing principals not supported"
24
- #@cloud.put ["cloud-service-auth", "principals", @id], self
23
+ raise 'editing principals not supported'
24
+ # @cloud.put ["cloud-service-auth", "principals", @id], self
25
25
  end
26
26
  apply_data(response)
27
- return self
27
+ self
28
28
  end
29
29
 
30
30
  def to_s
@@ -33,9 +33,9 @@ module LMC
33
33
 
34
34
  def to_json(*a)
35
35
  {
36
- "name" => @name,
37
- "type" => @type,
38
- "password" => @password
36
+ 'name' => @name,
37
+ 'type' => @type,
38
+ 'password' => @password
39
39
  }.to_json(*a)
40
40
  end
41
41
 
@@ -52,3 +52,4 @@ module LMC
52
52
  end
53
53
  end
54
54
  end
55
+
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LMC
4
+ # Represents a UUID
5
+ class UUID
6
+ def initialize(string)
7
+ uuid_re = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i
8
+ raise "#{string} is not recognized as a valid uuid string." unless uuid_re.match? string
9
+ @string = string
10
+ end
11
+
12
+ def to_s
13
+ @string
14
+ end
15
+ end
16
+ end
17
+
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LMC
4
- VERSION = '0.8.0'
4
+ VERSION = '0.12.0'
5
5
  end
6
+
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('../lib', __FILE__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require "lmc/version"
5
+ require 'lmc/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = "lmc"
8
+ spec.name = 'lmc'
9
9
  spec.version = LMC::VERSION
10
- spec.authors = ["erpel"]
11
- spec.email = ["philipp@copythat.de"]
10
+ spec.authors = ['erpel']
11
+ spec.email = ['philipp@copythat.de']
12
12
 
13
13
  spec.summary = %q{Library for interacting with LMC cloud instances}
14
14
  spec.license = 'BSD-3-Clause'
@@ -16,27 +16,29 @@ Gem::Specification.new do |spec|
16
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
17
  # to allow pushing to a single host or delete this section to allow pushing to any host.
18
18
  if spec.respond_to?(:metadata)
19
- #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
20
  else
21
- raise "RubyGems 2.0 or newer is required to protect against " \
22
- "public gem pushes."
21
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
22
+ 'public gem pushes.'
23
23
  end
24
24
 
25
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
26
  f.match(%r{^(test|spec|features)/})
27
27
  end
28
- spec.bindir = "exe"
28
+ spec.bindir = 'exe'
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
30
+ spec.require_paths = ['lib']
31
31
 
32
- spec.add_development_dependency 'bundler', '~> 1.16'
33
- spec.add_development_dependency 'minitest', '~> 5.0'
32
+ spec.add_development_dependency 'bundler', '~> 2.0'
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
+ spec.add_development_dependency 'rubocop', '~> 0.58.1'
39
40
 
40
- spec.add_runtime_dependency 'json', '~> 2.0'
41
+ spec.add_runtime_dependency 'json', '~> 2.3'
41
42
  spec.add_runtime_dependency 'rest-client', '~> 2.0'
42
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.8.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - erpel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-22 00:00:00.000000000 Z
11
+ date: 2020-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: '5.11'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.0'
40
+ version: '5.11'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest-reporters
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -108,20 +108,34 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.2.4
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.58.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.58.1
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: json
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '2.0'
131
+ version: '2.3'
118
132
  type: :runtime
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '2.0'
138
+ version: '2.3'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rest-client
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -145,15 +159,16 @@ extra_rdoc_files: []
145
159
  files:
146
160
  - ".gitignore"
147
161
  - ".idea/codeStyles/codeStyleConfig.xml"
162
+ - ".idea/encodings.xml"
148
163
  - ".idea/inspectionProfiles/Project_Default.xml"
149
164
  - ".idea/runConfigurations/tests.xml"
150
165
  - ".idea/vcs.xml"
151
166
  - ".rubocop.yml"
152
167
  - ".ruby-version"
153
- - ".travis.yml"
154
168
  - Gemfile
155
169
  - LICENSE.txt
156
- - README.md
170
+ - PATTERNS.md
171
+ - README.rdoc
157
172
  - Rakefile
158
173
  - bin/console
159
174
  - bin/setup
@@ -170,6 +185,8 @@ files:
170
185
  - lib/lmc/account_manager.rb
171
186
  - lib/lmc/auth/auth_action.rb
172
187
  - lib/lmc/authority.rb
188
+ - lib/lmc/config/device_config.rb
189
+ - lib/lmc/config/device_dsc_ui.rb
173
190
  - lib/lmc/device_config_state.rb
174
191
  - lib/lmc/entity.rb
175
192
  - lib/lmc/exceptions/lmc_outdated_terms_of_use_exception.rb
@@ -178,7 +195,9 @@ files:
178
195
  - lib/lmc/mixins/json_able.rb
179
196
  - lib/lmc/mixins/service_resource.rb
180
197
  - lib/lmc/monitoring/monitoring_record.rb
198
+ - lib/lmc/preferences/preferences.rb
181
199
  - lib/lmc/principal.rb
200
+ - lib/lmc/uuid.rb
182
201
  - lib/lmc/version.rb
183
202
  - lmc.gemspec
184
203
  - misc/debug_log_experiment.rb
@@ -201,8 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
220
  - !ruby/object:Gem::Version
202
221
  version: '0'
203
222
  requirements: []
204
- rubyforge_project:
205
- rubygems_version: 2.6.11
223
+ rubygems_version: 3.1.2
206
224
  signing_key:
207
225
  specification_version: 4
208
226
  summary: Library for interacting with LMC cloud instances