Project

Profile

Help

Issue #3075

closed

Not able to create a new user using API

Added by kersom over 6 years ago. Updated over 4 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Version:
Platform Release:
OS:
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Sprint:
Sprint 28
Quarter:

Description

I am using httpie to send a request to Pulp3 endpoint to create a new user. netrc file has the following configuration.

machine f26-p3
login admin
password admin
http POST http://f26-p3:8000/api/v3/users/ username=test_alpha23 password=1234

HTTP/1.0 500 Internal Server Error
Content-Length: 19283
Content-Type: text/plain
Date: Tue, 17 Oct 2017 15:48:04 GMT
Server: WSGIServer/0.2 CPython/3.6.2
Vary: Cookie
X-Frame-Options: SAMEORIGIN

KeyError at /api/v3/users/
'reset_jwt_secret'

Request Method: POST
Request URL: http://f26-p3:8000/api/v3/users/
Django Version: 1.11.6
Python Executable: /home/pulp/pulpvenv/bin/python3
Python Version: 3.6.2
Python Path: ['/home/pulp/pulpvenv/bin', '/usr/lib64/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', '/home/pulp/pulpvenv/lib64/python3.6/site-packages', '/home/pulp/pulpvenv/lib/python3.6/site-packages', '/home/pulp']
Server time: Tue, 17 Oct 2017 15:48:04 +0000
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django_filters',
 'rest_framework',
 'pulpcore.app',
 'pulp_file.app.PulpFilePluginAppConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback:  

File "/home/pulp/pulpvenv/lib64/python3.6/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/home/pulp/pulpvenv/lib64/python3.6/site-packages/django/core/handlers/base.py" in _legacy_get_response
  249.             response = self._get_response(request)

File "/home/pulp/pulpvenv/lib64/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/home/pulp/pulpvenv/lib64/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/pulp/pulpvenv/lib64/python3.6/site-packages/django/views/decorators/csrf.py" in wrapped_view
  58.         return view_func(*args, **kwargs)

File "/home/pulp/pulpvenv/lib64/python3.6/site-packages/rest_framework/viewsets.py" in view
  90.             return self.dispatch(request, *args, **kwargs)

File "/home/pulp/pulpvenv/lib64/python3.6/site-packages/rest_framework/views.py" in dispatch
  489.             response = self.handle_exception(exc)

File "/home/pulp/pulpvenv/lib64/python3.6/site-packages/rest_framework/views.py" in handle_exception
  449.             self.raise_uncaught_exception(exc)

File "/home/pulp/pulpvenv/lib64/python3.6/site-packages/rest_framework/views.py" in dispatch
  486.             response = handler(request, *args, **kwargs)

File "/home/pulp/pulpvenv/lib64/python3.6/site-packages/rest_framework/mixins.py" in create
  20.         serializer.is_valid(raise_exception=True)

File "/home/pulp/pulpvenv/lib64/python3.6/site-packages/rest_framework/serializers.py" in is_valid
  236.                 self._validated_data = self.run_validation(self.initial_data)

File "/home/pulp/pulpvenv/lib64/python3.6/site-packages/rest_framework/serializers.py" in run_validation
  434.             value = self.validate(value)

File "/home/pulp/pulpvenv/lib64/python3.6/site-packages/pulpcore/app/serializers/user.py" in validate
  74.         if data["reset_jwt_secret"]:

Exception Type: KeyError at /api/v3/users/
Exception Value: 'reset_jwt_secret'
Request information:
USER: admin

Pulp3 Version:


pulp-file==0.0.1a2
pulpcore==3.0.0a4
pulpcore-common==3.0.0a4
pulpcore-plugin==0.0.1a4

OS version:


Fedora release 26 (Twenty Six)
Actions #1

Updated by kersom over 6 years ago

  • Description updated (diff)
Actions #2

Updated by amacdona@redhat.com over 6 years ago

I think this is an easyfix.

https://github.com/pulp/pulp/blob/3.0-dev/platform/pulpcore/app/serializers/user.py#L74

s/data["reset_jwt_secret"]/ data.get("reset_jwt_secret")

Actions #3

Updated by bizhang over 6 years ago

An additional error arises from passing reset_jwt_secret=True to the request:

TypeError: 'reset_jwt_secret' is an invalid keyword argument for this function

The following patch to delete the reset_jwt_secret from the data before it's passed to the model create would fix it:

diff --git a/platform/pulpcore/app/serializers/user.py b/platform/pulpcore/app/serializers/user.py
index d5c294a80..d8407bafb 100644
--- a/platform/pulpcore/app/serializers/user.py
+++ b/platform/pulpcore/app/serializers/user.py
@@ -91,8 +91,9 @@ class UserSerializer(ModelSerializer):
         """
         If reset_jwt_secret is True generate user random jwt secret.
         """
-        if data["reset_jwt_secret"]:
+        if data.get("reset_jwt_secret"):
             data["jwt_secret"] = User.gen_random_jwt_secret()
+        del data["reset_jwt_secret"]
         return data

     class Meta:

But I think a better way to do this will be to add a detailed route to the user viewset (/users/{user}/jwt_reset)

Actions #4

Updated by dalley over 6 years ago

  • Sprint/Milestone set to 46
Actions #5

Updated by dalley over 6 years ago

  • Triaged changed from No to Yes
Actions #6

Updated by daviddavis over 6 years ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to daviddavis
Actions #7

Updated by daviddavis over 6 years ago

I'm creating a new endpoint per @bizhang's suggestion but I ran into a problem where it's showing extra params in the api schema. I notice that it's happening in other places too so I opened #3093.

Actions #8

Updated by daviddavis over 6 years ago

  • Status changed from ASSIGNED to POST
Actions #9

Updated by mhrivnak over 6 years ago

  • Sprint/Milestone changed from 46 to 47

Added by daviddavis over 6 years ago

Revision d4ca40f1 | View on GitHub

Create a new jwt reset endpoint instead of a user field

Creating a new endpoint for resetting jwts instead of having a field on user to reset them. This also fixes user creation which is currently broken.

fixes #3075 https://pulp.plan.io/issues/3075

Added by daviddavis over 6 years ago

Revision d4ca40f1 | View on GitHub

Create a new jwt reset endpoint instead of a user field

Creating a new endpoint for resetting jwts instead of having a field on user to reset them. This also fixes user creation which is currently broken.

fixes #3075 https://pulp.plan.io/issues/3075

Actions #10

Updated by daviddavis over 6 years ago

  • Status changed from POST to MODIFIED
Actions #11

Updated by bmbouter about 6 years ago

  • Sprint set to Sprint 28
Actions #12

Updated by bmbouter about 6 years ago

  • Sprint/Milestone deleted (47)
Actions #13

Updated by daviddavis almost 5 years ago

  • Sprint/Milestone set to 3.0.0
Actions #14

Updated by bmbouter almost 5 years ago

  • Tags deleted (Pulp 3)
Actions #15

Updated by bmbouter over 4 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Also available in: Atom PDF