Add ability to update the session data of any instantiated services
This commit is contained in:
@@ -14,6 +14,13 @@ module Aviator
|
||||
super("The config file at #{ path } does not exist!")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class SessionNotAuthenticatedError < StandardError
|
||||
def initialize
|
||||
super("Session is not authenticated. Please authenticate before proceeding.")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def initialize(opts={})
|
||||
@@ -42,6 +49,7 @@ module Aviator
|
||||
|
||||
if response.status == 200
|
||||
@auth_info = response.body
|
||||
update_services_session_data
|
||||
else
|
||||
raise AuthenticationFailedError.new(response.body)
|
||||
end
|
||||
@@ -65,6 +73,11 @@ module Aviator
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def auth_info
|
||||
@auth_info
|
||||
end
|
||||
|
||||
|
||||
def auth_service
|
||||
@@ -96,10 +109,14 @@ module Aviator
|
||||
end
|
||||
|
||||
|
||||
def auth_info
|
||||
@auth_info
|
||||
def update_services_session_data
|
||||
return unless @services
|
||||
|
||||
@services.each do |name, obj|
|
||||
obj.default_session_data = auth_info
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -44,6 +44,24 @@ class Aviator::Test
|
||||
|
||||
session.authenticated?.must_equal true
|
||||
end
|
||||
|
||||
|
||||
it 'updates the session data of its service objects' do
|
||||
session = new_session
|
||||
session.authenticate
|
||||
|
||||
keystone = session.identity_service
|
||||
|
||||
session_data_1 = keystone.default_session_data
|
||||
|
||||
session.authenticate
|
||||
|
||||
session.identity_service.must_equal keystone
|
||||
|
||||
new_token = session.identity_service.default_session_data[:access][:token][:id]
|
||||
new_token.wont_equal session_data_1[:access][:token][:id]
|
||||
keystone.default_session_data[:access][:token][:id].must_equal new_token
|
||||
end
|
||||
|
||||
end # describe '#authenticate'
|
||||
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
---
|
||||
http_interactions:
|
||||
- request:
|
||||
method: post
|
||||
uri: <HOST_URI>:5000/v2.0/tokens
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: ! '{"auth":{"passwordCredentials":{"username":"admin","password":"<PASSWORD>"},"tenantName":"admin"}}'
|
||||
headers:
|
||||
Content-Type:
|
||||
- application/json
|
||||
User-Agent:
|
||||
- Faraday v0.8.8
|
||||
response:
|
||||
status:
|
||||
code: 200
|
||||
message:
|
||||
headers:
|
||||
vary:
|
||||
- X-Auth-Token
|
||||
content-type:
|
||||
- application/json
|
||||
content-length:
|
||||
- '2648'
|
||||
date:
|
||||
- Thu, 29 Aug 2013 03:12:37 GMT
|
||||
connection:
|
||||
- close
|
||||
body:
|
||||
encoding: US-ASCII
|
||||
string: ! '{"access": {"token": {"issued_at": "2013-08-29T03:12:37.169969",
|
||||
"expires": "2013-08-30T03:12:37Z", "id": "8f26b1737f984153b9f8adc7e2a3b485",
|
||||
"tenant": {"description": null, "enabled": true, "id": "3cab25130620477b8b03f1bfa8741603",
|
||||
"name": "admin"}}, "serviceCatalog": [{"endpoints": [{"adminURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603",
|
||||
"region": "RegionOne", "internalURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603",
|
||||
"id": "3b72a66bf2f0491bb8dba827cade0d48", "publicURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603"}],
|
||||
"endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints": [{"adminURL":
|
||||
"http://192.168.56.11:3333", "region": "RegionOne", "internalURL": "http://192.168.56.11:3333",
|
||||
"id": "482f749b370c40eab8788d6d0bc47f48", "publicURL": "http://192.168.56.11:3333"}],
|
||||
"endpoints_links": [], "type": "s3", "name": "s3"}, {"endpoints": [{"adminURL":
|
||||
"http://192.168.56.11:9292", "region": "RegionOne", "internalURL": "http://192.168.56.11:9292",
|
||||
"id": "0cd5d5d5a0c24721a0392b47c89e3640", "publicURL": "http://192.168.56.11:9292"}],
|
||||
"endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints": [{"adminURL":
|
||||
"http://192.168.56.11:8777", "region": "RegionOne", "internalURL": "http://192.168.56.11:8777",
|
||||
"id": "4eb4edec1d2647bfb8ba4f9a5757169d", "publicURL": "http://192.168.56.11:8777"}],
|
||||
"endpoints_links": [], "type": "metering", "name": "ceilometer"}, {"endpoints":
|
||||
[{"adminURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603",
|
||||
"region": "RegionOne", "internalURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603",
|
||||
"id": "009e8a41953d439f845b2a0c0dc28b73", "publicURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603"}],
|
||||
"endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints":
|
||||
[{"adminURL": "http://192.168.56.11:8773/services/Admin", "region": "RegionOne",
|
||||
"internalURL": "http://192.168.56.11:8773/services/Cloud", "id": "6820836ec6834548bf7b54da0271dded",
|
||||
"publicURL": "http://192.168.56.11:8773/services/Cloud"}], "endpoints_links":
|
||||
[], "type": "ec2", "name": "ec2"}, {"endpoints": [{"adminURL": "http://192.168.56.11:35357/v2.0",
|
||||
"region": "RegionOne", "internalURL": "http://192.168.56.11:5000/v2.0", "id":
|
||||
"24a95f51f67949e784971e97463ee4d8", "publicURL": "http://192.168.56.11:5000/v2.0"}],
|
||||
"endpoints_links": [], "type": "identity", "name": "keystone"}], "user": {"username":
|
||||
"admin", "roles_links": [], "id": "cbbcc4f7aef6435fa2da7e5f0b2f1e97", "roles":
|
||||
[{"name": "admin"}], "name": "admin"}, "metadata": {"is_admin": 0, "roles":
|
||||
["01a81f2dbb3441f1aaa8fe68a7c6f546"]}}}'
|
||||
http_version:
|
||||
recorded_at: Thu, 29 Aug 2013 07:12:10 GMT
|
||||
- request:
|
||||
method: post
|
||||
uri: <HOST_URI>:5000/v2.0/tokens
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: ! '{"auth":{"passwordCredentials":{"username":"admin","password":"<PASSWORD>"},"tenantName":"admin"}}'
|
||||
headers:
|
||||
Content-Type:
|
||||
- application/json
|
||||
User-Agent:
|
||||
- Faraday v0.8.8
|
||||
response:
|
||||
status:
|
||||
code: 200
|
||||
message:
|
||||
headers:
|
||||
vary:
|
||||
- X-Auth-Token
|
||||
content-type:
|
||||
- application/json
|
||||
content-length:
|
||||
- '2648'
|
||||
date:
|
||||
- Thu, 29 Aug 2013 03:12:38 GMT
|
||||
connection:
|
||||
- close
|
||||
body:
|
||||
encoding: US-ASCII
|
||||
string: ! '{"access": {"token": {"issued_at": "2013-08-29T03:12:37.563279",
|
||||
"expires": "2013-08-30T03:12:37Z", "id": "1cf85706201e4e2db86ec1af3b16e295",
|
||||
"tenant": {"description": null, "enabled": true, "id": "3cab25130620477b8b03f1bfa8741603",
|
||||
"name": "admin"}}, "serviceCatalog": [{"endpoints": [{"adminURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603",
|
||||
"region": "RegionOne", "internalURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603",
|
||||
"id": "3b72a66bf2f0491bb8dba827cade0d48", "publicURL": "http://192.168.56.11:8774/v2/3cab25130620477b8b03f1bfa8741603"}],
|
||||
"endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints": [{"adminURL":
|
||||
"http://192.168.56.11:3333", "region": "RegionOne", "internalURL": "http://192.168.56.11:3333",
|
||||
"id": "482f749b370c40eab8788d6d0bc47f48", "publicURL": "http://192.168.56.11:3333"}],
|
||||
"endpoints_links": [], "type": "s3", "name": "s3"}, {"endpoints": [{"adminURL":
|
||||
"http://192.168.56.11:9292", "region": "RegionOne", "internalURL": "http://192.168.56.11:9292",
|
||||
"id": "0cd5d5d5a0c24721a0392b47c89e3640", "publicURL": "http://192.168.56.11:9292"}],
|
||||
"endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints": [{"adminURL":
|
||||
"http://192.168.56.11:8777", "region": "RegionOne", "internalURL": "http://192.168.56.11:8777",
|
||||
"id": "4eb4edec1d2647bfb8ba4f9a5757169d", "publicURL": "http://192.168.56.11:8777"}],
|
||||
"endpoints_links": [], "type": "metering", "name": "ceilometer"}, {"endpoints":
|
||||
[{"adminURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603",
|
||||
"region": "RegionOne", "internalURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603",
|
||||
"id": "009e8a41953d439f845b2a0c0dc28b73", "publicURL": "http://192.168.56.11:8776/v1/3cab25130620477b8b03f1bfa8741603"}],
|
||||
"endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints":
|
||||
[{"adminURL": "http://192.168.56.11:8773/services/Admin", "region": "RegionOne",
|
||||
"internalURL": "http://192.168.56.11:8773/services/Cloud", "id": "6820836ec6834548bf7b54da0271dded",
|
||||
"publicURL": "http://192.168.56.11:8773/services/Cloud"}], "endpoints_links":
|
||||
[], "type": "ec2", "name": "ec2"}, {"endpoints": [{"adminURL": "http://192.168.56.11:35357/v2.0",
|
||||
"region": "RegionOne", "internalURL": "http://192.168.56.11:5000/v2.0", "id":
|
||||
"24a95f51f67949e784971e97463ee4d8", "publicURL": "http://192.168.56.11:5000/v2.0"}],
|
||||
"endpoints_links": [], "type": "identity", "name": "keystone"}], "user": {"username":
|
||||
"admin", "roles_links": [], "id": "cbbcc4f7aef6435fa2da7e5f0b2f1e97", "roles":
|
||||
[{"name": "admin"}], "name": "admin"}, "metadata": {"is_admin": 0, "roles":
|
||||
["01a81f2dbb3441f1aaa8fe68a7c6f546"]}}}'
|
||||
http_version:
|
||||
recorded_at: Thu, 29 Aug 2013 07:12:11 GMT
|
||||
recorded_with: VCR 2.5.0
|
||||
Reference in New Issue
Block a user