Debian Codegraph @

keystoneclient/auth/identity/generic/password.py

raw symbols SCIP
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 oslo_config import cfg
14
15 from keystoneclient import _discover
16 from keystoneclient.auth.identity.generic import base
17 from keystoneclient.auth.identity import v2
18 from keystoneclient.auth.identity import v3
19 from keystoneclient import utils
20
21
22 def get_options():
23 return [
24 cfg.StrOpt('user-id', help='User id'),
25 cfg.StrOpt('username', dest='username', help='Username',
26 deprecated_name='user-name'),
27 cfg.StrOpt('user-domain-id', help="User's domain id"),
28 cfg.StrOpt('user-domain-name', help="User's domain name"),
29 cfg.StrOpt('password', secret=True, help="User's password"),
30 ]
31
32
33 class Password(base.BaseGenericPlugin):
34 """A common user/password authentication plugin.
35
36 :param string username: Username for authentication.
37 :param string user_id: User ID for authentication.
38 :param string password: Password for authentication.
39 :param string user_domain_id: User's domain ID for authentication.
40 :param string user_domain_name: User's domain name for authentication.
41
42 """
43
44 def __init__(self, auth_url, username=None, user_id=None, password=None,
45 user_domain_id=None, user_domain_name=None, **kwargs):
46 super(Password, self).__init__(auth_url=auth_url, **kwargs)
47
48 self._username = username
49 self._user_id = user_id
50 self._password = password
51 self._user_domain_id = user_domain_id
52 self._user_domain_name = user_domain_name
53
54 def create_plugin(self, session, version, url, raw_status=None):
55 if _discover.version_match((2,), version):
56 if self._user_domain_id or self._user_domain_name:
57 # If you specify any domain parameters it won't work so quit.
58 return None
59
60 return v2.Password(auth_url=url,
61 user_id=self._user_id,
62 username=self._username,
63 password=self._password,
64 **self._v2_params)
65
66 elif _discover.version_match((3,), version):
67 return v3.Password(auth_url=url,
68 user_id=self._user_id,
69 username=self._username,
70 user_domain_id=self._user_domain_id,
71 user_domain_name=self._user_domain_name,
72 password=self._password,
73 **self._v3_params)
74
75 @classmethod
76 def get_options(cls):
77 options = super(Password, cls).get_options()
78 options.extend(get_options())
79 return options
80
81 @classmethod
82 def load_from_argparse_arguments(cls, namespace, **kwargs):
83 if not (kwargs.get('password') or namespace.os_password):
84 kwargs['password'] = utils.prompt_user_password()
85
86 return super(Password, cls).load_from_argparse_arguments(namespace,
87 **kwargs)