taori / NugetUnlister

dotnet global tool, to unlist nuget packages
MIT License
5 stars 0 forks source link

nuget.config support #27

Open iPilot opened 5 months ago

iPilot commented 5 months ago

Pretty nice tool, but for keeping clean our CI scripts we use nuget.config files. Does it support nuget.config file located in current working directory? Anyway, option --source <source name from the config> does not work at the moment.

taori commented 5 months ago

There is no nuget.config support, no. Which version of the tool are you using? There were some recent changes to --source with this PR. I would recommend checking it out and debugging it with your parameters to see where it goes wrong with your source target. Personally i have never used the tool with private artifact sources, so there might be some work necessary to get it working.

iPilot commented 5 months ago

I've tried the most recent version - 2.2.2. As I can see, PR expects the source as exact URL. Meanwhile, CLI dotnet nuget command can resolve source from the config with its alias. Therefore, I mistakenly, supposed that the tool works the same way.

I've tried to use nuget-unlist list all <package> --source gitlab-group

Here is an example of nuget.config file. Any dotnet nuget command in directory with such config file will be able to interact with both sources.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <packageSources>
     <add key="gitlab-group" value="https://gitlab.com/api/v4/groups/{id}/-/packages/nuget/index.json" />
     <add key="gitlab-project" value="https://gitlab.com/api/v4/projects/{id}/packages/nuget/index.json" />
 </packageSources>
 <packageSourceCredentials>
     <gitlab-group>
         <add key="Username" value="%GITLAB_PACKAGE_REGISTRY_USERNAME%" />
         <add key="ClearTextPassword" value="%GITLAB_PACKAGE_REGISTRY_PASSWORD%" />
     </gitlab-group>
     <gitlab-project>
         <add key="Username" value="%GITLAB_PACKAGE_REGISTRY_USERNAME%" />
         <add key="ClearTextPassword" value="%GITLAB_PACKAGE_REGISTRY_PASSWORD%" />
     </gitlab-project>     
 </packageSourceCredentials>
 <config>
    <add key="defaultPushSource" value="gitlab-project"/>
 </config>
</configuration>
taori commented 2 weeks ago

Do you know if gitlab also supports this for retrieving the package status? :

https://api.nuget.org/v3/registration5-gz-semver2/amusoft.toolkit.threading/1.0.1-alpha.10.json

I have time to take a stab at it, so i might be able to also add nuget config support potentially. Also it would be good to know if the tool worked for you if you explicitly specified a source, because from just taking a look at it, it appears gitlab works rather different from the nuget server itself. image

iPilot commented 2 weeks ago

Yes, Gitlab supports all basic Nuget APIs.

What's about the tool... Actually, it does not work. It uses incorrect url to access package info, despite the correct url is provided in the source info response. Valid is:

https://{gitlab-domain}/api/v4/projects/{project-id}/packages/nuget/metadata/{package-id}/{package-version}.json

What happened when command is used:

nuget-unlist list any {package-id} --source https://{gitlab-domain}/api/v4/groups/{group-id}/-/packages/nuget/index.json Loading packages from "https://{gitlab-domain}/api/v4/groups/{group-id}/-/packages/nuget/index.json/{package-id}/index.json". Unhandled exception: NugetUnlister.ExitCodeException: Response status code does not indicate success: 404 (Not Found).

I used source as it used in Visual Studio where it works fine

iPilot commented 2 weeks ago

Gitlab NuGet documentation. There are two different scopes: project and group. Packages can be downloaded in both scopes, but can only be published, updated or deleted in the project scope. It means that not every source is valid for the tool. But source validation might be too complicated...

taori commented 2 weeks ago

i can make the tool work with nuget.config, but making it work for gitlab would be another story, because it currently is only designed to work with the nuget source server. i can have a look at the gitlab nuget, to see how much effort it is.

iPilot commented 1 week ago

Is there any library for Nuget API interaction regardless exact services address it provides? It looks like source index page provides all the necessary information about services available.

taori commented 1 week ago

Apparently not. In fact during the runtime of the project they even changed the behavior of an existing service endpoint, which is why i noticed yesterday the tool no longer works. Currently refactoring it, so it works with service endpoints and setting up CI to regularly check whether the API is broken by nuget(/potentially gitlab) breaking the API i am using

taori commented 1 week ago

I have done some refactoring. Implementing the GitLab support should be fairly easy now. I do not have a gitlab server to test the tool against so i guess someone else will have to implement+test it.

iPilot commented 1 week ago

I can do it next weekends.

taori commented 1 week ago

Okay cool. Ideally we can look into the headers of the service index request, because in the index itself I did not see anything pointing out that it is gitlab Vs nuget. And knowing that is essential information to properly handle the code flow so this would work with gitlabs different way of getting the metadata for packages (in nuget I just append the package information) while gitlab does require token replacements. But I guess we will find out later

taori commented 1 week ago

Alternatively you give me the URLs so I can do it myself. Up to you. But I won't change the code unless I can verify that it works properly