blob: c3217c928d8df907439d59fac118755a701c6def [file] [log] [blame]
ghanshyam17193062016-06-24 10:36:54 +09001# 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
songwenping99d6e002021-01-05 03:07:46 +000013from urllib import parse as urllib
14
ghanshyam17193062016-06-24 10:36:54 +090015from oslo_serialization import jsonutils as json
ghanshyam17193062016-06-24 10:36:54 +090016
17from tempest.lib.common import rest_client
18
19
20class UsersClient(rest_client.RestClient):
21 api_version = "v2.0"
22
23 def create_user(self, **kwargs):
24 """Create a user.
25
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090026 For a full list of available parameters, please refer to the official
27 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020028 https://docs.openstack.org/api-ref/identity/v2-admin/index.html#create-user-admin-endpoint
ghanshyam17193062016-06-24 10:36:54 +090029 """
30 post_body = json.dumps({'user': kwargs})
31 resp, body = self.post('users', post_body)
32 self.expected_success(200, resp.status)
33 body = json.loads(body)
34 return rest_client.ResponseBody(resp, body)
35
36 def update_user(self, user_id, **kwargs):
37 """Updates a user.
38
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090039 For a full list of available parameters, please refer to the official
40 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020041 https://docs.openstack.org/api-ref/identity/v2-admin/index.html#update-user-admin-endpoint
ghanshyam17193062016-06-24 10:36:54 +090042 """
43 put_body = json.dumps({'user': kwargs})
44 resp, body = self.put('users/%s' % user_id, put_body)
45 self.expected_success(200, resp.status)
46 body = json.loads(body)
47 return rest_client.ResponseBody(resp, body)
48
49 def show_user(self, user_id):
50 """GET a user.
51
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090052 For a full list of available parameters, please refer to the official
53 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020054 https://docs.openstack.org/api-ref/identity/v2-admin/index.html#show-user-details-admin-endpoint
ghanshyam17193062016-06-24 10:36:54 +090055 """
56 resp, body = self.get("users/%s" % user_id)
57 self.expected_success(200, resp.status)
58 body = json.loads(body)
59 return rest_client.ResponseBody(resp, body)
60
61 def delete_user(self, user_id):
62 """Delete a user.
63
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090064 For a full list of available parameters, please refer to the official
65 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020066 https://docs.openstack.org/api-ref/identity/v2-admin/index.html#delete-user-admin-endpoint
ghanshyam17193062016-06-24 10:36:54 +090067 """
68 resp, body = self.delete("users/%s" % user_id)
69 self.expected_success(204, resp.status)
70 return rest_client.ResponseBody(resp, body)
71
72 def list_users(self, **params):
73 """Get the list of users.
74
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090075 For a full list of available parameters, please refer to the official
76 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020077 https://docs.openstack.org/api-ref/identity/v2-admin/index.html#list-users-admin-endpoint
ghanshyam17193062016-06-24 10:36:54 +090078 """
79 url = "users"
80 if params:
81 url += '?%s' % urllib.urlencode(params)
82 resp, body = self.get(url)
83 self.expected_success(200, resp.status)
84 body = json.loads(body)
85 return rest_client.ResponseBody(resp, body)
86
87 def update_user_enabled(self, user_id, **kwargs):
88 """Enables or disables a user.
89
OTSUKA, Yuanyingfaac5712016-09-15 13:53:55 +090090 For a full list of available parameters, please refer to the official
91 API reference:
Andreas Jaegerbf30ae72019-07-22 19:22:57 +020092 https://docs.openstack.org/api-ref/identity/v2-ext/index.html#enable-disable-user
ghanshyam17193062016-06-24 10:36:54 +090093 """
94 # NOTE: The URL (users/<id>/enabled) is different from the api-site
95 # one (users/<id>/OS-KSADM/enabled) , but they are the same API
96 # because of the fact that in keystone/contrib/admin_crud/core.py
97 # both api use same action='set_user_enabled'
98 put_body = json.dumps({'user': kwargs})
99 resp, body = self.put('users/%s/enabled' % user_id, put_body)
100 self.expected_success(200, resp.status)
101 body = json.loads(body)
102 return rest_client.ResponseBody(resp, body)
103
104 def update_user_password(self, user_id, **kwargs):
105 """Update User Password."""
106 # TODO(piyush): Current api-site doesn't contain this API description.
107 # After fixing the api-site, we need to fix here also for putting the
108 # link to api-site.
109 # LP: https://bugs.launchpad.net/openstack-api-site/+bug/1524147
110 put_body = json.dumps({'user': kwargs})
111 resp, body = self.put('users/%s/OS-KSADM/password' % user_id, put_body)
112 self.expected_success(200, resp.status)
113 body = json.loads(body)
114 return rest_client.ResponseBody(resp, body)
115
116 def update_user_own_password(self, user_id, **kwargs):
117 """User updates own password"""
118 # TODO(piyush): Current api-site doesn't contain this API description.
119 # After fixing the api-site, we need to fix here also for putting the
120 # link to api-site.
121 # LP: https://bugs.launchpad.net/openstack-api-site/+bug/1524153
122 # NOTE: This API is used for updating user password by itself.
123 # Ref: http://lists.openstack.org/pipermail/openstack-dev/2015-December
124 # /081803.html
125 patch_body = json.dumps({'user': kwargs})
126 resp, body = self.patch('OS-KSCRUD/users/%s' % user_id, patch_body)
127 self.expected_success(200, resp.status)
128 body = json.loads(body)
129 return rest_client.ResponseBody(resp, body)
130
131 def create_user_ec2_credential(self, user_id, **kwargs):
132 # TODO(piyush): Current api-site doesn't contain this API description.
133 # After fixing the api-site, we need to fix here also for putting the
134 # link to api-site.
135 post_body = json.dumps(kwargs)
136 resp, body = self.post('/users/%s/credentials/OS-EC2' % user_id,
137 post_body)
138 self.expected_success(200, resp.status)
139 body = json.loads(body)
140 return rest_client.ResponseBody(resp, body)
141
142 def delete_user_ec2_credential(self, user_id, access):
143 resp, body = self.delete('/users/%s/credentials/OS-EC2/%s' %
144 (user_id, access))
145 self.expected_success(204, resp.status)
146 return rest_client.ResponseBody(resp, body)
147
148 def list_user_ec2_credentials(self, user_id):
149 resp, body = self.get('/users/%s/credentials/OS-EC2' % user_id)
150 self.expected_success(200, resp.status)
151 body = json.loads(body)
152 return rest_client.ResponseBody(resp, body)
153
154 def show_user_ec2_credential(self, user_id, access):
155 resp, body = self.get('/users/%s/credentials/OS-EC2/%s' %
156 (user_id, access))
157 self.expected_success(200, resp.status)
158 body = json.loads(body)
159 return rest_client.ResponseBody(resp, body)