lmc 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3a6cc095210c99890c8ebb6b1c24f18fdee5ace
4
- data.tar.gz: c32528dfb1a87d9238db2c96f23297dbdd75660f
3
+ metadata.gz: d48faaacdbd824c7de50805b596093047f0d998b
4
+ data.tar.gz: 75157b26d52efbb46c47f6eaf79b617360e06e71
5
5
  SHA512:
6
- metadata.gz: 32ff5ff2362f3534b20e8dab058cc0faccf9f754fa7858b89e5693f26be5c7d2adab48af988660df597242323bcb58f39f46440ba75efd938d8517f7dbaf468c
7
- data.tar.gz: b9c2259efdb008fca13912c5066a966d66b65f25a92843413d2447bc0ee20011365869f1514f0f1c265b73f0ea64fd2176892b475bdf481e6e9115c13b9f958a
6
+ metadata.gz: ec495e4f3442c58ee21f6ba28a1f748c8ec8fc89f011c1bfecdb5b603b0410312c1a18b65927b75e2bed552642d4466bf9a9e6a9bd100b206f4cf8e93eb4b7b8
7
+ data.tar.gz: 6954e95f5657f7d5e2c51004f269f334c7d7eaf3d820621da71fcebbc3fc6bed07ccd38b6a5364ac9cfb23480559c839ecc83742836d2e02b3a1ae5d225b9a2c
data/.idea/lmc.iml CHANGED
@@ -1,7 +1,34 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <module type="RUBY_MODULE" version="4">
3
3
  <component name="ModuleRunConfigurationManager">
4
- <shared />
4
+ <shared>
5
+ <configuration default="false" name="tests" type="TestUnitRunConfigurationType" factoryName="Test::Unit/Shoulda/Minitest">
6
+ <predefined_log_file id="RUBY_TESTUNIT" enabled="true" />
7
+ <module name="lmc" />
8
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
9
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="" />
10
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
11
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
12
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
13
+ <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
14
+ <EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
15
+ <EXTENSION ID="RubyCoverageRunConfigurationExtension" track_test_folders="true" runner="rcov">
16
+ <COVERAGE_PATTERN ENABLED="true">
17
+ <PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
18
+ </COVERAGE_PATTERN>
19
+ </EXTENSION>
20
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="$MODULE_DIR$/test" />
21
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="" />
22
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/{*_test,test_*,*_spec}.rb" />
23
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_METHOD_NAME" VALUE="" />
24
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="ALL_IN_FOLDER" />
25
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
26
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
27
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="SPRING" VALUE="false" />
28
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_OPTIONS" VALUE="" />
29
+ <method />
30
+ </configuration>
31
+ </shared>
5
32
  </component>
6
33
  <component name="NewModuleRootManager">
7
34
  <content url="file://$MODULE_DIR$" />
@@ -9,22 +36,27 @@
9
36
  <orderEntry type="sourceFolder" forTests="false" />
10
37
  <orderEntry type="library" scope="PROVIDED" name="ansi (v1.5.0, rbenv: 2.4.1) [gem]" level="application" />
11
38
  <orderEntry type="library" scope="PROVIDED" name="builder (v3.2.3, rbenv: 2.4.1) [gem]" level="application" />
12
- <orderEntry type="library" scope="PROVIDED" name="bundler (v1.16.1, rbenv: 2.4.1) [gem]" level="application" />
13
- <orderEntry type="library" scope="PROVIDED" name="docile (v1.1.5, rbenv: 2.4.1) [gem]" level="application" />
14
- <orderEntry type="library" scope="PROVIDED" name="domain_name (v0.5.20170404, rbenv: 2.4.1) [gem]" level="application" />
39
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.16.2, rbenv: 2.4.1) [gem]" level="application" />
40
+ <orderEntry type="library" scope="PROVIDED" name="coderay (v1.1.2, rbenv: 2.4.1) [gem]" level="application" />
41
+ <orderEntry type="library" scope="PROVIDED" name="docile (v1.3.1, rbenv: 2.4.1) [gem]" level="application" />
42
+ <orderEntry type="library" scope="PROVIDED" name="domain_name (v0.5.20180417, rbenv: 2.4.1) [gem]" level="application" />
15
43
  <orderEntry type="library" scope="PROVIDED" name="http-cookie (v1.0.3, rbenv: 2.4.1) [gem]" level="application" />
16
44
  <orderEntry type="library" scope="PROVIDED" name="json (v2.1.0, rbenv: 2.4.1) [gem]" level="application" />
45
+ <orderEntry type="library" scope="PROVIDED" name="method_source (v0.8.2, rbenv: 2.4.1) [gem]" level="application" />
17
46
  <orderEntry type="library" scope="PROVIDED" name="mime-types (v3.1, rbenv: 2.4.1) [gem]" level="application" />
