lmc 0.7.0 → 0.8.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
2
  SHA1:
3
- metadata.gz: 1b427aa6fb475e2cae56564144444cc2e4ca76e7
4
- data.tar.gz: 6a780cc2a84e4417fc0172eb30d2b5d4a7d73284
3
+ metadata.gz: 31077763003e89d0d7d95ccf0882eca185921b9b
4
+ data.tar.gz: 20f58644eeb3bbf19f9a20142f6603147f028a51
5
5
  SHA512:
6
- metadata.gz: 4e3ee7fd714001efcdd496a246d694a616bd025b494816c34285a29333c3c5322a86f62c5c8b7529f2541a2f8f59e0640a14dddeb4ca62eec9e590215c3a43fc
7
- data.tar.gz: f42450556c13a9cf95c6d5e8d0dfb9731b6050b4fec980b83b44f52d5c356533e608d4f97109c3ae1409be9f78836cc5f43c0ea43d8a45f41af447fd5f96fed4
6
+ metadata.gz: 7eb1f25f826afe31759b6a553acd5fbeee9aaef610a09a9e280441d21390fca1e169fc00a1aa77ba81d7567940ecb5b7de3730658ee4cc93b7262fb79be04bd6
7
+ data.tar.gz: 2054e10d846866b107e70e12c6413adc863cf5a48a0b3399254db08c72e4f042b887bee326cb8d8efd3f2e5922c8fab2e372eabcf24ce644c9876548198c1035
@@ -0,0 +1,5 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
+ </state>
5
+ </component>
@@ -1,6 +1,9 @@
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">
5
+ <scope name="Tests" level="ERROR" enabled="true" />
6
+ </inspection_tool>
4
7
  <inspection_tool class="RubyInstanceMethodNamingConvention" enabled="true" level="WARNING" enabled_by_default="true">
5
8
  <scope name="Tests" level="WARNING" enabled="false" />
6
9
  </inspection_tool>
@@ -1,8 +1,8 @@
1
1
  <component name="ProjectRunConfigurationManager">
2
- <configuration default="false" name="tests" type="TestUnitRunConfigurationType" factoryName="Test::Unit/Shoulda/Minitest" show_console_on_std_err="true" show_console_on_std_out="true">
2
+ <configuration default="false" name="tests" type="TestUnitRunConfigurationType" factoryName="Test::Unit/Shoulda/Minitest">
3
3
  <predefined_log_file id="RUBY_TESTUNIT" enabled="true" />
4
- <module name="ruby-lmc" />
5
- <RTEST_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-I test" />
4
+ <module name="lmc" />
5
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="" />
6
6
  <RTEST_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="" />
7
7
  <RTEST_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
8
8
  <RTEST_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
data/Rakefile CHANGED
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
5
+ require 'rubocop/rake_task'
3
6
 
4
7
  Rake::TestTask.new(:test) do |t|
5
8
  t.libs << "test"
@@ -7,4 +10,8 @@ Rake::TestTask.new(:test) do |t|
7
10
  t.test_files = FileList["test/**/*_test.rb"]
8
11
  end
9
12
 
13
+
14
+ RuboCop::RakeTask.new(:autocop) do |t|
15
+ t.options = ['--only', 'Style/FrozenStringLiteralComment', '--auto-correct', 'lib', 'test', 'Rakefile', 'lmc.gemspec']
16
+ end
10
17
  task :default => :test
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "result": {
3
- "covered_percent": 80.54
3
+ "covered_percent": 84.99
4
4
  }
5
5
  }
data/lib/lmc.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'restclient'
3
5
 
@@ -13,15 +15,15 @@ module LMC
13
15
  end
14
16
  end
15
17
 
16
- Dir.glob(File.expand_path("../lmc/mixins/*.rb", __FILE__)).each do |file|
18
+ Dir.glob(File.expand_path('../lmc/mixins/*.rb', __FILE__)).each do |file|
17
19
  require file
18
20
  end
19
21
 
20
- Dir.glob(File.expand_path("../lmc/*.rb", __FILE__)).each do |file|
22
+ Dir.glob(File.expand_path('../lmc/*.rb', __FILE__)).each do |file|
21
23
  require file
22
24
  end
23
25
 
