lmc 0.8.0 → 0.9.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 +4 -4
- data/.idea/encodings.xml +4 -0
- data/.rubocop.yml +3 -1
- data/PATTERNS.md +26 -0
- data/{README.md → README.rdoc} +0 -0
- data/Rakefile +30 -7
- data/coverage/.last_run.json +1 -1
- data/lib/lmc.rb +2 -3
- data/lib/lmc/Account.rb +44 -46
- data/lib/lmc/Cloud.rb +19 -13
- data/lib/lmc/Configstates.rb +3 -5
- data/lib/lmc/Device.rb +17 -23
- data/lib/lmc/Response.rb +2 -4
- data/lib/lmc/Site.rb +10 -21
- data/lib/lmc/User.rb +9 -11
- data/lib/lmc/account_manager.rb +28 -28
- data/lib/lmc/auth/auth_action.rb +2 -2
- data/lib/lmc/authority.rb +10 -9
- data/lib/lmc/config/device_config.rb +192 -0
- data/lib/lmc/config/device_dsc_ui.rb +93 -0
- data/lib/lmc/device_config_state.rb +0 -1
- data/lib/lmc/entity.rb +7 -8
- data/lib/lmc/exceptions/lmc_outdated_terms_of_use_exception.rb +2 -3
- data/lib/lmc/logger.rb +1 -1
- data/lib/lmc/membership.rb +4 -5
- data/lib/lmc/mixins/json_able.rb +2 -2
- data/lib/lmc/mixins/service_resource.rb +6 -5
- data/lib/lmc/monitoring/monitoring_record.rb +4 -4
- data/lib/lmc/principal.rb +8 -8
- data/lib/lmc/uuid.rb +16 -0
- data/lib/lmc/version.rb +1 -1
- data/lmc.gemspec +14 -13
- metadata +26 -8
- data/.travis.yml +0 -5
@@ -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
|
data/lib/lmc/entity.rb
CHANGED
@@ -2,18 +2,17 @@
|
|
2
2
|
|
3
3
|
module LMC
|
4
4
|
class Entity
|
5
|
-
def self.get_by_uuid_or_name
|
6
|
-
raise
|
5
|
+
def self.get_by_uuid_or_name(term)
|
6
|
+
raise 'Missing argument' if term.nil?
|
7
7
|
begin
|
8
|
-
return
|
8
|
+
return get_by_uuid term
|
9
9
|
rescue RestClient::BadRequest, URI::InvalidURIError
|
10
|
-
return
|
10
|
+
return get_by_name term
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def []
|
15
|
-
|
14
|
+
def [](key)
|
15
|
+
send(key)
|
16
16
|
end
|
17
|
-
|
18
17
|
end
|
19
|
-
end
|
18
|
+
end
|
data/lib/lmc/logger.rb
CHANGED
data/lib/lmc/membership.rb
CHANGED
@@ -6,12 +6,11 @@ module LMC
|
|
6
6
|
|
7
7
|
def to_json(*a)
|
8
8
|
{
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
data/lib/lmc/mixins/json_able.rb
CHANGED
@@ -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 =
|
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} #{
|
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
|
18
|
+
def scalar(name, count, period)
|
19
19
|
fetch_data name, count, period, 'scalar'
|
20
20
|
end
|
21
21
|
|
22
|
-
def row
|
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,
|
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
|
data/lib/lmc/principal.rb
CHANGED
@@ -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 [
|
21
|
+
Cloud.instance.post ['cloud-service-auth', 'principals'], self
|
22
22
|
else
|
23
|
-
raise
|
24
|
-
|
23
|
+
raise 'editing principals not supported'
|
24
|
+
# @cloud.put ["cloud-service-auth", "principals", @id], self
|
25
25
|
end
|
26
26
|
apply_data(response)
|
27
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
36
|
+
'name' => @name,
|
37
|
+
'type' => @type,
|
38
|
+
'password' => @password
|
39
39
|
}.to_json(*a)
|
40
40
|
end
|
41
41
|
|
data/lib/lmc/uuid.rb
ADDED
@@ -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
|
data/lib/lmc/version.rb
CHANGED
data/lmc.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require 'lmc/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
8
|
+
spec.name = 'lmc'
|
9
9
|
spec.version = LMC::VERSION
|
10
|
-
spec.authors = [
|
11
|
-
spec.email = [
|
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
|
22
|
-
|
21
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
22
|
+
'public gem pushes.'
|
23
23
|
end
|
24
24
|
|
25
|
-
spec.files
|
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 =
|
28
|
+
spec.bindir = 'exe'
|
29
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
-
spec.require_paths = [
|
30
|
+
spec.require_paths = ['lib']
|
31
31
|
|
32
|
-
spec.add_development_dependency 'bundler', '~>
|
33
|
-
spec.add_development_dependency 'minitest', '~> 5.
|
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.
|
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:
|
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: '
|
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: '
|
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.
|
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.
|
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
|
-
-
|
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
|