yao 0.3.2 → 0.3.3

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: 5f5e910f9f7616e6e9e7402416b818e366d718e1
4
- data.tar.gz: 392f0c4b9ba85c8c5fed0939c3dc07c457611a3e
3
+ metadata.gz: 9cb896f2250772f6580f028bb2dc529c962cbaec
4
+ data.tar.gz: 897adb236fd643b44fb04cbbfee42f33d6585f7c
5
5
  SHA512:
6
- metadata.gz: 9432f815b9ec8e394f85764827537d2dcdc646823201f2cba83cd3b830177ce59f738675c61b4bcd18603e61b934ba31d46400c27f29b3abf022566d536c533d
7
- data.tar.gz: 9d035450f40b5672afdffc7c8e43d0f8567ae47ddabcf3db0d6534da324b5987288bf53adc5bdd4b889e7e2c0cbc99b17be0c27492069117304a649c5b17a4b8
6
+ metadata.gz: 0d61e5b8f00624660f4fc2f2cf565d2ff61251b1dc7a7ab0b00a666337cf7f4b621b107e45bc3ca617ce12777174c6f62e21ccde194414acf348f46a97dcb48e
7
+ data.tar.gz: e5ec0f64e49552af51df369edb40f60157bdfc9013f144c4cb3eff654980186085c6efc896fc170532fa27991adacd8b1318b62f3befe34a125c48b16f501252
data/README.md CHANGED
@@ -26,7 +26,7 @@ Or install it yourself as:
26
26
  require 'yao'
27
27
 
28
28
  Yao.configure do
29
- auth_url "http://keystone.example.local:8080/v2.0/tokens"
29
+ auth_url "http://keystone.example.local:8080/v2.0"
30
30
  tenant_name "fooproject"
31
31
  username "udzura"
32
32
  password "tonk0tsu-r@men"
@@ -47,7 +47,7 @@ If you want to override some of endpoints by service, you can do:
47
47
 
