mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack] Make current_user and current_token accessible to services
- This is for users with no permission to access keystone admin API Signed-off-by: Nelvin Driz <nelvindriz@live.com>
This commit is contained in:
parent
aa79bf47fc
commit
7b46964770
5 changed files with 60 additions and 13 deletions
|
@ -103,8 +103,6 @@ module Fog
|
|||
|
||||
svc = body['access']['serviceCatalog'].
|
||||
detect{|x| @service_name.include?(x['type']) }
|
||||
identity_svc = body['access']['serviceCatalog'].
|
||||
detect{|x| @identity_service_name.include?(x['type']) } if @identity_service_name
|
||||
|
||||
unless svc
|
||||
unless @openstack_tenant
|
||||
|
@ -124,15 +122,20 @@ module Fog
|
|||
body = retrieve_tokens_v2(connection, req_body, uri)
|
||||
svc = body['access']['serviceCatalog'].
|
||||
detect{|x| @service_name.include?(x['type']) }
|
||||
identity_svc = body['access']['serviceCatalog'].
|
||||
detect{|x| @identity_service_name.include?(x['type']) } if @identity_service_name
|
||||
end
|
||||
|
||||
identity_svc = body['access']['serviceCatalog'].
|
||||
detect{|x| @identity_service_name.include?(x['type']) } if @identity_service_name
|
||||
tenant = body['access']['token']['tenant']
|
||||
user = body['access']['user']
|
||||
|
||||
mgmt_url = svc['endpoints'].detect{|x| x[@endpoint_type]}[@endpoint_type]
|
||||
identity_url = identity_svc['endpoints'].detect{|x| x['publicURL']}['publicURL'] if identity_svc
|
||||
token = body['access']['token']['id']
|
||||
|
||||
{
|
||||
:user => user,
|
||||
:tenant => tenant,
|
||||
:token => token,
|
||||
:server_management_url => mgmt_url,
|
||||
:identity_public_endpoint => identity_url,
|
||||
|
|
|
@ -9,7 +9,8 @@ module Fog
|
|||
requires :openstack_auth_url
|
||||
recognizes :openstack_auth_token, :openstack_management_url,
|
||||
:persistent, :openstack_service_name, :openstack_tenant,
|
||||
:openstack_api_key, :openstack_username, :openstack_identity_endpoint
|
||||
:openstack_api_key, :openstack_username, :openstack_identity_endpoint,
|
||||
:current_user, :current_tenant
|
||||
|
||||
## MODELS
|
||||
#
|
||||
|
@ -208,6 +209,8 @@ module Fog
|
|||
|
||||
class Real
|
||||
attr_reader :auth_token
|
||||
attr_reader :current_user
|
||||
attr_reader :current_tenant
|
||||
|
||||
def initialize(options={})
|
||||
@openstack_auth_token = options[:openstack_auth_token]
|
||||
|
@ -232,6 +235,9 @@ module Fog
|
|||
|
||||
@connection_options = options[:connection_options] || {}
|
||||
|
||||
@current_user = options[:current_user]
|
||||
@current_tenant = options[:current_tenant]
|
||||
|
||||
authenticate
|
||||
|
||||
@persistent = options[:persistent] || false
|
||||
|
@ -243,7 +249,9 @@ module Fog
|
|||
:openstack_auth_url => @openstack_auth_uri.to_s,
|
||||
:openstack_auth_token => @auth_token,
|
||||
:openstack_management_url => @openstack_management_url,
|
||||
:openstack_identity_endpoint => @openstack_identity_public_endpoint }
|
||||
:openstack_identity_endpoint => @openstack_identity_public_endpoint,
|
||||
:current_user => @current_user,
|
||||
:current_tenant => @current_tenant }
|
||||
end
|
||||
|
||||
def reload
|
||||
|
@ -305,6 +313,9 @@ module Fog
|
|||
credentials = Fog::OpenStack.authenticate_v1(options, @connection_options)
|
||||
end
|
||||
|
||||
@current_user = credentials[:user]
|
||||
@current_tenant = credentials[:tenant]
|
||||
|
||||
@openstack_must_reauthenticate = false
|
||||
@auth_token = credentials[:token]
|
||||
@openstack_management_url = credentials[:server_management_url]
|
||||
|
|
|
@ -8,7 +8,8 @@ module Fog
|
|||
requires :openstack_auth_url
|
||||
recognizes :openstack_auth_token, :openstack_management_url, :persistent,
|
||||
:openstack_service_name, :openstack_tenant,
|
||||
:openstack_api_key, :openstack_username, :openstack_current_user_id
|
||||
:openstack_api_key, :openstack_username, :openstack_current_user_id,
|
||||
:current_user, :current_tenant
|
||||
|
||||
model_path 'fog/openstack/models/identity'
|
||||
model :tenant
|
||||
|
@ -102,6 +103,8 @@ module Fog
|
|||
end
|
||||
|
||||
class Real
|
||||
attr_reader :current_user
|
||||
attr_reader :current_tenant
|
||||
|
||||
def initialize(options={})
|
||||
require 'multi_json'
|
||||
|
@ -128,6 +131,9 @@ module Fog
|
|||
|
||||
@openstack_current_user_id = options[:openstack_current_user_id]
|
||||
|
||||
@current_user = options[:current_user]
|
||||
@current_tenant = options[:current_tenant]
|
||||
|
||||
authenticate
|
||||
|
||||
@persistent = options[:persistent] || false
|
||||
|
@ -139,7 +145,9 @@ module Fog
|
|||
:openstack_auth_url => @openstack_auth_uri.to_s,
|
||||
:openstack_auth_token => @auth_token,
|
||||
:openstack_management_url => @openstack_management_url,
|
||||
:openstack_current_user_id => @openstack_current_user_id}
|
||||
:openstack_current_user_id => @openstack_current_user_id,
|
||||
:current_user => @current_user,
|
||||
:current_tenant => @current_tenant }
|
||||
end
|
||||
|
||||
def reload
|
||||
|
@ -196,6 +204,9 @@ module Fog
|
|||
|
||||
credentials = Fog::OpenStack.authenticate_v2(options, @connection_options)
|
||||
|
||||
@current_user = credentials[:user]
|
||||
@current_tenant = credentials[:tenant]
|
||||
|
||||
@openstack_must_reauthenticate = false
|
||||
@auth_token = credentials[:token]
|
||||
@openstack_management_url = credentials[:server_management_url]
|
||||
|
|
|
@ -8,7 +8,8 @@ module Fog
|
|||
requires :openstack_auth_url
|
||||
recognizes :openstack_auth_token, :openstack_management_url, :persistent,
|
||||
:openstack_service_name, :openstack_tenant,
|
||||
:openstack_api_key, :openstack_username
|
||||
:openstack_api_key, :openstack_username,
|
||||
:current_user, :current_tenant
|
||||
|
||||
model_path 'fog/openstack/models/image'
|
||||
|
||||
|
@ -79,6 +80,8 @@ module Fog
|
|||
end
|
||||
|
||||
class Real
|
||||
attr_reader :current_user
|
||||
attr_reader :current_tenant
|
||||
|
||||
def initialize(options={})
|
||||
require 'multi_json'
|
||||
|
@ -103,6 +106,9 @@ module Fog
|
|||
|
||||
@connection_options = options[:connection_options] || {}
|
||||
|
||||
@current_user = options[:current_user]
|
||||
@current_tenant = options[:current_tenant]
|
||||
|
||||
authenticate
|
||||
|
||||
@persistent = options[:persistent] || false
|
||||
|
@ -113,7 +119,9 @@ module Fog
|
|||
{ :provider => 'openstack',
|
||||
:openstack_auth_url => @openstack_auth_uri.to_s,
|
||||
:openstack_auth_token => @auth_token,
|
||||
:openstack_management_url => @openstack_management_url }
|
||||
:openstack_management_url => @openstack_management_url,
|
||||
:current_user => @current_user,
|
||||
:current_tenant => @current_tenant }
|
||||
end
|
||||
|
||||
def reload
|
||||
|
@ -170,6 +178,9 @@ module Fog
|
|||
|
||||
credentials = Fog::OpenStack.authenticate_v2(options, @connection_options)
|
||||
|
||||
@current_user = credentials[:user]
|
||||
@current_tenant = credentials[:tenant]
|
||||
|
||||
@openstack_must_reauthenticate = false
|
||||
@auth_token = credentials[:token]
|
||||
@openstack_management_url = credentials[:server_management_url]
|
||||
|
|
|
@ -8,7 +8,8 @@ module Fog
|
|||
requires :openstack_auth_url
|
||||
recognizes :openstack_auth_token, :openstack_management_url, :persistent,
|
||||
:openstack_service_name, :openstack_tenant,
|
||||
:openstack_api_key, :openstack_username
|
||||
:openstack_api_key, :openstack_username,
|
||||
:current_user, :current_tenant
|
||||
|
||||
#model_path 'fog/openstack/models/volume'
|
||||
|
||||
|
@ -79,6 +80,8 @@ module Fog
|
|||
end
|
||||
|
||||
class Real
|
||||
attr_reader :current_user
|
||||
attr_reader :current_tenant
|
||||
|
||||
def initialize(options={})
|
||||
require 'multi_json'
|
||||
|
@ -103,6 +106,9 @@ module Fog
|
|||
|
||||
@connection_options = options[:connection_options] || {}
|
||||
|
||||
@current_user = options[:current_user]
|
||||
@current_tenant = options[:current_tenant]
|
||||
|
||||
authenticate
|
||||
|
||||
@persistent = options[:persistent] || false
|
||||
|
@ -113,7 +119,9 @@ module Fog
|
|||
{ :provider => 'openstack',
|
||||
:openstack_auth_url => @openstack_auth_uri.to_s,
|
||||
:openstack_auth_token => @auth_token,
|
||||
:openstack_management_url => @openstack_management_url }
|
||||
:openstack_management_url => @openstack_management_url,
|
||||
:current_user => @current_user,
|
||||
:current_tenant => @current_tenant }
|
||||
end
|
||||
|
||||
def reload
|
||||
|
@ -170,6 +178,9 @@ module Fog
|
|||
|
||||
credentials = Fog::OpenStack.authenticate_v2(options, @connection_options)
|
||||
|
||||
@current_user = credentials[:user]
|
||||
@current_tenant = credentials[:tenant]
|
||||
|
||||
@openstack_must_reauthenticate = false
|
||||
@auth_token = credentials[:token]
|
||||
@openstack_management_url = credentials[:server_management_url]
|
||||
|
|
Loading…
Reference in a new issue