4 # Copyright 2017 RIFT.IO Inc
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 from keystoneauth1
.identity
import v3
19 from keystoneauth1
.identity
import v2
23 class TokenDriver(object):
25 Class for token based authentication for openstack.
27 This is just placeholder for now
29 def __init__(self
, version
, logger
=None, **kwargs
):
34 self
.log
= logging
.getLogger('rwcal.openstack.keystone.token')
35 self
.log
.setLevel(logging
.DEBUG
)
41 def auth_handle(self
):
44 class PasswordDriver(object):
46 Class for password based authentication for openstack
48 def __init__(self
, version
, logger
=None, **kwargs
):
52 version (str): Keystone API version to use
53 logger (instance of logging.Logger)
54 A dictionary of following key-value pairs
56 auth_url (string) : Keystone Auth URL
57 username (string) : Username for authentication
58 password (string) : Password for authentication
59 project_name (string) : Name of the project or tenant
60 project_domain_name (string) : Name of the project domain
61 user_domain_name (string) : Name of the user domain
62 logger (instance of logging.Logger)
68 self
.log
= logging
.getLogger('rwcal.openstack.keystone.password')
69 self
.log
.setLevel(logging
.DEBUG
)
74 version
= int(float(version
))
77 self
.log
.info("Using keystone version 3 for authentication at URL: %s", kwargs
['auth_url'])
78 self
._auth
= v3
.Password(auth_url
= kwargs
['auth_url'],
79 username
= kwargs
['username'],
80 password
= kwargs
['password'],
81 project_name
= kwargs
['project_name'],
82 project_domain_name
= kwargs
['project_domain_name'],
83 user_domain_name
= kwargs
['user_domain_name'])
85 self
.log
.info("Using keystone version 2 for authentication at URL: %s", kwargs
['auth_url'])
86 self
._auth
= v2
.Password(auth_url
= kwargs
['auth_url'],
87 username
= kwargs
['username'],
88 password
= kwargs
['password'],
89 tenant_name
= kwargs
['project_name'])
91 def auth_handle(self
):
95 class AuthDriver(object):
97 Driver class for handling authentication plugins for openstack
100 password
=PasswordDriver
,
103 def __init__(self
, auth_type
, version
, logger
= None, **kwargs
):
105 auth_type (string): At this point, only "password" based
106 authentication is supported.
107 version (string): Keystone API version
108 logger (instance of logging.Logger)
110 kwargs a dictionary of following key/value pairs
112 username (string) : Username
113 password (string) : Password
114 auth_url (string) : Authentication URL
115 tenant_name(string): Tenant Name
116 user_domain_name (string) : User domain name
117 project_domain_name (string): Project domain name
118 region (string) : Region name
122 self
.log
= logging
.getLogger('rwcal.openstack.auth')
123 self
.log
.setLevel(logging
.DEBUG
)
128 self
.log
.info("Using %s authentication method", auth_type
)
129 if auth_type
not in AuthDriver
.AuthMethod
:
130 self
.log
.error("Unsupported authentication method %s", auth_type
)
131 raise KeyError("Unsupported authentication method %s", auth_type
)
133 self
._auth
_method
= AuthDriver
.AuthMethod
[auth_type
](version
, self
.log
, **kwargs
)
136 def auth_handle(self
):
137 return self
._auth
_method
.auth_handle