48
48
  ```ruby
49
49
  Yao.configure do
50
- auth_url "http://endpoint.example.com:12345"
50
+ auth_url "http://endpoint.example.com:12345/v2.0"
51
51
  tenant_name "example"
52
52
  username "udzura"
53
53
  password "XXXXXXXX"
@@ -70,7 +70,7 @@ You can use a prittier namespace:
70
70
  require 'yao/is_openstack_client'
71
71
 
72
72
  OpenStack.configure do
73
- auth_url "http://keystone.example.local:8080/v2.0/tokens"
73
+ auth_url "http://keystone.example.local:8080/v2.0"
74
74
  tenant_name "fooproject"
75
75
  username "udzura"
76
76
  password "tonk0tsu-r@men"
data/lib/yao/auth.rb CHANGED
@@ -4,7 +4,7 @@ require 'time'
4
4
  require 'yao/token'
5
5
 
6
6
  module Yao
7
- %i(tenant_name username password timeout client_cert client_key).each do |name|
7
+ %i(tenant_name username password timeout client_cert client_key region_name).each do |name|
8
8
  Yao.config.param name, nil
9
9
  end
10
10
 
data/lib/yao/client.rb CHANGED
@@ -28,8 +28,7 @@ module Yao
28
28
  # XXX: neutron just have v2.0 API and endpoint may not have version prefix
29
29
  if type == "network"
30
30
  urls = urls.map {|public_or_admin, url|
31
- path = URI.parse(url).path
32
- url = (path == '' || path == '/') ? File.join(url, "v2.0") : url
31
+ url = File.join(url, "v2.0")
33
32
  [public_or_admin, url]
34
33
  }.to_h
35
34
  end
@@ -22,7 +22,7 @@ class Faraday::Request::OSToken
22
22
 
23
23
  def call(env)
24
24
  if @token.expired?
25
- @token.reflesh(Yao.default_client.default)
25
+ @token.refresh(Yao.default_client.default)
26
26
  end
27
27
 
28
28
  env[:request_headers]['X-Auth-Token'] = @token.to_s
@@ -51,7 +51,7 @@ class Faraday::Request::ReadOnly
51
51
  private
52
52
 
53
53
  ALLOWED_REQUESTS = [
54
- {method: :post, path: "/v2.0/tokens"}
54
+ {method: :post, path: "/tokens"}
55
55
  ]
56
56
 
57
57
  def allowed_request?(env)
@@ -0,0 +1,17 @@
1
+ module Yao::Resources
2
+ class RoleAssignment < Base
3
+ friendly_attributes :scope, :role, :user
4
+ self.service = "identity"
5
+ self.resource_name = "role_assignment"
6
+ self.resources_name = "role_assignments"
7
+ self.admin = true
8
+ self.api_version = "v3"
9
+
10
+ def project
11
+ @project ||= Yao::Tenant.get(scope["project"]["id"])
12
+ end
13
+
14
+ map_attribute_to_resource :role => Role
15
+ map_attribute_to_resource :user => User
16
+ end
17
+ end
data/lib/yao/resources.rb CHANGED
@@ -18,6 +18,7 @@ module Yao
18
18
  autoload :Host, "yao/resources/host"
19
19
  autoload :User, "yao/resources/user"
20
20
  autoload :Role, "yao/resources/role"
21
+ autoload :RoleAssignment, "yao/resources/role_assignment"
21
22
 
22
23
  autoload :Resource, "yao/resources/resource"
23
24
  autoload :Meter, "yao/resources/meter"
data/lib/yao/token.rb CHANGED
@@ -4,7 +4,7 @@ module Yao
4
4
  class Token
5
5
  def self.issue(cli, auth_info)
6
6
  t = new(auth_info)
7
- t.reflesh(cli)
7
+ t.refresh(cli)
8
8
  t
9
9
  end
10
10
 
@@ -29,10 +29,10 @@ module Yao
29
29
  Time.now >= self.expire_at
30
30
  end
31
31
 
32
- def reflesh(cli)
32
+ def refresh(cli)
33
33
  @endpoints.clear
34
34
 
35
- res = cli.post('/v2.0/tokens') do |req|
35
+ res = cli.post("#{Yao.config.auth_url}/tokens") do |req|
36
36
  req.body = auth_info.to_json
37
37
  req.headers['Content-Type'] = 'application/json'
38
38
  end
@@ -48,11 +48,13 @@ module Yao
48
48
 
49
49
  _endpoints.each do |endpoint_data|
50
50
  type = endpoint_data["type"]
51
- endpoint = endpoint_data["endpoints"].first
51
+ region_name = Yao.config.region_name ? Yao.config.region_name : 'RegionOne'
52
+ endpoint = endpoint_data["endpoints"].find { |ep| ep.has_value?(region_name) }
52
53
  urls = {}
53
- urls[:public_url] = endpoint["publicURL"] if endpoint["publicURL"]
54
- urls[:admin_url] = endpoint["adminURL"] if endpoint["adminURL"]
55
-
54
+ if endpoint
55
+ urls[:public_url] = endpoint["publicURL"] if endpoint["publicURL"]
56
+ urls[:admin_url] = endpoint["adminURL"] if endpoint["adminURL"]
57
+ end
56
58
  @endpoints[type] = urls
57
59
  end
58
60
 
data/lib/yao/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yao
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  module AuthStub
2
2
  def stub_auth_request(auth_url, username, password, tenant)
3
- stub_request(:post, "#{auth_url}/v2.0/tokens")
3
+ stub_request(:post, "#{auth_url}/tokens")
4
4
  .with(
5
5
  body: auth_json(username, password, tenant)
6
6
  ).to_return(
@@ -44,6 +44,13 @@ module AuthStub
44
44
  "internalURL": "http://nova-endpoint.example.com:8774/v2/b598bf98671c47e1b955f8c9660e3c44",
45
45
  "id": "1a66e6af97c440b2a7bbc4f9735923d9",
46
46
  "publicURL": "http://nova-endpoint.example.com:8774/v2/b598bf98671c47e1b955f8c9660e3c44"
47
+ },
48
+ {
49
+ "adminURL": "https://global-endpoint.example.com/api/nova/b598bf98671c47e1b955f8c9660e3c44",
50
+ "region": "RegionTest",
51
+ "internalURL": "http://192.168.10.52:8774/v2/b598bf98671c47e1b955f8c9660e3c44",
52
+ "id": "18df07456cda4af1a7031f0de68637ea",
53
+ "publicURL": "https://global-endpoint.example.com/api/nova/b598bf98671c47e1b955f8c9660e3c44"
47
54
  }
48
55
  ],
49
56
  "endpoints_links": [],
@@ -58,6 +65,13 @@ module AuthStub
58
65
  "internalURL": "http://neutron-endpoint.example.com:9696/",
59
66
  "id": "0418104da877468ca65d739142fa3454",
60
67
  "publicURL": "http://neutron-endpoint.example.com:9696/"
68
+ },
69
+ {
70
+ "adminURL": "https://global-endpoint.example.com/api/neutron/",
71
+ "region": "RegionTest",
72
+ "internalURL": "http://192.168.10.53:9696/",
73
+ "id": "5e5cf4ffecfa4ce1a956fe517baf3154",
74
+ "publicURL": "https://global-endpoint.example.com/api/neutron/"
61
75
  }
62
76
  ],
63
77
  "endpoints_links": [],
@@ -72,6 +86,13 @@ module AuthStub
72
86
  "internalURL": "http://glance-endpoint.example.com:9292",
73
87
  "id": "246f33509ff64802b86eb081307ecec0",
74
88
  "publicURL": "http://glance-endpoint.example.com:9292"
89
+ },
90
+ {
91
+ "adminURL": "https://global-endpoint.example.com/api/glance/",
92
+ "region": "RegionTest",
93
+ "internalURL": "http://192.168.10.54:9292/",
94
+ "id": "62d6f676ff0c491e9671a7ab6a596493",
95
+ "publicURL": "https://global-endpoint.example.com/api/glance/"
75
96
  }
76
97
  ],
77
98
  "endpoints_links": [],
@@ -81,11 +102,18 @@ module AuthStub
81
102
  {
82
103
  "endpoints": [
83
104
  {
84
- "adminURL": "#{auth_url}/v2.0",
105
+ "adminURL": "#{auth_url}",
85
106
  "region": "RegionOne",
86
107
  "internalURL": "http://endpoint.example.com:5000/v2.0",
87
108
  "id": "2b982236cc084128bf42b647c1b7fb49",
88
109
  "publicURL": "http://endpoint.example.com:5000/v2.0"
110
+ },
111
+ {
112
+ "adminURL": "https://global-endpoint.example.com/api/admin/keystone/",
113
+ "region": "RegionTest",
114
+ "internalURL": "http://192.168.10.52:35357/v2.0",
115
+ "id": "11ae249e090d4b548ae992c08ea3b35a",
116
+ "publicURL": "https://global-endpoint.example.com/api/keystone/"
89
117
  }
90
118
  ],
91
119
  "endpoints_links": [],
@@ -2,7 +2,7 @@ class TestAuth < Test::Unit::TestCase
2
2
  include AuthStub
3
3
 
4
4
  def setup
5
- @auth_url = "http://endpoint.example.com:12345"
5
+ @auth_url = "http://endpoint.example.com:12345/v2.0"
6
6
  username = "udzura"
7
7
  tenant = "example"
8
8
  password = "XXXXXXXX"
@@ -21,7 +21,7 @@ class TestAuth < Test::Unit::TestCase
21
21
 
22
22
  def test_auth_successful
23
23
  cli = Yao.default_client.pool["default"]
24
- assert { cli.url_prefix.to_s == "http://endpoint.example.com:12345/" }
24
+ assert { cli.url_prefix.to_s == "http://endpoint.example.com:12345/v2.0" }
25
25
  end
26
26
 
27
27
  def test_service_sclients_initialized
@@ -53,7 +53,7 @@ class TestAuth < Test::Unit::TestCase
53
53
  stub(auth).new
54
54
 
55
55
  Yao.configure do
56
- auth_url "http://endpoint.example.com:12345"
56
+ auth_url "http://endpoint.example.com:12345/v2.0"
57
57
  tenant_name "example"
58
58
  username "udzura"
59
59
  password "XXXXXXXX"
@@ -63,14 +63,28 @@ class TestAuth < Test::Unit::TestCase
63
63
 
64
64
  def test_override_endpoint
65
65
  Yao.configure do
66
- auth_url "http://endpoint.example.com:12345"
66
+ auth_url "http://endpoint.example.com:12345/v2.0"
67
67
  tenant_name "example"
68
68
  username "udzura"
69
69
  password "XXXXXXXX"
70
70
  endpoints ({ identity: { public: "http://override-endpoint.example.com:35357/v3.0" } })
71
71
  end
72
- assert(Yao.default_client.pool["identity"].url_prefix.to_s, "http://override-endpoint.example.com:35357/v3.0")
72
+ assert { Yao.default_client.pool["identity"].url_prefix.to_s == "http://override-endpoint.example.com:35357/v3.0" }
73
73
  end
74
74
 
75
+ def test_region
76
+ Yao.configure do
77
+ auth_url "http://endpoint.example.com:12345/v2.0"
78
+ tenant_name "example"
79
+ username "udzura"
80
+ password "XXXXXXXX"
81
+ region_name "RegionTest"
82
+ end
83
+ assert { Yao.default_client.pool["identity"].url_prefix.to_s == "https://global-endpoint.example.com/api/keystone/" }
84
+ ensure
85
+ Yao.configure do
86
+ region_name "RegionOne"
87
+ end
88
+ end
75
89
 
76
90
  end
@@ -2,7 +2,7 @@ class TestOnly < Test::Unit::TestCase
2
2
  include AuthStub
3
3
 
4
4
  def setup
5
- auth_url = "http://endpoint.example.com:12345"
5
+ auth_url = "http://endpoint.example.com:12345/v2.0"
6
6
  username = "udzura"
7
7
  tenant = "example"
8
8
  password = "XXXXXXXX"
@@ -17,8 +17,8 @@ class TestOnly < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  @username = username
20
- @get_stub = stub_request(:get, "#{auth_url}/v2.0/users?name=#{username}")
21
- @post_stub = stub_request(:post, "#{auth_url}/v2.0/users")
20
+ @get_stub = stub_request(:get, "#{auth_url}/users?name=#{username}")
21
+ @post_stub = stub_request(:post, "#{auth_url}/users")
22
22
  end
23
23
 
24
24
  def test_read_only
@@ -30,8 +30,8 @@ class TestToken < Test::Unit::TestCase
30
30
  assert { ! t.expired? }
31
31
  end
32
32
 
33
- def test_reflesh
34
- auth_url = "http://endpoint.example.com:12345"
33
+ def test_refresh
34
+ auth_url = "http://endpoint.example.com:12345/v2.0"
35
35
  username = "udzura"
36
36
  tenant = "example"
37
37
  password = "XXXXXXXX"
@@ -58,7 +58,7 @@ class TestToken < Test::Unit::TestCase
58
58
  stub_auth_request(auth_url, username, password, tenant)
59
59
 
60
60
  Yao.config.auth_url auth_url
61
- t.reflesh(Yao.default_client.default)
61
+ t.refresh(Yao.default_client.default)
62
62
 
63
63
  assert { t.token == "aaaa166533fd49f3b11b1cdce2430000" }
64
64
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yao
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uchio, KONDO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-10 00:00:00.000000000 Z
11
+ date: 2017-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -193,6 +193,7 @@ files:
193
193
  - lib/yao/resources/resource.rb
194
194
  - lib/yao/resources/restfully_accessible.rb
195
195
  - lib/yao/resources/role.rb
196
+ - lib/yao/resources/role_assignment.rb
196
197
  - lib/yao/resources/router.rb
197
198
  - lib/yao/resources/sample.rb
198
199
  - lib/yao/resources/security_group.rb
@@ -241,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
242
  version: '0'
242
243
  requirements: []
243
244
  rubyforge_project:
244
- rubygems_version: 2.5.1
245
+ rubygems_version: 2.6.8
245
246
  signing_key:
246
247
  specification_version: 4
247
248
  summary: Yet Another OpenStack API Wrapper that rocks!!