|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | + |
| 13 | +from openstack.auth.identity import v2 |
| 14 | +from openstack.auth.identity import v3 |
| 15 | +from openstack import exceptions |
| 16 | + |
| 17 | + |
| 18 | +def create(username=None, password=None, token=None, auth_url=None, |
| 19 | + version='3', project_name=None): |
| 20 | + """Temporary code for creating an authenticator |
| 21 | +
|
| 22 | + This is temporary code to create an authenticator. This code will be |
| 23 | + removed in the future. |
| 24 | +
|
| 25 | + :param string username: User name for authentication. |
| 26 | + :param string password: Password associated with the user. |
| 27 | + :param string token: Authentication token to use if available. |
| 28 | + :param string auth_url: The URL to use for authentication. |
| 29 | + :param string version: Version of authentication to use. |
| 30 | + :param string project_name: Project name to athenticate. |
| 31 | +
|
| 32 | + :returns string: An authenticator. |
| 33 | + """ |
| 34 | + version = version.lower().replace('v', '') |
| 35 | + version = version.split('.')[0] |
| 36 | + if version == '3': |
| 37 | + if not token: |
| 38 | + args = {'username': username, 'password': password} |
| 39 | + if project_name: |
| 40 | + args['project_name'] = project_name |
| 41 | + return v3.Password(auth_url, **args) |
| 42 | + else: |
| 43 | + return v3.Token(auth_url, token=token) |
| 44 | + elif version == '2': |
| 45 | + if not token: |
| 46 | + args = {} |
| 47 | + if project_name: |
| 48 | + args['tenant_name'] = project_name |
| 49 | + return v2.Password(auth_url, username, password, **args) |
| 50 | + else: |
| 51 | + return v2.Token(auth_url, token) |
| 52 | + msg = ("No support for identity version: %s" % version) |
| 53 | + raise exceptions.NoMatchingPlugin(msg) |
0 commit comments