18
47
  <orderEntry type="library" scope="PROVIDED" name="mime-types-data (v3.2016.0521, rbenv: 2.4.1) [gem]" level="application" />
19
48
  <orderEntry type="library" scope="PROVIDED" name="minitest (v5.11.3, rbenv: 2.4.1) [gem]" level="application" />
20
- <orderEntry type="library" scope="PROVIDED" name="minitest-reporters (v1.1.19, rbenv: 2.4.1) [gem]" level="application" />
49
+ <orderEntry type="library" scope="PROVIDED" name="minitest-reporters (v1.2.0, rbenv: 2.4.1) [gem]" level="application" />
21
50
  <orderEntry type="library" scope="PROVIDED" name="netrc (v0.11.0, rbenv: 2.4.1) [gem]" level="application" />
51
+ <orderEntry type="library" scope="PROVIDED" name="pry (v0.10.4, rbenv: 2.4.1) [gem]" level="application" />
52
+ <orderEntry type="library" scope="PROVIDED" name="pry-nav (v0.2.4, rbenv: 2.4.1) [gem]" level="application" />
22
53
  <orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, rbenv: 2.4.1) [gem]" level="application" />
23
54
  <orderEntry type="library" scope="PROVIDED" name="recursive-open-struct (v1.1.0, rbenv: 2.4.1) [gem]" level="application" />
24
55
  <orderEntry type="library" scope="PROVIDED" name="rest-client (v2.0.2, rbenv: 2.4.1) [gem]" level="application" />
25
56
  <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.9.0, rbenv: 2.4.1) [gem]" level="application" />
26
- <orderEntry type="library" scope="PROVIDED" name="simplecov (v0.15.1, rbenv: 2.4.1) [gem]" level="application" />
57
+ <orderEntry type="library" scope="PROVIDED" name="simplecov (v0.16.1, rbenv: 2.4.1) [gem]" level="application" />
27
58
  <orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.10.2, rbenv: 2.4.1) [gem]" level="application" />
59
+ <orderEntry type="library" scope="PROVIDED" name="slop (v3.6.0, rbenv: 2.4.1) [gem]" level="application" />
28
60
  <orderEntry type="library" scope="PROVIDED" name="unf (v0.1.4, rbenv: 2.4.1) [gem]" level="application" />
29
61
  <orderEntry type="library" scope="PROVIDED" name="unf_ext (v0.0.7.5, rbenv: 2.4.1) [gem]" level="application" />
30
62
  </component>
@@ -0,0 +1,28 @@
1
+ <component name="ProjectRunConfigurationManager">
2
+ <configuration default="false" name="tests" type="TestUnitRunConfigurationType" factoryName="Test::Unit/Shoulda/Minitest">
3
+ <predefined_log_file id="RUBY_TESTUNIT" enabled="true" />
4
+ <module name="lmc" />
5
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
6
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="" />
7
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
8
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
9
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
10
+ <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
11
+ <EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
12
+ <EXTENSION ID="RubyCoverageRunConfigurationExtension" track_test_folders="true" runner="rcov">
13
+ <COVERAGE_PATTERN ENABLED="true">
14
+ <PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
15
+ </COVERAGE_PATTERN>
16
+ </EXTENSION>
17
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="$MODULE_DIR$/test" />
18
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="" />
19
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/{*_test,test_*,*_spec}.rb" />
20
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_METHOD_NAME" VALUE="" />
21
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="ALL_IN_FOLDER" />
22
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
23
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
24
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="SPRING" VALUE="false" />
25
+ <RTEST_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_OPTIONS" VALUE="" />
26
+ <method />
27
+ </configuration>
28
+ </component>
data/README.md CHANGED
@@ -29,6 +29,8 @@ TODO: Write usage instructions here
29
29
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
30
 
31
31
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+ ### Running a single test file
33
+ rake test TEST=test/file_with_tests.rb
32
34
 
33
35
  ### Tests against real LMC instances
34
36
 
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "result": {
3
- "covered_percent": 83.38
3
+ "covered_percent": 75.05
4
4
  }
5
5
  }
data/lib/lmc.rb CHANGED
@@ -10,6 +10,12 @@ Dir.glob(File.expand_path("../lmc/exceptions/*.rb", __FILE__)).each do |file|
10
10
  end
11
11
 
12
12
  module LMC
13
+ SERVICELIST = ['cloud-service-auth',
14
+ 'cloud-service-devices',
15
+ 'cloud-service-monitoring',
16
+ 'cloud-service-config',
17
+ 'cloud-service-licenses']
18
+
13
19
  def self.useful
14
20
  return true
15
21
  end
data/lib/lmc/Account.rb CHANGED
@@ -4,7 +4,7 @@ module LMC
4
4
  class Account < Entity
