iron_core 1.0.5 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +1 -0
- data/Gemfile.lock +12 -12
- data/iron_core.gemspec +1 -1
- data/lib/iron_core.rb +2 -0
- data/lib/iron_core/client.rb +33 -3
- data/lib/iron_core/configuration_error.rb +9 -0
- data/lib/iron_core/iron_token_provider.rb +11 -0
- data/lib/iron_core/keystone_token_provider.rb +51 -0
- data/lib/iron_core/version.rb +1 -1
- data/test/test_base.rb +25 -0
- data/test/tmp.rb +17 -0
- metadata +24 -17
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ODFhMmIzYmVjNjIwYTFhZmQ2ZDhjNmZkZGEzN2IwMDZhYmUzODE0ZA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d4242d46932aaa5d4631b63ef7ca271d8b8e8e4d
|
4
|
+
data.tar.gz: b711a9caed69077007f64e94f89fa952e1d890d2
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MTEzMjBjOGZlZWVmMDAzM2EzNjEzYjMyOGVlZGI5YjU2MTQ3NGY2MTZiYTU0
|
11
|
-
NDYxZTVkOTBhMzU2OTliMjA1ODVjODY0ZjY4NGU2ZmY2ZDVjMjg=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YzJmZWNjNTE4MDI2NDM0NGFiYjRkZDg4M2VjMGFlNDYxNzJlYjY1Y2NjMzBl
|
14
|
-
YWUwYTQ1MzI3N2YzNjdhMDc0YWNhYmM4Zjk1Njk5YmVlNTAwMTI1ODc1MjFk
|
15
|
-
NzhiZGVhYzI4MjFkOTJjMzUwNDZhMmQ5NDRmYmU2NDJhYTgwOWQ=
|
6
|
+
metadata.gz: e05d8fcf5d06d2371411478aee9f98d8d0cba40f80b6146b0835269f81f733a909e5d514a09bad2c11afcdf34df18ce8e54233018d38813dfef6229bdab2cb8b
|
7
|
+
data.tar.gz: 546cdfa1320532b6a33b261edac03043c7ba58415304733efd6f0363b72d46f7ea460a2bd1f641e885b275884b6819b70d936e1d32fb439975fca1b7134009b4
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
iron_core (1.0.
|
5
|
-
rest (>=
|
4
|
+
iron_core (1.0.5)
|
5
|
+
rest (>= 3.0.3)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
minitest (5.5.1)
|
11
|
+
net-http-persistent (2.9.4)
|
12
|
+
netrc (0.10.3)
|
13
|
+
power_assert (0.2.2)
|
14
|
+
rake (10.4.2)
|
15
|
+
rest (3.0.3)
|
16
|
+
net-http-persistent (>= 2.9.1)
|
17
|
+
netrc
|
18
|
+
test-unit (3.0.9)
|
19
|
+
power_assert
|
20
20
|
|
21
21
|
PLATFORMS
|
22
22
|
ruby
|
data/iron_core.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
|
17
17
|
gem.required_rubygems_version = ">= 1.3.6"
|
18
18
|
gem.required_ruby_version = Gem::Requirement.new(">= 1.8")
|
19
|
-
gem.add_runtime_dependency "rest", ">=
|
19
|
+
gem.add_runtime_dependency "rest", ">= 3.0.4"
|
20
20
|
|
21
21
|
gem.add_development_dependency "test-unit"
|
22
22
|
gem.add_development_dependency "minitest"
|
data/lib/iron_core.rb
CHANGED
data/lib/iron_core/client.rb
CHANGED
@@ -8,9 +8,10 @@ module IronCore
|
|
8
8
|
class Client
|
9
9
|
attr_accessor :content_type
|
10
10
|
attr_accessor :env
|
11
|
+
attr_reader :rest
|
11
12
|
|
12
13
|
def initialize(company, product, options = {}, default_options = {}, extra_options_list = [])
|
13
|
-
@options_list = [:scheme, :host, :port, :user_agent, :http_gem] + extra_options_list
|
14
|
+
@options_list = [:scheme, :host, :port, :user_agent, :http_gem, :keystone, :http_proxy] + extra_options_list
|
14
15
|
|
15
16
|
metaclass = class << self
|
16
17
|
self
|
@@ -75,11 +76,35 @@ module IronCore
|
|
75
76
|
default_http_gem = RUBY_VERSION.split('.')[1].to_i == 8 ? :rest_client : nil
|
76
77
|
http_gem = @http_gem.nil? ? default_http_gem : @http_gem.to_sym
|
77
78
|
|
78
|
-
|
79
|
+
rest_options = {:gem => http_gem}
|
80
|
+
rest_options[:http_proxy] = options[:http_proxy] if options[:http_proxy]
|
81
|
+
@rest = Rest::Client.new(rest_options)
|
82
|
+
|
83
|
+
if self.keystone && self.keystone.is_a?(Hash)
|
84
|
+
raise_keystone_config_error('server') if self.keystone[:server].nil?
|
85
|
+
raise_keystone_config_error('tenant') if self.keystone[:tenant].nil?
|
86
|
+
if self.keystone[:token].nil? && self.keystone[:tenant_token].nil? &&
|
87
|
+
(self.keystone[:username].nil? && self.keystone[:password].nil?)
|
88
|
+
raise_keystone_config_error('username, password or token')
|
89
|
+
end
|
90
|
+
|
91
|
+
@token_provider = IronCore::KeystoneTokenProvider.new(@rest, self.keystone)
|
92
|
+
else
|
93
|
+
@token_provider = IronCore::IronTokenProvider.new(@token)
|
94
|
+
end
|
79
95
|
end
|
80
96
|
|
81
97
|
def set_option(source, name, value)
|
82
98
|
if send(name.to_s).nil? && (not value.nil?)
|
99
|
+
if value.class == Hash
|
100
|
+
value.keys.each do |key|
|
101
|
+
if key.class == String
|
102
|
+
value[key.to_sym] = value[key]
|
103
|
+
value.delete(key)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
83
108
|
IronCore::Logger.debug 'IronCore', "Setting #{name} to '#{value}' from #{source}"
|
84
109
|
|
85
110
|
send(name.to_s + '=', value)
|
@@ -227,7 +252,7 @@ module IronCore
|
|
227
252
|
IronCore::Logger.debug 'IronCore', "PUT #{base_url + method} with params='#{request_hash.to_s}'"
|
228
253
|
|
229
254
|
begin
|
230
|
-
|
255
|
+
@rest.put(base_url + method, request_hash)
|
231
256
|
rescue Rest::HttpError => ex
|
232
257
|
extract_error_msg(ex)
|
233
258
|
end
|
@@ -318,5 +343,10 @@ module IronCore
|
|
318
343
|
IronCore::Logger.error 'IronCore', "Expecting #{length} symbol #{name} string", IronCore::Error
|
319
344
|
end
|
320
345
|
end
|
346
|
+
|
347
|
+
def raise_keystone_config_error(missing)
|
348
|
+
IronCore::Logger.error 'IronCore', "Keystone keys missing: #{missing}", IronCore::Error
|
349
|
+
raise IronCore::ConfigurationError.new("Keystone keys missing: #{missing}")
|
350
|
+
end
|
321
351
|
end
|
322
352
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module IronCore
|
2
|
+
class KeystoneTokenProvider
|
3
|
+
def initialize(client, options)
|
4
|
+
@rest_client = client.dup
|
5
|
+
@token = options[:tenant_token] # Way to bypass fetching a token from keystone api
|
6
|
+
@server = options[:server]
|
7
|
+
@tenant = options[:tenant]
|
8
|
+
@username = options[:username]
|
9
|
+
@password = options[:password]
|
10
|
+
@user_token = options[:token]
|
11
|
+
end
|
12
|
+
|
13
|
+
def token
|
14
|
+
if @token.nil? || (@local_expires_at && (Time.now - @local_expires_at > -10))
|
15
|
+
payload = {
|
16
|
+
auth: {
|
17
|
+
tenantId: @tenant,
|
18
|
+
}
|
19
|
+
}
|
20
|
+
if @username.to_s != ''
|
21
|
+
payload[:auth][:passwordCredentials] = {
|
22
|
+
username: @username,
|
23
|
+
password: @password
|
24
|
+
}
|
25
|
+
elsif @user_token.to_s != ''
|
26
|
+
payload[:auth][:token] = {id: @user_token}
|
27
|
+
end
|
28
|
+
|
29
|
+
response = post(@server + 'tokens', payload)
|
30
|
+
result = JSON.parse(response.body)
|
31
|
+
token_data = result['access']['token']
|
32
|
+
|
33
|
+
issued_at = Time.parse(token_data['issued_at'] + " UTC")
|
34
|
+
expires = Time.parse(token_data['expires'] + " UTC")
|
35
|
+
duration = (expires - issued_at).to_i
|
36
|
+
|
37
|
+
@local_expires_at = Time.now + duration
|
38
|
+
@token = token_data['id']
|
39
|
+
end
|
40
|
+
|
41
|
+
@token
|
42
|
+
end
|
43
|
+
|
44
|
+
def post(path, params = {})
|
45
|
+
request_hash = {}
|
46
|
+
request_hash[:headers] = {'Content-Type' => 'application/json', 'Accept' => 'application/json'}
|
47
|
+
request_hash[:body] = params.to_json
|
48
|
+
@rest_client.post(path, request_hash)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/iron_core/version.rb
CHANGED
data/test/test_base.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'yaml'
|
3
|
+
begin
|
4
|
+
require File.join(File.dirname(__FILE__), '../lib/iron_core')
|
5
|
+
rescue Exception => ex
|
6
|
+
puts "Could NOT load gem: " + ex.message
|
7
|
+
raise ex
|
8
|
+
end
|
9
|
+
|
10
|
+
class TestBase < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
puts 'setup'
|
14
|
+
@core = IronCore::Client.new("iron", "product", :gem => :net_http_persistent, :log_level=>Logger::DEBUG,
|
15
|
+
:http_proxy=>"http://whatever"
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_fake
|
20
|
+
end
|
21
|
+
|
22
|
+
ALL_OPS = [:get, :put, :post, :delete]
|
23
|
+
|
24
|
+
|
25
|
+
end
|
data/test/tmp.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iron_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kirilenko
|
@@ -9,62 +9,62 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 3.0.4
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 3.0.4
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: test-unit
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: minitest
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rake
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
description: Core library for Iron products
|
@@ -74,7 +74,7 @@ executables: []
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
-
- .gitignore
|
77
|
+
- ".gitignore"
|
78
78
|
- Gemfile
|
79
79
|
- Gemfile.lock
|
80
80
|
- LICENSE
|
@@ -83,10 +83,15 @@ files:
|
|
83
83
|
- iron_core.gemspec
|
84
84
|
- lib/iron_core.rb
|
85
85
|
- lib/iron_core/client.rb
|
86
|
+
- lib/iron_core/configuration_error.rb
|
86
87
|
- lib/iron_core/error.rb
|
87
88
|
- lib/iron_core/iron_logger.rb
|
89
|
+
- lib/iron_core/iron_token_provider.rb
|
90
|
+
- lib/iron_core/keystone_token_provider.rb
|
88
91
|
- lib/iron_core/response_error.rb
|
89
92
|
- lib/iron_core/version.rb
|
93
|
+
- test/test_base.rb
|
94
|
+
- test/tmp.rb
|
90
95
|
homepage: https://github.com/iron-io/iron_core_ruby
|
91
96
|
licenses: []
|
92
97
|
metadata: {}
|
@@ -96,18 +101,20 @@ require_paths:
|
|
96
101
|
- lib
|
97
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
98
103
|
requirements:
|
99
|
-
- -
|
104
|
+
- - ">="
|
100
105
|
- !ruby/object:Gem::Version
|
101
106
|
version: '1.8'
|
102
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
108
|
requirements:
|
104
|
-
- -
|
109
|
+
- - ">="
|
105
110
|
- !ruby/object:Gem::Version
|
106
111
|
version: 1.3.6
|
107
112
|
requirements: []
|
108
113
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.4.2
|
110
115
|
signing_key:
|
111
116
|
specification_version: 4
|
112
117
|
summary: Core library for Iron products
|
113
|
-
test_files:
|
118
|
+
test_files:
|
119
|
+
- test/test_base.rb
|
120
|
+
- test/tmp.rb
|