24
- ["exceptions", "auth"].each do |folder|
26
+ ['exceptions', 'auth', 'monitoring'].each do |folder|
25
27
  Dir.glob(File.expand_path("../lmc/#{folder}/*.rb", __FILE__)).each do |file|
26
28
  require file
27
29
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'account_manager.rb'
2
4
  require_relative 'entity'
3
5
  module LMC
4
6
  class Account < Entity
5
7
  ROOT_ACCOUNT_UUID = '9ec458c2-d05f-3004-96f0-ebe73fa20de8'
6
8
  attr_accessor :name
7
- attr_reader :id, :state, :type, :identifier
9
+ attr_reader :id, :state, :type, :identifier, :cloud
8
10
 
9
11
  def self.get(id)
10
12
  cloud = Cloud.instance
@@ -56,7 +58,7 @@ module LMC
56
58
  delete_action.name = Cloud.user
57
59
  delete_action.data = {'password' => Cloud.password,
58
60
  'accountId' => @id}
59
- deleted = delete_action.post
61
+ delete_action.post
60
62
  @id = nil
61
63
  return true
62
64
  end
@@ -151,7 +151,7 @@ module LMC
151
151
  end
152
152
 
153
153
  def auth_bearer
154
- 'Bearer ' + session_token
154
+ "Bearer #{session_token}"
155
155
  end
156
156
 
157
157
  def headers
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LMC
2
4
  class Configstates
3
5
  attr_reader :actual, :outdated
@@ -1,17 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LMC
2
4
  class Device
3
5
  attr_reader :id, :name, :model, :serial, :heartbeatstate
4
6
 
5
7
  def initialize(data)
6
- @cloud = Cloud.instance
7
- @id = data["id"]
8
- @comment = data["comment"]
9
- @name = data["status"]["name"]
10
- @serial = data["status"]["serial"]
11
- @model = data["status"]["model"]
12
- @heartbeatstate = data["status"]["heartbeatState"]
13
- @status = data["status"]
14
- @account = data["account"]
8
+ @id = data['id']
9
+ @comment = data['comment']
10
+ @name = data['status']['name']
11
+ @serial = data['status']['serial']
12
+ @model = data['status']['model']
13
+ @heartbeatstate = data['status']['heartbeatState']
14
+ @status = data['status']
15
+ @account = data['account']
16
+ @cloud = @account.cloud
17
+ @cloud ||= Cloud.instance
15
18
  end
16
19
 
17
20
  def get_config_for_account(account)
@@ -24,7 +27,7 @@ module LMC
24
27
  end
25
28
 
26
29
  def get_monitor_widgets(widget_item_ids)
27
- @cloud.get ["cloud-service-monitoring", @account.id, "devices", @id, "monitordata"], {:widgetItemIds => widget_item_ids.join(",")}
30
+ @cloud.get ["cloud-service-monitoring", @account.id, "devices", @id, "monitordata"], { :widgetItemIds => widget_item_ids.join(",") }
28
31
  end
29
32
 
30
33
  def self.get_for_account(account)
@@ -58,9 +61,18 @@ module LMC
58
61
  raise "device logs not supported"
59
62
  end
60
63
 
64
+ def record name
65
+ MonitoringRecord.new(@cloud, @account, self, name)
66
+ end
67
+
68
+ def monitor_record_group
69
+ 'DEVICE'
70
+ end
71
+
61
72
  private
73
+
62
74
  def get_config_state
63
- reply = @cloud.get ["cloud-service-config", "configdevice", "accounts", @account.id, "state"], {"deviceIds" => @id}
75
+ reply = @cloud.get ["cloud-service-config", "configdevice", "accounts", @account.id, "state"], { "deviceIds" => @id }
64
76
  if reply.code == 200
65
77
  # binding.pry
66
78
  DeviceConfigState.new reply.body[@id]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ostruct'
2
4
  module LMC
3
5
  class LMCResponse
@@ -33,6 +35,14 @@ module LMC
33
35
  @body_object[key]
34
36
  end
35
37
 
38
+ def []=(key, val)
39
+ @body_object[key] = val
40
+ end
41
+
42
+ def keys
43
+ @body_object.keys
44
+ end
45
+
36
46
  def map(&block)
37
47
  @body_object.map(&block)
38
48
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LMC
2
4
  class Site
3
5
  attr_accessor :name
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LMC
2
4
  class User