5
5
  ROOT_ACCOUNT_UUID = '9ec458c2-d05f-3004-96f0-ebe73fa20de8'
6
6
  attr_accessor :name
7
- attr_reader :id, :state, :type
7
+ attr_reader :id, :state, :type, :identifier
8
8
 
9
9
  def self.get(id)
10
10
  cloud = Cloud.instance
@@ -31,6 +31,14 @@ module LMC
31
31
  end
32
32
  end
33
33
 
34
+ def self.get_children_from_root account
35
+ cloud = Cloud.instance
36
+ cloud.auth_for_accounts [ROOT_ACCOUNT_UUID]
37
+ response = cloud.get ['cloud-service-auth', 'accounts', account.id, 'children'],
38
+ {"parent.id" => account.id}
39
+ response.map {|child| Account.new child}
40
+ end
41
+
34
42
 
35
43
  def initialize(data)
36
44
  @cloud = LMC::Cloud.instance
@@ -49,7 +57,7 @@ module LMC
49
57
  return self
50
58
  end
51
59
 
52
- def delete
60
+ def delete!
53
61
  if @id != nil
54
62
  @cloud.auth_for_accounts [@id]
55
63
  deleted = @cloud.delete ["cloud-service-auth", "accounts", @id]
@@ -94,20 +102,20 @@ module LMC
94
102
  #end
95
103
 
96
104
  def remove_membership(member_id)
97
- response = @cloud.delete ["cloud-service-auth", "accounts", id, "members", member_id]
105
+ @cloud.delete ["cloud-service-auth", "accounts", id, "members", member_id]
98
106
  end
99
107
 
100
108
  def remove_membership_self
101
- response = @cloud.delete ["cloud-service-auth", "accounts", id, "members", "self"]
109
+ @cloud.delete ["cloud-service-auth", "accounts", id, "members", "self"]
102
110
  end
103
111
 
104
112
  def authorities
105
113
  response = @cloud.get ['cloud-service-auth', 'accounts', id, 'authorities']
106
- if response.code == 200
107
- return response.body
108
- else
109
- raise 'Unable to get authorities'
114
+ raise 'Unable to get authorities' unless response.code == 200
115
+ authorities = response.body.map do |r|
116
+ Authority.new r, self
110
117
  end
118
+ return authorities
111
119
  end
112
120
 
113
121
  def children
@@ -116,6 +124,7 @@ module LMC
116
124
  response.map {|child| Account.new child}
117
125
  end
118
126
 
127
+
119
128
  def logs
120
129
  # https://lmctest/cloud-service-logging/accounts/6392b234-b11c-498a-a077-a5f5b23c54a0/logs?lang=DE
121
130
  cloud = Cloud.instance
@@ -169,6 +178,7 @@ module LMC
169
178
  @name = data["name"]
170
179
  @state = data["state"]
171
180
  @type = data["type"]
181
+ @identifier = data["identifier"]
172
182
  end
173
183
 
174
184
  end
data/lib/lmc/Cloud.rb CHANGED
@@ -24,12 +24,13 @@ module LMC
24
24
 
25
25
  attr_reader :auth_ok, :cloud_host
26
26
 
27
- def initialize(cloud_host, user, pass, auth=true)
27
+ def initialize(cloud_host, user, pass, auth = true)
28
28
  @auth_ok = false
29
29
  @cloud_host = cloud_host
30
30
  @user = user
31
31
  @password = pass
32
32
  @verify_tls = Cloud.verify_tls
33
+ #@last_authorized_account_ids = []
33
34
  authorize if auth
34
35
  end
35
36
 
@@ -186,21 +187,25 @@ module LMC
186
187
  end
187
188
 
188
189
  def accept_tos(tos)
189
- authorize([], tos)
190
+ authorize([], tos)
190
191
  end
191
192
 
192
193
 
193
194
  private
195
+
194
196
  def authorize(account_ids = [], tos = [])
195
- begin
196
- reply = post(["cloud-service-auth", "auth"], {name: @user, password: @password, accountIds: account_ids, termsOfUse: tos})
197
- puts "authorize reply " + reply.inspect if Cloud.debug
198
- @auth_token = reply
199
- @auth_ok = true
200
- rescue ::RestClient::ExceptionWithResponse => e
201
- response = JSON.parse(e.response.body)
202
- if response['code'] == 100
197
+ if account_ids != @last_authorized_account_ids
198
+ begin
199
+ reply = post(["cloud-service-auth", "auth"], {name: @user, password: @password, accountIds: account_ids, termsOfUse: tos})
200
+ puts "authorize reply " + reply.inspect if Cloud.debug
201
+ @last_authorized_account_ids = account_ids
202
+ @auth_token = reply
203
+ @auth_ok = true
204
+ rescue ::RestClient::ExceptionWithResponse => e
205
+ response = JSON.parse(e.response.body)
206
+ if response['code'] == 100
203
207
  raise LMC::OutdatedTermsOfUseException.new(response)
