docker / hub-feedback

Feedback and bug reports for the Docker Hub
https://hub.docker.com
234 stars 39 forks source link

Querying for namespaces does not return organizational namespaces (REST API) #2117

Closed karolz-ms closed 3 years ago

karolz-ms commented 3 years ago

When querying Docker Hub via its REST API, the v2/repositories/namespaces query only returns namespaces associated with the Docker Hub login. The same query used by the Docker Hub site UI returns both namespaces associated with the login, as well as namespaces owned by all organizations that the user belongs to.

Full repro steps (using VS Code) are available from related VS Code Docker extension issue

silvin-lubecki commented 3 years ago

Hello @karolz-ms ! Thanks for filling this issue 👍 I checked it on my side, but I got the same results between the Hub-UI and a cURL request... Hub-UI:

Screen Shot 2021-07-05 at 10 59 28

cURL:

$ curl --request GET \
  --url https://hub.docker.com/v2/repositories/namespaces/ \
  --header 'Authorization: Bearer XXXXX.XXXXX.XXXXX' \
{"namespaces": ["composeonkubernetes", "dockerinternal", "kamoulox", "silvinorgtest", "slubecki"]}

But maybe I'm misunderstanding your point ? Can you add more context about what you get from hub-ui, and what you got by calling the API directly, and what you expect ? Thanks !

karolz-ms commented 3 years ago

Silvin, good question, and sorry for stating the problem poorly.

I have the following setup:

When I log to Docker Hub website using karolzms credentials, I can see the zpkarolfriends/hwflask repository with no difficulty.

When I log in to Docker Hub from VS Code though, VS code issues a GET HTTP request with the path v2/repositories/namespaces?page_size=100 against GitHub API, no namespaces are returned. I tried the same query using curl, with the same effect.

Hope this makes it clearer?

nebuk89 commented 3 years ago

Yep that does thanks @karolz-ms we are able to reproduce and are looking into this further

ruggi commented 3 years ago

Hey @karolz-ms 👋 we just deployed a fix for this issue. Any chance you can give it another go and see if it is indeed as expected on your end too? Thanks!

karolz-ms commented 3 years ago

Hey @ruggi thanks for checking, but no, unfortunately I do not see the zpkarolfriends organization returned from the namespaces query when I log as karolzms user. Only karolzms namespace is returned... 😞 So it is a change, but I still don't get from the query the organizational namespace I was hoping to see.

Please let me know if I can try something else?

silvin-lubecki commented 3 years ago

Hello @karolz-ms, can I ask how you call the Docker Hub API? What is the authentication process you use (ie: Bearer token)?

karolz-ms commented 3 years ago

@silvin-lubecki yes, bearer token. The relevant code is

https://github.com/microsoft/vscode-docker/blob/main/src/tree/registries/dockerHub/DockerHubAccountTreeItem.ts#L49

(see loadMoreChildrenImpl, signRequest and refreshToken functions in this file)

silvin-lubecki commented 3 years ago

Hello @karolz-ms, I have a question after parsing your code. What is your intent when you query namespaces? If I understand it correctly, you want to display a tree view with all the organizations the user is part of, then all the repositories inside? After re-checking our /namespaces code, in the end it behaves as expected, ie: it returns all the organizations where you are an owner. Can I suggest you to use the /v2/user/orgs/ endpoint instead, so you can list all the organizations ? Happy to help you to migrate to the new endpoint if needed 👍

bwateratmsft commented 3 years ago

So v2/repositories/namespaces is specifically for owners? If so we'll have to query /v2/user/orgs as you suggest and merge it.

@karolz-ms can you add me to the zpkarolfriends org and I can try these scenarios out?

karolz-ms commented 3 years ago

@bwateratmsft done

silvin-lubecki commented 3 years ago

Hello @karolz-ms , I can see you patched the code to use /v2/user/orgs https://github.com/microsoft/vscode-docker/commit/f4ac5cd1e664244a89c1f4a5edb22463abc36c8e. Does that fix the issue? Can I close the ticket?

bwateratmsft commented 3 years ago

I think that would be fine, any objections @karolz-ms?

karolz-ms commented 3 years ago

Yep, looks good, thanks @silvin-lubecki !