3
5
  #todo: look into hiding password
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LMC
2
4
  class AccountManager
3
5
  #@options
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LMC
2
4
  class AuthAction
3
5
  include LMC::ServiceResource
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LMC
2
4
  class Authority
3
5
  attr_accessor :account, :id, :name, :visibility, :type
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ostruct'
2
4
  module LMC
3
5
  class DeviceConfigState < OpenStruct
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LMC
2
4
  class Entity
3
5
  def self.get_by_uuid_or_name term
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LMC
2
4
  class OutdatedTermsOfUseException < Exception
3
5
  def initialize(response = {})
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LMC
2
4
  class Membership
3
5
  attr_accessor :name, :type, :state, :authorities
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LMC::JSONAble
2
4
  def self.included(klass)
3
5
  klass.class_exec do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LMC
2
4
  module ServiceResource
3
5
  def self.included(klass)
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LMC
4
+ class MonitoringRecord
5
+ # https://beta.cloud.lancom.de/cloud-service-monitoring/accounts/316f5f14-ff6c-4fd4-a49a-d28a6b3ba26c/records/uptime?count=144&
6
+ # group=DEVICE&groupId=8b2a3fef-2f7b-444c-86e7-1cf1b509e951&name=device&period=MINUTE10&relative=0&type=scalar
7
+ def record_url
8
+ ['cloud-service-monitoring', 'accounts', @account.id, 'records', @record_name]
9
+ end
10
+
11
+ def initialize(cloud, account, grouping, record_name)
12
+ @cloud = cloud
13
+ @account = account
14
+ @record_name = record_name
15
+ @grouping = grouping
16
+ end
17
+
18
+ def scalar name, count, period
19
+ fetch_data name, count, period, 'scalar'
20
+ end
21
+
22
+ def row name, count, period
23
+ fetch_data name, count, period, 'row'
24
+ end
25
+
26
+ private
27
+
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 }
30
+ r.body
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LMC
2
4
  class Principal
5
+ PRINCIPAL_URL_BASE = %w[cloud-service-auth users].freeze
6
+ attr_reader :id, :name, :password, :type
7
+
8
+ # this is actually a bad hack because the lmc api treats users different
9
+ # from principals.
10
+ def self.get_self(cloud)
11
+ new(cloud.get([PRINCIPAL_URL_BASE, 'self']))
12
+ end
13
+
3
14
  def initialize(data)
4
15
  apply_data(data)
5
16
  end
@@ -12,9 +23,14 @@ module LMC
12
23
  raise "editing principals not supported"
13
24
  #@cloud.put ["cloud-service-auth", "principals", @id], self
14
25
  end
15
- apply_data(response.body)
26
+ apply_data(response)
16
27
  return self
17
28
  end
29
+
30
+ def to_s
31
+ "#{@name} - #{@id}"
32
+ end
33
+
18
34
  def to_json(*a)
19
35
  {
20
36
  "name" => @name,
@@ -24,7 +40,11 @@ module LMC
24
40
  end
25
41
 
26
42
  private
43
+
27
44
  def apply_data(data)
45
+ data.keys.each do |k|
46
+ data[k.to_s] = data[k]
47
+ end
28
48
  @id = data['id']
29
49
  @name = data['name']
30
50
  @password = data['password']
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LMC
2
- VERSION = "0.7.0"
4
+ VERSION = '0.8.0'
3
5
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  lib = File.expand_path("../lib", __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
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.7.0
4
+ version: 0.8.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-10-28 00:00:00.000000000 Z
11
+ date: 2018-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -144,6 +144,7 @@ extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
146
  - ".gitignore"
147
+ - ".idea/codeStyles/codeStyleConfig.xml"
147
148
  - ".idea/inspectionProfiles/Project_Default.xml"
148
149
  - ".idea/runConfigurations/tests.xml"
149
150
  - ".idea/vcs.xml"
@@ -176,6 +177,7 @@ files:
176
177
  - lib/lmc/membership.rb
177
178
  - lib/lmc/mixins/json_able.rb
178
179
  - lib/lmc/mixins/service_resource.rb
180
+ - lib/lmc/monitoring/monitoring_record.rb
179
181
  - lib/lmc/principal.rb
180
182
  - lib/lmc/version.rb
181
183
  - lmc.gemspec