208
+ end
204
209
  end
205
210
  end
206
211
  end
data/lib/lmc/Device.rb CHANGED
@@ -39,6 +39,7 @@ module LMC
39
39
  data["account"] = account
40
40
  LMC::Device.new(data)
41
41
  end
42
+ return devices
42
43
  end
43
44
 
44
45
  def self.get_for_account_id(account_id)
@@ -69,4 +70,4 @@ module LMC
69
70
 
70
71
  end
71
72
 
72
- end
73
+ end
data/lib/lmc/Response.rb CHANGED
@@ -34,11 +34,11 @@ module LMC
34
34
  end
35
35
 
36
36
  def map(&block)
37
- @body_object.map &block
37
+ @body_object.map(&block)
38
38
  end
39
39
 
40
40
  def each(&block)
41
- @body_object.each &block
41
+ @body_object.each(&block)
42
42
  end
43
43
 
44
44
  def to_s
data/lib/lmc/Site.rb CHANGED
@@ -31,7 +31,8 @@ module LMC
31
31
  def configstates
32
32
  response = @cloud.get ["cloud-service-config", "configsubnetgroup", "accounts", @account.id, "subnetgroups", @subnet_group_id, "updatestates"]
33
33
  states = LMC::Configstates.new response.body
34
+ return states
34
35
  end
35
36
  end
36
37
 
37
- end
38
+ end
@@ -1,8 +1,8 @@
1
1
  module LMC
2
2
  class AccountManager
3
- @options
4
- @global_options
5
- @errors
3
+ #@options
4
+ #@global_options
5
+ #@errors
6
6
  attr_reader :errors
7
7
 
8
8
  def initialize(options, global_options)
@@ -80,4 +80,4 @@ END
80
80
  return true
81
81
  end
82
82
  end
83
- end
83
+ end
@@ -0,0 +1,51 @@
1
+ module LMC
2
+ class Authority
3
+ attr_accessor :account, :id, :name, :visibility, :type
4
+
5
+ def initialize(data, account)
6
+ @cloud = Cloud.instance
7
+ apply_data(data)
8
+ @account = account
9
+ end
10
+
11
+ def rights
12
+ # GET /accounts/{accountId}/authorities/{authorityId}/rights
13
+ @cloud.auth_for_account @account
14
+ response = @cloud.get ['cloud-service-auth', 'accounts', @account.id, 'authorities', @id, 'rights']
15
+ return response.body.to_s
16
+ end
17
+
18
+ #returns itself, allows chaining
19
+ def save
20
+ response = if @id.nil?
21
+ Cloud.instance.post ["cloud-service-auth", 'accounts', @account.id, "authorities"], self
22
+ else
23
+ raise "editing authorities not supported"
24
+ #@cloud.put ["cloud-service-auth", "principals", @id], self
25
+ end
26
+ apply_data(response.body)
27
+ return self
28
+ end
29
+
30
+ def to_json(*a)
31
+ {
32
+ "name" => @name,
33
+ "type" => @type,
34
+ "visibility" => @visibility
35
+ }.to_json(*a)
36
+ end
37
+
38
+ def to_s
39
+ "#{@name} (#{@type}/#{@visibility})"
40
+ end
41
+
42
+ private
43
+
44
+ def apply_data(data)
45
+ @id = data['id']
46
+ @name = data['name']
47
+ @visibility = data['visibility']
48
+ @type = data['type']
49
+ end
50
+ end
51
+ end
data/lib/lmc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LMC
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lmc.gemspec CHANGED
@@ -10,7 +10,6 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["philipp@copythat.de"]
11
11
 
12
12
  spec.summary = %q{Library for interacting with LMC cloud instances}
13
- # spec.homepage = "https://copythat.de"
14
13
  spec.license = 'BSD-3-Clause'
15
14
 
16
15
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
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.0
4
+ version: 0.5.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-07-06 00:00:00.000000000 Z
11
+ date: 2018-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -148,6 +148,7 @@ files:
148
148
  - ".idea/lmc.iml"
149
149
  - ".idea/misc.xml"
150
150
  - ".idea/modules.xml"
151
+ - ".idea/runConfigurations/tests.xml"
151
152
  - ".idea/vcs.xml"
152
153
  - ".ruby-version"
153
154
  - ".travis.yml"
@@ -167,6 +168,7 @@ files:
167
168
  - lib/lmc/Site.rb
168
169
  - lib/lmc/User.rb
169
170
  - lib/lmc/account_manager.rb
171
+ - lib/lmc/authority.rb
170
172
  - lib/lmc/device_config_state.rb
171
173
  - lib/lmc/entity.rb
172
174
  - lib/lmc/exceptions/lmc_outdated_terms_of_use_exception.rb