yao 0.2.7 → 0.2.8
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 +4 -4
- data/lib/yao/client.rb +3 -0
- data/lib/yao/{server_error.rb → error.rb} +2 -0
- data/lib/yao/faraday_middlewares.rb +36 -1
- data/lib/yao/mode.rb +35 -0
- data/lib/yao/plugins/default_client_generator.rb +2 -0
- data/lib/yao/resources/restfully_accessible.rb +3 -3
- data/lib/yao/version.rb +1 -1
- data/lib/yao.rb +2 -0
- data/test/config.rb +2 -0
- data/test/support/auth_stub.rb +117 -0
- data/test/yao/test_auth.rb +10 -102
- data/test/yao/test_client.rb +3 -0
- data/test/yao/test_read_only.rb +114 -0
- data/test/yao/test_token.rb +11 -29
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1265dc90ca7a24dc73c1bea6f56dd54170ca1cd2
|
4
|
+
data.tar.gz: ae58d2f7e8b5c8830f2965e072e726bed04c982c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c27613a24e52a2e1397e73a18d44d54335cf249a5eed33be21a5f37ec91f8ab9a33ebc8be030a8fa0ecc0faf4a83831c5d46d804f2c2287ff3d4215fb69629a
|
7
|
+
data.tar.gz: f6879388cb203aa0b481d24a5597fffd628e351f253c50ad1d173292ab5e541bcf20e72c0613fee73627a064f1edf7d7fba1542e53cfb2336cb5049c36ac09f2
|
data/lib/yao/client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'faraday'
|
2
|
+
require 'yao/error'
|
2
3
|
|
3
4
|
class Faraday::Request::Accept
|
4
5
|
def initialize(app, accept=nil)
|
@@ -30,6 +31,39 @@ class Faraday::Request::OSToken
|
|
30
31
|
end
|
31
32
|
Faraday::Request.register_middleware os_token: -> { Faraday::Request::OSToken }
|
32
33
|
|
34
|
+
class Faraday::Request::ReadOnly
|
35
|
+
def initialize(app)
|
36
|
+
@app = app
|
37
|
+
end
|
38
|
+
|
39
|
+
def call(env)
|
40
|
+
return @app.call(env) if allowed_request?(env)
|
41
|
+
|
42
|
+
if Yao.config.raise_on_write
|
43
|
+
raise Yao::ReadOnlyViolationError
|
44
|
+
elsif Yao.config.noop_on_write
|
45
|
+
env
|
46
|
+
else
|
47
|
+
@app.call(env)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
ALLOWED_REQUESTS = [
|
54
|
+
{method: :post, path: "/v2.0/tokens"}
|
55
|
+
]
|
56
|
+
|
57
|
+
def allowed_request?(env)
|
58
|
+
return true if env[:method] == :get
|
59
|
+
|
60
|
+
ALLOWED_REQUESTS.any? do |allowed|
|
61
|
+
env[:method] == allowed[:method] && env[:url].path == allowed[:path]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
Faraday::Request.register_middleware read_only: -> { Faraday::Request::ReadOnly }
|
66
|
+
|
33
67
|
class Faraday::Response::OSDumper < Faraday::Response::Middleware
|
34
68
|
def on_complete(env)
|
35
69
|
require 'pp'
|
@@ -74,6 +108,8 @@ class Faraday::Response::OSResponseRecorder < Faraday::Response::Middleware
|
|
74
108
|
def on_complete(env)
|
75
109
|
require 'pathname'
|
76
110
|
root = Pathname.new(File.expand_path('../../../tmp', __FILE__))
|
111
|
+
Dir.mkdir(root) unless File.exist?(root)
|
112
|
+
|
77
113
|
path = [env.method.to_s.upcase, env.url.path.gsub('/', '-')].join("-") + ".json"
|
78
114
|
|
79
115
|
puts root.join(path)
|
@@ -84,7 +120,6 @@ class Faraday::Response::OSResponseRecorder < Faraday::Response::Middleware
|
|
84
120
|
end
|
85
121
|
Faraday::Response.register_middleware os_response_recorder: -> { Faraday::Response::OSResponseRecorder }
|
86
122
|
|
87
|
-
require 'yao/server_error'
|
88
123
|
class Faraday::Response::OSErrorDetector < Faraday::Response::Middleware
|
89
124
|
# TODO: Better handling, respecting official doc
|
90
125
|
def on_complete(env)
|
data/lib/yao/mode.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Yao
|
2
|
+
module Mode
|
3
|
+
def read_only!(&blk)
|
4
|
+
raise unless block_given?
|
5
|
+
|
6
|
+
raise_on_write_org = Yao.config.raise_on_write
|
7
|
+
noop_on_write_org = Yao.config.noop_on_write
|
8
|
+
|
9
|
+
Yao.config.set :noop_on_write, false if noop_on_write_org
|
10
|
+
Yao.config.set :raise_on_write, true
|
11
|
+
begin
|
12
|
+
yield
|
13
|
+
ensure
|
14
|
+
Yao.config.set :raise_on_write, raise_on_write_org
|
15
|
+
Yao.config.set :noop_on_write, noop_on_write_org
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def read_only(&blk)
|
20
|
+
raise unless block_given?
|
21
|
+
|
22
|
+
noop_on_write_org = Yao.config.noop_on_write
|
23
|
+
raise_on_write_org = Yao.config.raise_on_write
|
24
|
+
|
25
|
+
Yao.config.set :raise_on_write, false if raise_on_write_org
|
26
|
+
Yao.config.set :noop_on_write, true
|
27
|
+
begin
|
28
|
+
yield
|
29
|
+
ensure
|
30
|
+
Yao.config.set :noop_on_write, noop_on_write_org
|
31
|
+
Yao.config.set :raise_on_write, raise_on_write_org
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -57,18 +57,18 @@ module Yao::Resources
|
|
57
57
|
def as_member(&blk)
|
58
58
|
if @admin
|
59
59
|
@admin = false
|
60
|
-
result = yield
|
60
|
+
result = yield
|
61
61
|
@admin = true
|
62
62
|
result
|
63
63
|
else
|
64
|
-
yield
|
64
|
+
yield
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
def with_resources_path(path, &blk)
|
69
69
|
original = @resources_path
|
70
70
|
@resources_path = path
|
71
|
-
result = yield
|
71
|
+
result = yield
|
72
72
|
@resources_path = original
|
73
73
|
|
74
74
|
result
|
data/lib/yao/version.rb
CHANGED
data/lib/yao.rb
CHANGED
data/test/config.rb
CHANGED
@@ -0,0 +1,117 @@
|
|
1
|
+
module AuthStub
|
2
|
+
def stub_auth_request(auth_url, username, password, tenant)
|
3
|
+
stub_request(:post, "#{auth_url}/v2.0/tokens")
|
4
|
+
.with(
|
5
|
+
body: auth_json(username, password, tenant)
|
6
|
+
).to_return(
|
7
|
+
:status => 200,
|
8
|
+
:body => response_json(auth_url, username, tenant),
|
9
|
+
:headers => {'Content-Type' => 'application/json'}
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def auth_json(username, password, tenant)
|
16
|
+
json = <<-JSON
|
17
|
+
{"auth":{"passwordCredentials":{"username":"#{username}","password":"#{password}"},"tenantName":"#{tenant}"}}
|
18
|
+
JSON
|
19
|
+
|
20
|
+
json.strip
|
21
|
+
end
|
22
|
+
|
23
|
+
def response_json(auth_url, username, tenant)
|
24
|
+
<<-JSON
|
25
|
+
{
|
26
|
+
"access": {
|
27
|
+
"token": {
|
28
|
+
"issued_at": "#{Time.now.iso8601}",
|
29
|
+
"expires": "#{(Time.now + 3600).utc.iso8601}",
|
30
|
+
"id": "aaaa166533fd49f3b11b1cdce2430000",
|
31
|
+
"tenant": {
|
32
|
+
"description": "Testing",
|
33
|
+
"enabled": true,
|
34
|
+
"id": "aaaa166533fd49f3b11b1cdce2430000",
|
35
|
+
"name": "#{tenant}"
|
36
|
+
}
|
37
|
+
},
|
38
|
+
"serviceCatalog": [
|
39
|
+
{
|
40
|
+
"endpoints": [
|
41
|
+
{
|
42
|
+
"adminURL": "http://nova-endpoint.example.com:8774/v2/b598bf98671c47e1b955f8c9660e3c44",
|
43
|
+
"region": "RegionOne",
|
44
|
+
"internalURL": "http://nova-endpoint.example.com:8774/v2/b598bf98671c47e1b955f8c9660e3c44",
|
45
|
+
"id": "1a66e6af97c440b2a7bbc4f9735923d9",
|
46
|
+
"publicURL": "http://nova-endpoint.example.com:8774/v2/b598bf98671c47e1b955f8c9660e3c44"
|
47
|
+
}
|
48
|
+
],
|
49
|
+
"endpoints_links": [],
|
50
|
+
"type": "compute",
|
51
|
+
"name": "nova"
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"endpoints": [
|
55
|
+
{
|
56
|
+
"adminURL": "http://neutron-endpoint.example.com:9696/",
|
57
|
+
"region": "RegionOne",
|
58
|
+
"internalURL": "http://neutron-endpoint.example.com:9696/",
|
59
|
+
"id": "0418104da877468ca65d739142fa3454",
|
60
|
+
"publicURL": "http://neutron-endpoint.example.com:9696/"
|
61
|
+
}
|
62
|
+
],
|
63
|
+
"endpoints_links": [],
|
64
|
+
"type": "network",
|
65
|
+
"name": "neutron"
|
66
|
+
},
|
67
|
+
{
|
68
|
+
"endpoints": [
|
69
|
+
{
|
70
|
+
"adminURL": "http://glance-endpoint.example.com:9292",
|
71
|
+
"region": "RegionOne",
|
72
|
+
"internalURL": "http://glance-endpoint.example.com:9292",
|
73
|
+
"id": "246f33509ff64802b86eb081307ecec0",
|
74
|
+
"publicURL": "http://glance-endpoint.example.com:9292"
|
75
|
+
}
|
76
|
+
],
|
77
|
+
"endpoints_links": [],
|
78
|
+
"type": "image",
|
79
|
+
"name": "glance"
|
80
|
+
},
|
81
|
+
{
|
82
|
+
"endpoints": [
|
83
|
+
{
|
84
|
+
"adminURL": "#{auth_url}/v2.0",
|
85
|
+
"region": "RegionOne",
|
86
|
+
"internalURL": "http://endpoint.example.com:5000/v2.0",
|
87
|
+
"id": "2b982236cc084128bf42b647c1b7fb49",
|
88
|
+
"publicURL": "http://endpoint.example.com:5000/v2.0"
|
89
|
+
}
|
90
|
+
],
|
91
|
+
"endpoints_links": [],
|
92
|
+
"type": "identity",
|
93
|
+
"name": "keystone"
|
94
|
+
}
|
95
|
+
],
|
96
|
+
"user": {
|
97
|
+
"username": "#{username}",
|
98
|
+
"roles_links": [],
|
99
|
+
"id": "a9994b2dee82423da7da572397d3157a",
|
100
|
+
"roles": [
|
101
|
+
{
|
102
|
+
"name": "admin"
|
103
|
+
}
|
104
|
+
],
|
105
|
+
"name": "#{username}"
|
106
|
+
},
|
107
|
+
"metadata": {
|
108
|
+
"is_admin": 0,
|
109
|
+
"roles": [
|
110
|
+
"ce5330c512cc4bd289b3a725ad1106b7"
|
111
|
+
]
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
JSON
|
116
|
+
end
|
117
|
+
end
|
data/test/yao/test_auth.rb
CHANGED
@@ -1,107 +1,16 @@
|
|
1
1
|
class TestAuth < Test::Unit::TestCase
|
2
|
-
|
3
|
-
AUTH_JSON = \
|
4
|
-
"{\"auth\":{\"passwordCredentials\":{\"username\":\"udzura\",\"password\":\"XXXXXXXX\"},\"tenantName\":\"example\"}}"
|
5
|
-
|
6
|
-
RESPONSE_JSON = <<-JSON
|
7
|
-
{
|
8
|
-
"access": {
|
9
|
-
"token": {
|
10
|
-
"issued_at": "2015-08-31T03:58:36.073232",
|
11
|
-
"expires": "2015-09-01T03:58:36Z",
|
12
|
-
"id": "aaaa166533fd49f3b11b1cdce2430000",
|
13
|
-
"tenant": {
|
14
|
-
"description": "Testing",
|
15
|
-
"enabled": true,
|
16
|
-
"id": "aaaa166533fd49f3b11b1cdce2430000",
|
17
|
-
"name": "example"
|
18
|
-
}
|
19
|
-
},
|
20
|
-
"serviceCatalog": [
|
21
|
-
{
|
22
|
-
"endpoints": [
|
23
|
-
{
|
24
|
-
"adminURL": "http://nova-endpoint.example.com:8774/v2/b598bf98671c47e1b955f8c9660e3c44",
|
25
|
-
"region": "RegionOne",
|
26
|
-
"internalURL": "http://nova-endpoint.example.com:8774/v2/b598bf98671c47e1b955f8c9660e3c44",
|
27
|
-
"id": "1a66e6af97c440b2a7bbc4f9735923d9",
|
28
|
-
"publicURL": "http://nova-endpoint.example.com:8774/v2/b598bf98671c47e1b955f8c9660e3c44"
|
29
|
-
}
|
30
|
-
],
|
31
|
-
"endpoints_links": [],
|
32
|
-
"type": "compute",
|
33
|
-
"name": "nova"
|
34
|
-
},
|
35
|
-
{
|
36
|
-
"endpoints": [
|
37
|
-
{
|
38
|
-
"adminURL": "http://neutron-endpoint.example.com:9696/",
|
39
|
-
"region": "RegionOne",
|
40
|
-
"internalURL": "http://neutron-endpoint.example.com:9696/",
|
41
|
-
"id": "0418104da877468ca65d739142fa3454",
|
42
|
-
"publicURL": "http://neutron-endpoint.example.com:9696/"
|
43
|
-
}
|
44
|
-
],
|
45
|
-
"endpoints_links": [],
|
46
|
-
"type": "network",
|
47
|
-
"name": "neutron"
|
48
|
-
},
|
49
|
-
{
|
50
|
-
"endpoints": [
|
51
|
-
{
|
52
|
-
"adminURL": "http://glance-endpoint.example.com:9292",
|
53
|
-
"region": "RegionOne",
|
54
|
-
"internalURL": "http://glance-endpoint.example.com:9292",
|
55
|
-
"id": "246f33509ff64802b86eb081307ecec0",
|
56
|
-
"publicURL": "http://glance-endpoint.example.com:9292"
|
57
|
-
}
|
58
|
-
],
|
59
|
-
"endpoints_links": [],
|
60
|
-
"type": "image",
|
61
|
-
"name": "glance"
|
62
|
-
},
|
63
|
-
{
|
64
|
-
"endpoints": [
|
65
|
-
{
|
66
|
-
"adminURL": "http://endpoint.example.com:12345/v2.0",
|
67
|
-
"region": "RegionOne",
|
68
|
-
"internalURL": "http://endpoint.example.com:5000/v2.0",
|
69
|
-
"id": "2b982236cc084128bf42b647c1b7fb49",
|
70
|
-
"publicURL": "http://endpoint.example.com:5000/v2.0"
|
71
|
-
}
|
72
|
-
],
|
73
|
-
"endpoints_links": [],
|
74
|
-
"type": "identity",
|
75
|
-
"name": "keystone"
|
76
|
-
}
|
77
|
-
],
|
78
|
-
"user": {
|
79
|
-
"username": "udzura",
|
80
|
-
"roles_links": [],
|
81
|
-
"id": "a9994b2dee82423da7da572397d3157a",
|
82
|
-
"roles": [
|
83
|
-
{
|
84
|
-
"name": "admin"
|
85
|
-
}
|
86
|
-
],
|
87
|
-
"name": "udzura"
|
88
|
-
},
|
89
|
-
"metadata": {
|
90
|
-
"is_admin": 0,
|
91
|
-
"roles": [
|
92
|
-
"ce5330c512cc4bd289b3a725ad1106b7"
|
93
|
-
]
|
94
|
-
}
|
95
|
-
}
|
96
|
-
}
|
97
|
-
JSON
|
2
|
+
include AuthStub
|
98
3
|
|
99
4
|
def setup
|
100
|
-
|
101
|
-
|
5
|
+
@auth_url = "http://endpoint.example.com:12345"
|
6
|
+
username = "udzura"
|
7
|
+
tenant = "example"
|
8
|
+
password = "XXXXXXXX"
|
9
|
+
|
10
|
+
stub_auth_request(@auth_url, username, password, tenant)
|
102
11
|
|
103
|
-
Yao.config.set :auth_url,
|
104
|
-
@token = Yao::Auth.new(tenant_name:
|
12
|
+
Yao.config.set :auth_url, @auth_url
|
13
|
+
@token = Yao::Auth.new(tenant_name: tenant, username: username, password: password)
|
105
14
|
end
|
106
15
|
|
107
16
|
def teardown
|
@@ -132,8 +41,7 @@ class TestAuth < Test::Unit::TestCase
|
|
132
41
|
|
133
42
|
def test_token_is_valid
|
134
43
|
assert { @token.token == "aaaa166533fd49f3b11b1cdce2430000" }
|
135
|
-
assert { @token.issued_at ==
|
136
|
-
assert { @token.expire_at == Time.parse("2015-09-01T03:58:36Z") }
|
44
|
+
assert { @token.expire_at - @token.issued_at == 3600 }
|
137
45
|
assert { @token.endpoints.size == 4 }
|
138
46
|
end
|
139
47
|
|
data/test/yao/test_client.rb
CHANGED
@@ -11,6 +11,7 @@ class TestClient < Test::Unit::TestCase
|
|
11
11
|
handlers = [
|
12
12
|
Faraday::Request::Accept,
|
13
13
|
Faraday::Request::UrlEncoded,
|
14
|
+
Faraday::Request::ReadOnly,
|
14
15
|
Faraday::Response::OSErrorDetector,
|
15
16
|
FaradayMiddleware::ParseJson,
|
16
17
|
Faraday::Adapter::NetHttp
|
@@ -24,6 +25,7 @@ class TestClient < Test::Unit::TestCase
|
|
24
25
|
Faraday::Request::Accept,
|
25
26
|
Faraday::Request::UrlEncoded,
|
26
27
|
Faraday::Request::OSToken,
|
28
|
+
Faraday::Request::ReadOnly,
|
27
29
|
Faraday::Response::OSErrorDetector,
|
28
30
|
FaradayMiddleware::ParseJson,
|
29
31
|
Faraday::Adapter::NetHttp
|
@@ -38,6 +40,7 @@ class TestClient < Test::Unit::TestCase
|
|
38
40
|
handlers = [
|
39
41
|
Faraday::Request::Accept,
|
40
42
|
Faraday::Request::UrlEncoded,
|
43
|
+
Faraday::Request::ReadOnly,
|
41
44
|
Faraday::Response::OSErrorDetector,
|
42
45
|
FaradayMiddleware::ParseJson,
|
43
46
|
Faraday::Response::Logger,
|
@@ -0,0 +1,114 @@
|
|
1
|
+
class TestOnly < Test::Unit::TestCase
|
2
|
+
include AuthStub
|
3
|
+
|
4
|
+
def setup
|
5
|
+
auth_url = "http://endpoint.example.com:12345"
|
6
|
+
username = "udzura"
|
7
|
+
tenant = "example"
|
8
|
+
password = "XXXXXXXX"
|
9
|
+
|
10
|
+
stub_auth_request(auth_url, username, password, tenant)
|
11
|
+
|
12
|
+
Yao.configure do
|
13
|
+
auth_url auth_url
|
14
|
+
username username
|
15
|
+
tenant_name tenant
|
16
|
+
password password
|
17
|
+
end
|
18
|
+
|
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")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_read_only
|
25
|
+
Yao.read_only do
|
26
|
+
Yao::User.get_by_name(@username)
|
27
|
+
Yao::User.create(name: "foo", email: "bar", password: "baz")
|
28
|
+
end
|
29
|
+
|
30
|
+
assert_requested @get_stub
|
31
|
+
assert_not_requested @post_stub
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_read_only!
|
35
|
+
assert_raise Yao::ReadOnlyViolationError do
|
36
|
+
Yao.read_only! do
|
37
|
+
Yao::User.get_by_name(@username)
|
38
|
+
Yao::User.create(name: "foo", email: "bar", password: "baz")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
assert_requested @get_stub
|
43
|
+
assert_not_requested @post_stub
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_read_only_flags_life_cycle
|
47
|
+
assert_false Yao.config.noop_on_write
|
48
|
+
assert_false Yao.config.raise_on_write
|
49
|
+
|
50
|
+
assert_raise RuntimeError do
|
51
|
+
Yao.read_only do
|
52
|
+
assert_true Yao.config.noop_on_write
|
53
|
+
raise
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
assert_false Yao.config.noop_on_write
|
58
|
+
assert_false Yao.config.raise_on_write
|
59
|
+
|
60
|
+
assert_raise RuntimeError do
|
61
|
+
Yao.read_only! do
|
62
|
+
assert_true Yao.config.raise_on_write
|
63
|
+
raise
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
assert_false Yao.config.noop_on_write
|
68
|
+
assert_false Yao.config.raise_on_write
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_reentrant_condition
|
72
|
+
Yao.read_only do
|
73
|
+
assert_true Yao.config.noop_on_write
|
74
|
+
|
75
|
+
Yao.read_only do
|
76
|
+
assert_true Yao.config.noop_on_write
|
77
|
+
end
|
78
|
+
|
79
|
+
assert_true Yao.config.noop_on_write
|
80
|
+
end
|
81
|
+
|
82
|
+
Yao.read_only! do
|
83
|
+
assert_true Yao.config.raise_on_write
|
84
|
+
|
85
|
+
Yao.read_only! do
|
86
|
+
assert_true Yao.config.raise_on_write
|
87
|
+
end
|
88
|
+
|
89
|
+
assert_true Yao.config.raise_on_write
|
90
|
+
end
|
91
|
+
|
92
|
+
Yao.read_only! do
|
93
|
+
assert_true Yao.config.raise_on_write
|
94
|
+
|
95
|
+
Yao.read_only do
|
96
|
+
assert_true Yao.config.noop_on_write
|
97
|
+
assert_false Yao.config.raise_on_write
|
98
|
+
end
|
99
|
+
|
100
|
+
assert_true Yao.config.raise_on_write
|
101
|
+
end
|
102
|
+
|
103
|
+
Yao.read_only do
|
104
|
+
assert_true Yao.config.noop_on_write
|
105
|
+
|
106
|
+
Yao.read_only! do
|
107
|
+
assert_true Yao.config.raise_on_write
|
108
|
+
assert_false Yao.config.noop_on_write
|
109
|
+
end
|
110
|
+
|
111
|
+
assert_true Yao.config.noop_on_write
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/test/yao/test_token.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class TestToken < Test::Unit::TestCase
|
2
|
+
include AuthStub
|
3
|
+
|
2
4
|
def setup
|
3
5
|
stub(Yao.config).debug { false }
|
4
6
|
stub(Yao.config).debug_record_response { false }
|
@@ -22,37 +24,18 @@ class TestToken < Test::Unit::TestCase
|
|
22
24
|
assert { ! t.expired? }
|
23
25
|
end
|
24
26
|
|
25
|
-
AUTH_JSON = \
|
26
|
-
"{\"auth\":{\"passwordCredentials\":{\"username\":\"udzura\",\"password\":\"XXXXXXXX\"},\"tenantName\":\"example\"}}"
|
27
|
-
|
28
|
-
def gen_response_json
|
29
|
-
<<-JSON
|
30
|
-
{
|
31
|
-
"access": {
|
32
|
-
"token": {
|
33
|
-
"issued_at": "#{Time.now.iso8601}",
|
34
|
-
"expires": "#{(Time.now + 3600).utc.iso8601}",
|
35
|
-
"id": "aaaa166533fd49f3b11b1cdce2430000",
|
36
|
-
"tenant": {
|
37
|
-
"description": "Testing",
|
38
|
-
"enabled": true,
|
39
|
-
"id": "aaaa166533fd49f3b11b1cdce2430000",
|
40
|
-
"name": "example"
|
41
|
-
}
|
42
|
-
},
|
43
|
-
"serviceCatalog": []
|
44
|
-
}
|
45
|
-
}
|
46
|
-
JSON
|
47
|
-
end
|
48
|
-
|
49
27
|
def test_reflesh
|
28
|
+
auth_url = "http://endpoint.example.com:12345"
|
29
|
+
username = "udzura"
|
30
|
+
tenant = "example"
|
31
|
+
password = "XXXXXXXX"
|
32
|
+
|
50
33
|
auth_info = {
|
51
34
|
auth: {
|
52
35
|
passwordCredentials: {
|
53
|
-
username:
|
36
|
+
username: username, password: password
|
54
37
|
},
|
55
|
-
tenantName:
|
38
|
+
tenantName: tenant
|
56
39
|
}
|
57
40
|
}
|
58
41
|
t = Yao::Token.new(auth_info)
|
@@ -63,10 +46,9 @@ class TestToken < Test::Unit::TestCase
|
|
63
46
|
})
|
64
47
|
assert { t.token == "old_token" }
|
65
48
|
|
66
|
-
|
67
|
-
.to_return(:status => 200, :body => gen_response_json, :headers => {'Content-Type' => 'application/json'})
|
49
|
+
stub_auth_request(auth_url, username, password, tenant)
|
68
50
|
|
69
|
-
Yao.config.auth_url
|
51
|
+
Yao.config.auth_url auth_url
|
70
52
|
t.reflesh(Yao.default_client.default)
|
71
53
|
|
72
54
|
assert { t.token == "aaaa166533fd49f3b11b1cdce2430000" }
|
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.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uchio, KONDO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -169,8 +169,10 @@ files:
|
|
169
169
|
- lib/yao/auth.rb
|
170
170
|
- lib/yao/client.rb
|
171
171
|
- lib/yao/config.rb
|
172
|
+
- lib/yao/error.rb
|
172
173
|
- lib/yao/faraday_middlewares.rb
|
173
174
|
- lib/yao/is_openstack_client.rb
|
175
|
+
- lib/yao/mode.rb
|
174
176
|
- lib/yao/plugins.rb
|
175
177
|
- lib/yao/plugins/default_client_generator.rb
|
176
178
|
- lib/yao/plugins/registry.rb
|
@@ -198,14 +200,15 @@ files:
|
|
198
200
|
- lib/yao/resources/subnet.rb
|
199
201
|
- lib/yao/resources/tenant.rb
|
200
202
|
- lib/yao/resources/user.rb
|
201
|
-
- lib/yao/server_error.rb
|
202
203
|
- lib/yao/token.rb
|
203
204
|
- lib/yao/version.rb
|
204
205
|
- test/config.rb
|
206
|
+
- test/support/auth_stub.rb
|
205
207
|
- test/yao/test_auth.rb
|
206
208
|
- test/yao/test_client.rb
|
207
209
|
- test/yao/test_client_plugin.rb
|
208
210
|
- test/yao/test_config.rb
|
211
|
+
- test/yao/test_read_only.rb
|
209
212
|
- test/yao/test_server_error.rb
|
210
213
|
- test/yao/test_token.rb
|
211
214
|
- yao-logo.png
|
@@ -230,15 +233,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
233
|
version: '0'
|
231
234
|
requirements: []
|
232
235
|
rubyforge_project:
|
233
|
-
rubygems_version: 2.
|
236
|
+
rubygems_version: 2.2.3
|
234
237
|
signing_key:
|
235
238
|
specification_version: 4
|
236
239
|
summary: Yet Another OpenStack API Wrapper that rocks!!
|
237
240
|
test_files:
|
238
241
|
- test/config.rb
|
242
|
+
- test/support/auth_stub.rb
|
239
243
|
- test/yao/test_auth.rb
|
240
244
|
- test/yao/test_client.rb
|
241
245
|
- test/yao/test_client_plugin.rb
|
242
246
|
- test/yao/test_config.rb
|
247
|
+
- test/yao/test_read_only.rb
|
243
248
|
- test/yao/test_server_error.rb
|
244
249
|
- test/yao/test_token.rb
|