lmc 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/.idea/runConfigurations/tests.xml +4 -4
- data/.rubocop.yml +2 -0
- data/README.md +4 -4
- data/coverage/.last_run.json +1 -1
- data/lib/lmc/Account.rb +18 -28
- data/lib/lmc/Cloud.rb +68 -111
- data/lib/lmc/auth/auth_action.rb +1 -1
- data/lib/lmc/logger.rb +12 -0
- data/lib/lmc/version.rb +1 -1
- data/misc/debug_log_experiment.rb +4 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b427aa6fb475e2cae56564144444cc2e4ca76e7
|
4
|
+
data.tar.gz: 6a780cc2a84e4417fc0172eb30d2b5d4a7d73284
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e3ee7fd714001efcdd496a246d694a616bd025b494816c34285a29333c3c5322a86f62c5c8b7529f2541a2f8f59e0640a14dddeb4ca62eec9e590215c3a43fc
|
7
|
+
data.tar.gz: f42450556c13a9cf95c6d5e8d0dfb9731b6050b4fec980b83b44f52d5c356533e608d4f97109c3ae1409be9f78836cc5f43c0ea43d8a45f41af447fd5f96fed4
|
data/.gitignore
CHANGED
@@ -5,10 +5,10 @@
|
|
5
5
|
/pkg/
|
6
6
|
/spec/reports/
|
7
7
|
/tmp/
|
8
|
+
.idea/*.iml
|
9
|
+
.idea/modules.xml
|
8
10
|
.idea/workspace.xml
|
9
11
|
.idea/tasks.xml
|
10
|
-
.idea/misc.xml
|
11
|
-
.idea/modules.xml
|
12
12
|
.idea/.rakeTasks
|
13
13
|
#When developing a gem, use the gemspec method in your Gemfile to avoid duplication. In general, a gem's Gemfile should contain the Rubygems source and a single gemspec line. Do not check your Gemfile.lock into version control, since it enforces precision that does not exist in the gem command, which is used to install gems in practice.
|
14
14
|
Gemfile.lock
|
@@ -1,8 +1,8 @@
|
|
1
1
|
<component name="ProjectRunConfigurationManager">
|
2
|
-
<configuration default="false" name="tests" type="TestUnitRunConfigurationType" factoryName="Test::Unit/Shoulda/Minitest">
|
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">
|
3
3
|
<predefined_log_file id="RUBY_TESTUNIT" enabled="true" />
|
4
|
-
<module name="lmc" />
|
5
|
-
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-
|
4
|
+
<module name="ruby-lmc" />
|
5
|
+
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-I test" />
|
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="" />
|
@@ -23,6 +23,6 @@
|
|
23
23
|
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
|
24
24
|
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="SPRING" VALUE="false" />
|
25
25
|
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_OPTIONS" VALUE="" />
|
26
|
-
<method />
|
26
|
+
<method v="2" />
|
27
27
|
</configuration>
|
28
28
|
</component>
|
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# ruby-lmc
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This gem provides access to select lmc functionality.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -32,6 +30,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
30
|
### Running a single test file
|
33
31
|
rake test TEST=test/file_with_tests.rb
|
34
32
|
|
33
|
+
### Running a single test
|
34
|
+
rake test TESTOPTS="--name=test_foobar1"
|
35
35
|
### Tests against real LMC instances
|
36
36
|
|
37
37
|
#### credentials file
|
data/coverage/.last_run.json
CHANGED
data/lib/lmc/Account.rb
CHANGED
@@ -31,15 +31,6 @@ 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
|
-
|
42
|
-
|
43
34
|
def initialize(data)
|
44
35
|
@cloud = LMC::Cloud.instance
|
45
36
|
apply_data(data)
|
@@ -66,12 +57,8 @@ module LMC
|
|
66
57
|
delete_action.data = {'password' => Cloud.password,
|
67
58
|
'accountId' => @id}
|
68
59
|
deleted = delete_action.post
|
69
|
-
|
70
|
-
|
71
|
-
return true
|
72
|
-
else
|
73
|
-
raise "unable to delete account: #{deleted.body.message}"
|
74
|
-
end
|
60
|
+
@id = nil
|
61
|
+
return true
|
75
62
|
end
|
76
63
|
end
|
77
64
|
|
@@ -86,11 +73,7 @@ module LMC
|
|
86
73
|
puts ids.inspect if Cloud.debug
|
87
74
|
principals = ids.map do |principal_id|
|
88
75
|
response = Cloud.instance.get ["cloud-service-auth", "accounts", @id, 'members', principal_id]
|
89
|
-
|
90
|
-
principal = response.body
|
91
|
-
else
|
92
|
-
raise "ERROR: #{response.code} #{response.body.message}"
|
93
|
-
end
|
76
|
+
principal = response.body
|
94
77
|
puts principal.inspect if Cloud.debug
|
95
78
|
principal
|
96
79
|
end
|
@@ -114,6 +97,13 @@ module LMC
|
|
114
97
|
@cloud.delete ["cloud-service-auth", "accounts", id, "members", "self"]
|
115
98
|
end
|
116
99
|
|
100
|
+
def authority(authority_id)
|
101
|
+
response = @cloud.get(
|
102
|
+
['cloud-service-auth', 'accounts', id, 'authorities', authority_id]
|
103
|
+
)
|
104
|
+
Authority.new(response, self)
|
105
|
+
end
|
106
|
+
|
117
107
|
def authorities
|
118
108
|
response = @cloud.get ['cloud-service-auth', 'accounts', id, 'authorities']
|
119
109
|
raise 'Unable to get authorities' unless response.code == 200
|
@@ -124,7 +114,7 @@ module LMC
|
|
124
114
|
end
|
125
115
|
|
126
116
|
def children
|
127
|
-
@cloud.
|
117
|
+
@cloud.auth_for_accounts([self.id, ROOT_ACCOUNT_UUID])
|
128
118
|
response = @cloud.get ['cloud-service-auth', 'accounts', id, 'children']
|
129
119
|
response.map {|child| Account.new child}
|
130
120
|
end
|
@@ -142,13 +132,13 @@ module LMC
|
|
142
132
|
return [] if @type == "PRIVATE_CLOUD"
|
143
133
|
@cloud.auth_for_accounts([id])
|
144
134
|
response = @cloud.get ["cloud-service-devices", "accounts", id, "sites"]
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
135
|
+
return response.body.map {|data|
|
136
|
+
Site.new(data, self)
|
137
|
+
}
|
138
|
+
end
|
139
|
+
|
140
|
+
def devices
|
141
|
+
Device.get_for_account self
|
152
142
|
end
|
153
143
|
|
154
144
|
def config_updatestates
|
data/lib/lmc/Cloud.rb
CHANGED
@@ -1,27 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'base64'
|
2
4
|
require 'json'
|
3
5
|
require 'restclient'
|
4
6
|
|
5
7
|
module LMC
|
6
8
|
class Cloud
|
7
|
-
#include ActionView::Helpers::DateHelper
|
8
|
-
|
9
9
|
class << self
|
10
10
|
attr_accessor :cloud_host, :user, :password, :verbose, :debug, :verify_tls, :use_tls
|
11
11
|
Cloud.use_tls = true
|
12
12
|
Cloud.verify_tls = true
|
13
13
|
end
|
14
14
|
|
15
|
-
# def self.cloud_host=(cloud_host)
|
16
|
-
# @@cloud_host = cloud_host
|
17
|
-
# end
|
18
|
-
|
19
15
|
def self.instance(opts = {authorize: true})
|
20
16
|
@@inst ||= self.new(@cloud_host, @user, @password, opts[:authorize])
|
21
17
|
end
|
22
|
-
|
23
|
-
|
24
|
-
attr_reader :auth_ok, :cloud_host
|
18
|
+
attr_reader :auth_ok, :cloud_host, :user, :password
|
25
19
|
|
26
20
|
def initialize(cloud_host, user, pass, auth = true)
|
27
21
|
@auth_ok = false
|
@@ -30,6 +24,9 @@ module LMC
|
|
30
24
|
@password = pass
|
31
25
|
@verify_tls = Cloud.verify_tls
|
32
26
|
@last_authorized_account_ids = nil
|
27
|
+
@logger ||= ::LMC::Logger.new(STDOUT) if Cloud.debug
|
28
|
+
@logger.cloud = self if Cloud.debug
|
29
|
+
RestClient.log = @logger if Cloud.debug
|
33
30
|
authorize if auth
|
34
31
|
end
|
35
32
|
|
@@ -39,15 +36,15 @@ module LMC
|
|
39
36
|
end
|
40
37
|
|
41
38
|
def get_backstage_serviceinfos
|
42
|
-
get
|
39
|
+
get 'cloud-service-backstage/serviceinfos'
|
43
40
|
end
|
44
41
|
|
45
42
|
def get_accounts
|
46
|
-
get
|
43
|
+
get 'cloud-service-auth/accounts'
|
47
44
|
end
|
48
45
|
|
49
46
|
def get_accounts_objects
|
50
|
-
result = get [
|
47
|
+
result = get ['cloud-service-auth', 'accounts']
|
51
48
|
if result.code == 200
|
52
49
|
accounts = result.map do |aj|
|
53
50
|
Account.new(aj)
|
@@ -59,125 +56,69 @@ module LMC
|
|
59
56
|
return accounts
|
60
57
|
end
|
61
58
|
|
62
|
-
# functionality should be moved to Account class
|
63
|
-
#def get_account(name, type = nil)
|
64
|
-
# accounts = get_accounts_objects.select do |a|
|
65
|
-
# (name.nil? || a.name == name) && (type.nil? || a.type == type)
|
66
|
-
# end
|
67
|
-
# if accounts.length == 1
|
68
|
-
# return accounts[0]
|
69
|
-
# else
|
70
|
-
# raise "Did not specify exactly one account"
|
71
|
-
# end
|
72
|
-
#end
|
73
|
-
|
74
59
|
def invite_user_to_account(email, account_id, type, authorities = [])
|
75
|
-
body = {name: email, state:
|
76
|
-
body[
|
77
|
-
post [
|
60
|
+
body = {name: email, state: 'ACTIVE', type: type}
|
61
|
+
body['authorities'] = authorities
|
62
|
+
post ['cloud-service-auth', 'accounts', account_id, 'members'], body
|
78
63
|
end
|
79
64
|
|
80
65
|
def get(path, params = nil)
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
}
|
90
|
-
args.merge!(rest_options)
|
91
|
-
resp = RestClient::Request.execute args
|
92
|
-
return LMCResponse.new(resp)
|
93
|
-
rescue RestClient::ExceptionWithResponse => e
|
94
|
-
puts "EXCEPTION: " + e.to_s if Cloud.debug
|
95
|
-
puts "EX.response: " + e.response.to_s if Cloud.debug
|
96
|
-
puts JSON.parse(e.response)["message"] if Cloud.debug
|
97
|
-
raise e
|
98
|
-
#return LMCResponse.new(e.response)
|
99
|
-
end
|
66
|
+
prepared_headers = headers
|
67
|
+
prepared_headers[:params] = params
|
68
|
+
args = {
|
69
|
+
:method => :get,
|
70
|
+
:url => build_url(path),
|
71
|
+
:headers => prepared_headers
|
72
|
+
}
|
73
|
+
execute_request args
|
100
74
|
end
|
101
75
|
|
102
76
|
def put(path, body_object)
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
}
|
112
|
-
args.merge!(rest_options)
|
113
|
-
resp = RestClient::Request.execute args
|
114
|
-
return LMCResponse.new(resp)
|
115
|
-
rescue RestClient::ExceptionWithResponse => e
|
116
|
-
puts "EXCEPTION: " + e.to_s if Cloud.debug
|
117
|
-
puts "EX.response: " + e.response.to_s if Cloud.debug
|
118
|
-
puts JSON.parse(e.response)["message"] if Cloud.debug
|
119
|
-
return LMCResponse.new(e.response)
|
120
|
-
end
|
77
|
+
args = {
|
78
|
+
:method => :put,
|
79
|
+
:url => build_url(path),
|
80
|
+
:payload => body_object.to_json
|
81
|
+
|
82
|
+
}
|
83
|
+
execute_request args
|
121
84
|
end
|
122
85
|
|
123
86
|
def post(path, body_object)
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
:headers => headers
|
131
|
-
|
132
|
-
}
|
133
|
-
args.merge!(rest_options)
|
134
|
-
resp = RestClient::Request.execute args
|
135
|
-
return LMCResponse.new(resp)
|
136
|
-
rescue RestClient::ExceptionWithResponse => e
|
137
|
-
puts "EXCEPTION: " + e.to_s if Cloud.debug
|
138
|
-
puts "EX.response: " + e.response.to_s if Cloud.debug
|
139
|
-
puts JSON.parse(e.response)["message"] if Cloud.debug
|
140
|
-
raise e
|
141
|
-
end
|
87
|
+
args = {
|
88
|
+
:method => :post,
|
89
|
+
:url => build_url(path),
|
90
|
+
:payload => body_object.to_json
|
91
|
+
}
|
92
|
+
execute_request args
|
142
93
|
end
|
143
94
|
|
144
95
|
def delete(path, body_object = nil)
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
}
|
153
|
-
args.merge!(rest_options)
|
154
|
-
resp = RestClient::Request.execute args
|
155
|
-
return LMCResponse.new(resp)
|
156
|
-
rescue RestClient::ExceptionWithResponse => e
|
157
|
-
puts "EXCEPTION: " + e.to_s if Cloud.debug
|
158
|
-
puts "EX.response: " + e.response.to_s if Cloud.debug
|
159
|
-
puts JSON.parse(e.response)["message"] if Cloud.debug
|
160
|
-
return LMCResponse.new(e.response)
|
161
|
-
end
|
96
|
+
args = {
|
97
|
+
:method => :delete,
|
98
|
+
:url => build_url(path),
|
99
|
+
:payload => body_object.to_json,
|
100
|
+
:headers => headers
|
101
|
+
}
|
102
|
+
execute_request args
|
162
103
|
end
|
163
104
|
|
164
105
|
##
|
165
106
|
# public accessors
|
166
107
|
##
|
167
108
|
def session_token
|
168
|
-
@auth_token[
|
109
|
+
@auth_token['value']
|
169
110
|
end
|
170
111
|
|
171
112
|
def build_url(*path_components)
|
172
|
-
protocol =
|
113
|
+
protocol = 'https'
|
173
114
|
if !Cloud.use_tls
|
174
|
-
protocol =
|
115
|
+
protocol = 'http'
|
175
116
|
end
|
176
|
-
["#{protocol}://#{@cloud_host}", path_components].flatten.compact.join(
|
117
|
+
["#{protocol}://#{@cloud_host}", path_components].flatten.compact.join('/')
|
177
118
|
end
|
178
119
|
|
179
120
|
def auth_for_accounts(account_ids)
|
180
|
-
puts
|
121
|
+
puts 'Authorizing for accounts: ' + account_ids.to_s if Cloud.debug
|
181
122
|
authorize(account_ids)
|
182
123
|
end
|
183
124
|
|
@@ -195,8 +136,8 @@ module LMC
|
|
195
136
|
def authorize(account_ids = [], tos = [])
|
196
137
|
if account_ids != @last_authorized_account_ids
|
197
138
|
begin
|
198
|
-
reply = post([
|
199
|
-
puts
|
139
|
+
reply = post(['cloud-service-auth', 'auth'], {name: @user, password: @password, accountIds: account_ids, termsOfUse: tos})
|
140
|
+
puts 'authorize reply ' + reply.inspect if Cloud.debug
|
200
141
|
@last_authorized_account_ids = account_ids
|
201
142
|
@auth_token = reply
|
202
143
|
@auth_ok = true
|
@@ -210,7 +151,7 @@ module LMC
|
|
210
151
|
end
|
211
152
|
|
212
153
|
def auth_bearer
|
213
|
-
|
154
|
+
'Bearer ' + session_token
|
214
155
|
end
|
215
156
|
|
216
157
|
def headers
|
@@ -224,11 +165,27 @@ module LMC
|
|
224
165
|
|
225
166
|
def rest_options
|
226
167
|
options = {}
|
227
|
-
|
228
|
-
|
168
|
+
options[:verify_ssl] = false unless @verify_tls
|
169
|
+
options
|
170
|
+
end
|
171
|
+
|
172
|
+
def execute_request(args)
|
173
|
+
internal_args = { headers: headers }
|
174
|
+
internal_args.merge! rest_options
|
175
|
+
internal_args.merge! args
|
176
|
+
begin
|
177
|
+
resp = RestClient::Request.execute internal_args
|
178
|
+
return LMCResponse.new(resp)
|
179
|
+
rescue RestClient::ExceptionWithResponse => e
|
180
|
+
print_exception e if Cloud.debug
|
181
|
+
raise e
|
229
182
|
end
|
230
|
-
return options
|
231
183
|
end
|
232
|
-
end
|
233
184
|
|
185
|
+
def print_exception(execption)
|
186
|
+
puts 'EXCEPTION: ' + execption.to_s
|
187
|
+
puts 'EX.response: ' + execption.response.to_s
|
188
|
+
puts JSON.parse(execption.response)['message']
|
189
|
+
end
|
190
|
+
end
|
234
191
|
end
|
data/lib/lmc/auth/auth_action.rb
CHANGED
data/lib/lmc/logger.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LMC
|
4
|
+
# Custom logger that hides the cloud password in restclient output
|
5
|
+
class Logger < ::Logger
|
6
|
+
@cloud = nil
|
7
|
+
attr_accessor :cloud
|
8
|
+
def <<(line)
|
9
|
+
super line.gsub @cloud.password, '********'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/lmc/version.rb
CHANGED
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.7.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-
|
11
|
+
date: 2018-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- ".idea/inspectionProfiles/Project_Default.xml"
|
148
148
|
- ".idea/runConfigurations/tests.xml"
|
149
149
|
- ".idea/vcs.xml"
|
150
|
+
- ".rubocop.yml"
|
150
151
|
- ".ruby-version"
|
151
152
|
- ".travis.yml"
|
152
153
|
- Gemfile
|
@@ -171,12 +172,14 @@ files:
|
|
171
172
|
- lib/lmc/device_config_state.rb
|
172
173
|
- lib/lmc/entity.rb
|
173
174
|
- lib/lmc/exceptions/lmc_outdated_terms_of_use_exception.rb
|
175
|
+
- lib/lmc/logger.rb
|
174
176
|
- lib/lmc/membership.rb
|
175
177
|
- lib/lmc/mixins/json_able.rb
|
176
178
|
- lib/lmc/mixins/service_resource.rb
|
177
179
|
- lib/lmc/principal.rb
|
178
180
|
- lib/lmc/version.rb
|
179
181
|
- lmc.gemspec
|
182
|
+
- misc/debug_log_experiment.rb
|
180
183
|
homepage:
|
181
184
|
licenses:
|
182
185
|
- BSD-3-Clause
|