Added Swfit All In One support.

Change-Id: I92cc63d4c22f45d59166bd3eb4b975b34953328f
This commit is contained in:
Richard (Rick) Hawkins 2013-09-23 13:28:46 -05:00
parent b1fd69fc43
commit eac18a168b
8 changed files with 179 additions and 2 deletions

View File

@ -13,16 +13,19 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from cloudcafe.auth.config import UserAuthConfig, UserConfig
from cloudcafe.extensions.rax_auth.v2_0.tokens_api.client import \
TokenAPI_Client as RaxTokenAPI_Client
from cloudcafe.extensions.rax_auth.v2_0.tokens_api.behaviors import \
TokenAPI_Behaviors as RaxTokenAPI_Behaviors
from cloudcafe.extensions.saio_tempauth.v1_0.client import \
TempauthAPI_Client as SaioAuthAPI_Client
from cloudcafe.extensions.saio_tempauth.v1_0.behaviors import \
TempauthAPI_Behaviors as SaioAuthAPI_Behaviors
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.auth.config import UserAuthConfig, UserConfig
class AuthProvider(object):
@ -47,5 +50,12 @@ class AuthProvider(object):
return token_behaviors.get_access_data(user_config.username,
user_config.api_key,
user_config.tenant_id)
elif endpoint_config.strategy.lower() == 'saio_tempauth':
auth_client = SaioAuthAPI_Client(endpoint_config.auth_endpoint)
auth_behaviors = SaioAuthAPI_Behaviors(auth_client)
return auth_behaviors.get_access_data(
user_config.username, user_config.password)
else:
raise NotImplementedError

View File

@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View File

@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View File

@ -0,0 +1,40 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from cafe.engine.behaviors import BaseBehavior, behavior
from cloudcafe.auth.config import UserConfig
from cloudcafe.extensions.saio_tempauth.v1_0.client import TempauthAPI_Client
class TempauthAPI_Behaviors(BaseBehavior):
"""
Tempauth Behaviors for use with Swift All In One.
"""
def __init__(self, client=None):
self.client = client
self.config = UserConfig()
@behavior(TempauthAPI_Client)
def get_access_data(self, username=None, password=None):
username = username or self.config.username
password = password or self.config.password
access_data = None
if username is not None and password is not None:
access_data = self.client.authenticate(username, password)
return access_data

View File

@ -0,0 +1,47 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from cafe.engine.clients.rest import BaseRestClient
from cloudcafe.extensions.saio_tempauth.v1_0.models.requests import AuthData
class TempauthAPI_Client(BaseRestClient):
"""
Tempauth Client for use with Swift All In One.
"""
def __init__(self, endpoint):
super(TempauthAPI_Client, self).__init__()
self.endpoint = endpoint
def authenticate(self, username, password):
headers = {
'X-Storage-User': username,
'X-Storage-Pass': password
}
url = '{0}/auth/v1.0'.format(self.endpoint)
r = self.request('GET', url, headers=headers)
if not r.ok:
raise Exception('Could not auth')
storage_url = r.headers['x-storage-url']
auth_token = r.headers['x-auth-token']
storage_token = r.headers['x-storage-token']
data = AuthData(storage_url, auth_token, storage_token)
return data

View File

@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View File

@ -0,0 +1,28 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from cafe.engine.models.base import BaseModel
class AuthData(BaseModel):
"""
Tempauth data model for use with Swift All In One.
"""
def __init__(self, storage_url, auth_token, storage_token):
super(AuthData, self).__init__()
self.storage_url = storage_url
self.auth_token = auth_token
self.storage_token = storage_token

View File

@ -0,0 +1,7 @@
[user_auth_config]
endpoint=http://127.0.0.1:8080
strategy=saio_tempauth
[user]
username=test:tester
password=testing