lmc 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,93 @@
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
@@ -3,6 +3,5 @@
3
3
  require 'ostruct'
4
4
  module LMC
5
5
  class DeviceConfigState < OpenStruct
6
-
7
6
  end
8
7
  end
@@ -2,18 +2,17 @@
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
+ return get_by_uuid term
9
9
  rescue RestClient::BadRequest, URI::InvalidURIError
10
- return self.get_by_name term
10
+ return 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
@@ -12,12 +12,11 @@ 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
@@ -9,4 +9,4 @@ module LMC
9
9
  super line.gsub @cloud.password, '********'
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -6,12 +6,11 @@ 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
@@ -6,11 +6,11 @@ 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
@@ -12,29 +12,30 @@ module LMC
12
12
  def methodtest
13
13
  puts("cloud-service-#{service_name}")
14
14
  end
15
+
15
16
  # method that wraps attr_accessor to keep the defined attrs in a class instance var for serializing
16
17
  def self.resource_attrs(*attrs)
17
18
  @resource_attributes ||= []
18
19
  @resource_attributes.concat attrs
19
20
  attr_accessor(*attrs)
20
21
  end
22
+
21
23
  def self.resource_attributes
22
24
  @resource_attributes
23
25
  end
24
26
  end
25
27
  end
28
+
26
29
  def method_on_instance_of_class
27
- puts("cloud-service-#{service_name} #{self.inspect}, #{@cloud}")
30
+ puts("cloud-service-#{service_name} #{inspect}, #{@cloud}")
28
31
  end
32
+
29
33
  def collection_path
30
34
  ["cloud-service-#{service_name}", collection_name]
31
35
  end
32
36
 
33
-
34
37
  def post
35
38
  @cloud.post collection_path, self
36
39
  end
37
-
38
-
39
40
  end
40
- end
41
+ end
@@ -15,19 +15,19 @@ 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
@@ -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
 
@@ -0,0 +1,16 @@
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LMC
4
- VERSION = '0.8.0'
4
+ VERSION = '0.9.0'
5
5
  end
@@ -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,26 +16,27 @@ 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
35
  spec.add_development_dependency 'rake', '~> 10.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
41
  spec.add_runtime_dependency 'json', '~> 2.0'
41
42
  spec.add_runtime_dependency 'rest-client', '~> 2.0'
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.9.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: 2019-11-23 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
@@ -108,6 +108,20 @@ 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
@@ -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
@@ -179,6 +196,7 @@ files:
179
196
  - lib/lmc/mixins/service_resource.rb
180
197
  - lib/lmc/monitoring/monitoring_record.rb
181
198
  - lib/lmc/principal.rb
199
+ - lib/lmc/uuid.rb
182
200
  - lib/lmc/version.rb
183
201
  - lmc.gemspec
184
202
  - misc/debug_log_experiment.rb