From da41e5425fc5eda6feae37ba27491ec1de9d7cab Mon Sep 17 00:00:00 2001 From: Daryl Walleck Date: Wed, 17 Apr 2013 12:31:14 -0700 Subject: [PATCH] Auth upgrade Change-Id: I79ab17ab95152fc483cde8eb8bbe4e123f66cfef --- cloudcafe/auth/__init__.py | 0 cloudcafe/auth/config.py | 27 +++++++++++++++++++ cloudcafe/auth/provider.py | 20 ++++++++++++++ cloudcafe/compute/config.py | 18 +++---------- .../rax_auth/v2_0/tokens_api/config.py | 6 +---- cloudcafe/identity/v2_0/tokens_api/config.py | 19 +++++++++---- 6 files changed, 65 insertions(+), 25 deletions(-) create mode 100644 cloudcafe/auth/__init__.py create mode 100644 cloudcafe/auth/config.py create mode 100644 cloudcafe/auth/provider.py diff --git a/cloudcafe/auth/__init__.py b/cloudcafe/auth/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cloudcafe/auth/config.py b/cloudcafe/auth/config.py new file mode 100644 index 00000000..1885d703 --- /dev/null +++ b/cloudcafe/auth/config.py @@ -0,0 +1,27 @@ +from cloudcafe.common.models.configuration import ConfigSectionInterface + + +class UserEndpointConfig(ConfigSectionInterface): + + SECTION_NAME = 'user_auth_endpoint' + + @property + def endpoint(self): + return self.get("endpoint") + + @property + def strategy(self): + return self.get("strategy") + + +class ComputeAdminEndpointConfig(ConfigSectionInterface): + + SECTION_NAME = 'compute_admin_auth_endpoint' + + @property + def endpoint(self): + return self.get("endpoint") + + @property + def strategy(self): + return self.get("strategy") \ No newline at end of file diff --git a/cloudcafe/auth/provider.py b/cloudcafe/auth/provider.py new file mode 100644 index 00000000..7a237db3 --- /dev/null +++ b/cloudcafe/auth/provider.py @@ -0,0 +1,20 @@ +from cloudcafe.extensions.rax_auth.v2_0.tokens_api.client import TokenAPI_Client +from cloudcafe.extensions.rax_auth.v2_0.tokens_api.behaviors import TokenAPI_Behaviors +from cloudcafe.extensions.rax_auth.v2_0.tokens_api.config import TokenAPI_Config +from cloudcafe.identity.v2_0.tokens_api.client import TokenAPI_Client as OSTokenAPI_Client +from cloudcafe.identity.v2_0.tokens_api.behaviors import TokenAPI_Behaviors as OSTokenAPI_Behaviors +from cloudcafe.identity.v2_0.tokens_api.config import TokenAPI_Config as OSTokenAPI_Config + +class AuthProvider(object): + + def __init__(self, auth_config): + self.auth_config = auth_config + + def get_access_data(self): + if self.auth_config.strategy.lower() == 'keystone': + token_client = OSTokenAPI_Client( + self.auth_config.authentication_endpoint, 'json', 'json') + token_behaviors = OSTokenAPI_Behaviors(token_client) + return token_behaviors.get_access_data(self.auth_config.username, + self.auth_config.password, + self.auth_config.tenant_name) \ No newline at end of file diff --git a/cloudcafe/compute/config.py b/cloudcafe/compute/config.py index 14b9b908..2c25238c 100644 --- a/cloudcafe/compute/config.py +++ b/cloudcafe/compute/config.py @@ -17,9 +17,9 @@ limitations under the License. from cloudcafe.common.models.configuration import ConfigSectionInterface -class ComputeConfig(ConfigSectionInterface): +class ComputeEndpointConfig(ConfigSectionInterface): - SECTION_NAME = 'compute' + SECTION_NAME = 'compute_endpoint' @property def region(self): @@ -47,22 +47,10 @@ class ComputeAuthorizationConfig(ConfigSectionInterface): return self.get("tenant_name") -class ComputeAdminConfig(ConfigSectionInterface): +class ComputeAdminUserConfig(ConfigSectionInterface): SECTION_NAME = 'compute_admin_user' - @property - def authentication_endpoint(self): - return self.get("authentication_endpoint") - - @property - def compute_endpoint_name(self): - return self.get("compute_endpoint_name") - - @property - def region(self): - return self.get("region") - @property def username(self): return self.get("username") diff --git a/cloudcafe/extensions/rax_auth/v2_0/tokens_api/config.py b/cloudcafe/extensions/rax_auth/v2_0/tokens_api/config.py index dc4d7e3f..fd6f5b4b 100644 --- a/cloudcafe/extensions/rax_auth/v2_0/tokens_api/config.py +++ b/cloudcafe/extensions/rax_auth/v2_0/tokens_api/config.py @@ -19,7 +19,7 @@ from cloudcafe.common.models.configuration import ConfigSectionInterface class TokenAPI_Config(ConfigSectionInterface): - SECTION_NAME = 'rax_token_api' + SECTION_NAME = 'user' @property def serialize_format(self): @@ -29,10 +29,6 @@ class TokenAPI_Config(ConfigSectionInterface): def deserialize_format(self): return self.get("deserialize_format") - @property - def authentication_endpoint(self): - return self.get("authentication_endpoint") - @property def username(self): return self.get("username") diff --git a/cloudcafe/identity/v2_0/tokens_api/config.py b/cloudcafe/identity/v2_0/tokens_api/config.py index 50e0acb3..7af919ed 100644 --- a/cloudcafe/identity/v2_0/tokens_api/config.py +++ b/cloudcafe/identity/v2_0/tokens_api/config.py @@ -19,7 +19,20 @@ from cloudcafe.common.models.configuration import ConfigSectionInterface class TokenAPI_Config(ConfigSectionInterface): - SECTION_NAME = 'token_api' + SECTION_NAME = 'user_auth_endpoint' + + @property + def endpoint(self): + return self.get("endpoint") + + @property + def strategy(self): + return self.get("strategy") + + +class TokenAPI_Config(ConfigSectionInterface): + + SECTION_NAME = 'user' @property def serialize_format(self): @@ -29,10 +42,6 @@ class TokenAPI_Config(ConfigSectionInterface): def deserialize_format(self): return self.get("deserialize_format") - @property - def authentication_endpoint(self): - return self.get("authentication_endpoint") - @property def username(self): return self.get("username")