Debian Codegraph @

keystoneclient/auth/identity/v3/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.auth.identity.v3 import base
16 from keystoneclient import utils
17
18
19 __all__ = ('PasswordMethod', 'Password')
20
21
22 class PasswordMethod(base.AuthMethod):
23 """Construct a User/Password based authentication method.
24
25 :param string password: Password for authentication.
26 :param string username: Username for authentication.
27 :param string user_id: User ID for authentication.
28 :param string user_domain_id: User's domain ID for authentication.
29 :param string user_domain_name: User's domain name for authentication.
30 """
31
32 _method_parameters = ['user_id',
33 'username',
34 'user_domain_id',
35 'user_domain_name',
36 'password']
37
38 def get_auth_data(self, session, auth, headers, **kwargs):
39 user = {'password': self.password}
40
41 if self.user_id:
42 user['id'] = self.user_id
43 elif self.username:
44 user['name'] = self.username
45
46 if self.user_domain_id:
47 user['domain'] = {'id': self.user_domain_id}
48 elif self.user_domain_name:
49 user['domain'] = {'name': self.user_domain_name}
50
51 return 'password', {'user': user}
52
53
54 class Password(base.AuthConstructor):
55 """A plugin for authenticating with a username and password.
56
57 :param string auth_url: Identity service endpoint for authentication.
58 :param string password: Password for authentication.
59 :param string username: Username for authentication.
60 :param string user_id: User ID for authentication.
61 :param string user_domain_id: User's domain ID for authentication.
62 :param string user_domain_name: User's domain name for authentication.
63 :param string trust_id: Trust ID for trust scoping.
64 :param string domain_id: Domain ID for domain scoping.
65 :param string domain_name: Domain name for domain scoping.
66 :param string project_id: Project ID for project scoping.
67 :param string project_name: Project name for project scoping.
68 :param string project_domain_id: Project's domain ID for project.
69 :param string project_domain_name: Project's domain name for project.
70 :param bool reauthenticate: Allow fetching a new token if the current one
71 is going to expire. (optional) default True
72 """
73
74 _auth_method_class = PasswordMethod
75
76 @classmethod
77 def get_options(cls):
78 options = super(Password, cls).get_options()
79
80 options.extend([
81 cfg.StrOpt('user-id', help='User ID'),
82 cfg.StrOpt('username', dest='username', help='Username',
83 deprecated_name='user-name'),
84 cfg.StrOpt('user-domain-id', help="User's domain id"),
85 cfg.StrOpt('user-domain-name', help="User's domain name"),
86 cfg.StrOpt('password', secret=True, help="User's password"),
87 ])
88
89 return options
90
91 @classmethod
92 def load_from_argparse_arguments(cls, namespace, **kwargs):
93 if not (kwargs.get('password') or namespace.os_password):
94 kwargs['password'] = utils.prompt_user_password()
95
96 return super(Password, cls).load_from_argparse_arguments(namespace,
97 **kwargs)