apisix-dashboard icon indicating copy to clipboard operation
apisix-dashboard copied to clipboard

bug: The consumer can not be delete by dashboard which created by admin API

Open idbeta opened this issue 6 years ago • 24 comments

  • Why do you submit this issue?
  • [ ] Question or discussion
  • [x] Bug
  • [ ] Requirements
  • [ ] Feature or performance improvement
  • [ ] Other

I used admin API created a consumer like this

curl http://127.0.0.1:9080/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
  "username": "user123",
  "plugins": {
      "jwt-auth": {
          "key": "dd",
          "secret": "my-secret-key"
      }
  }
}'

but when I try to delete it by dashboard, it prompt error image

idbeta avatar Nov 07 '20 08:11 idbeta

but when I try to delete it by dashboard, it prompt error

What is the request sent by the front end at this time?

Is there a network API call?

membphis avatar Nov 07 '20 08:11 membphis

@membphis request

Request URL: http://127.0.0.1:8080/apisix/admin/consumers/
Request Method: DELETE
Status Code: 200 OK

response image

idbeta avatar Nov 07 '20 08:11 idbeta

Request URL: http://127.0.0.1:8080/apisix/admin/consumers/ Request Method: DELETE

the URL should be wrong. missing consumer name.

https://github.com/apache/apisix/blob/master/doc/admin-api.md#consumer

membphis avatar Nov 07 '20 08:11 membphis

@membphis That’s because the API doesn’t return consumer name.

juzhiyuan avatar Nov 07 '20 10:11 juzhiyuan

Why the update time is 1970 in dashboard? @juzhiyuan

moonming avatar Nov 07 '20 10:11 moonming

image

@membphis This issue is related to API, that's because the API doesn't return ID as agreed.

https://github.com/apache/apisix-dashboard/blob/v2.0/web/src/pages/Consumer/List.tsx#L65

juzhiyuan avatar Nov 07 '20 10:11 juzhiyuan

Why the update time is 1970 in dashboard? @juzhiyuan

because the date returned from API is invalid.

juzhiyuan avatar Nov 07 '20 10:11 juzhiyuan

@idbeta Why not paste the response here?

juzhiyuan avatar Nov 07 '20 10:11 juzhiyuan

@membphis That’s because the API doesn’t return consumer name.

But the user name can display in dashboard

moonming avatar Nov 07 '20 10:11 moonming

@membphis That’s because the API doesn’t return consumer name.

But the user name can display in dashboard

ID has been used since the beginning, and no one tells us to fallback to a username.

juzhiyuan avatar Nov 07 '20 10:11 juzhiyuan

image

@membphis @moonming And according to this doc, we MUST use the ID as the key instead of the username.

juzhiyuan avatar Nov 07 '20 10:11 juzhiyuan

the id and username must be the same. if they were not the same, will return an error message. confirm this.

if we can get username, we should use username. if not, we can use id.

I create an issue right now to fix the doc issue: https://github.com/apache/apisix/issues/2651

membphis avatar Nov 08 '20 00:11 membphis

@juzhiyuan

if we can get username, we should use username. if not, we can use id.

frontend should use this way to read the consumer id.

membphis avatar Nov 08 '20 00:11 membphis

Why the frontend should do this fallback? If it's sure that we must use the username as identify (from docs), then both fe and backend should use the username.

juzhiyuan avatar Nov 08 '20 00:11 juzhiyuan

I check the process in APISIX, I am sure that we can use username is enough. then we can ignore the field id.

use the username as identify (from docs), then both fe and backend should use the username

agree +1

membphis avatar Nov 08 '20 00:11 membphis

@juzhiyuan if we both use username, please confirm the frontend need to update.

it shows you mainly use id now: https://github.com/apache/apisix-dashboard/issues/718#issuecomment-723427291

membphis avatar Nov 08 '20 00:11 membphis

Yes, the frontend has to update the consumer.

juzhiyuan avatar Nov 08 '20 00:11 juzhiyuan

@nic-chen please confim if we need any update for manager-api. I think we do not need to update manager-api.

if we do not need to update manager-api, we should remove the label backend.

membphis avatar Nov 08 '20 02:11 membphis

@nic-chen please confim if we need any update for manager-api. I think we do not need to update manager-api.

if we do not need to update manager-api, we should remove the label backend.

yes, we do not need to update manager-api.

nic-chen avatar Nov 08 '20 02:11 nic-chen

https://github.com/apache/apisix-dashboard/blob/v2.0/api/internal/handler/consumer/consumer.go#L102-L110

Should the manager-api still handle ID? cc @nic-chen @membphis

juzhiyuan avatar Nov 08 '20 04:11 juzhiyuan