chocolatey / cChoco

Community resource to manage Chocolatey
Apache License 2.0
154 stars 99 forks source link

Allow cChocoSource to update an existing Source #156

Closed bozho closed 2 years ago

bozho commented 3 years ago

Is your feature request related to a problem? Please describe. cChocoSource does not update source URL on an existing source.

Describe the solution you'd like cChocoSource to update source URL if a source with the specified Name already exists.

Describe alternatives you've considered Manually deleting Chocolatey source on managed servers when URL changes.

Additional context I've submitted a patch.

pauby commented 3 years ago

Appreciate it's been some time since you submitted this but that is not the correct Chocolatey behaviour. Without additional information we can't look into this. Can you go back and complete the bug issue template?

laoist commented 2 years ago

This might be related, if it's not let me know.

I have my Chocolatey packages sitting in Azure DevOps Artefacts repostiory, hosts need to authenticate using a token which has an expiry date. I'm unable to simply update the credentials in order for the source to be updated, I instead have to remove the source and add it again, which brings further complicates due to the source name being a unique value.

In each of the below scenarios, the source credential is updated ($ChocolateySourceCredential).

Example of what I currently have to do: This is pretty messy.

    cChocoSource RemoveMyRepo_Old
    {
        Name = 'MyRepo-20210901-0'
        Ensure = 'Absent'
        DependsOn = '[cChocoInstaller]ChocoInstaller'
    }
    cChocoSource AddMyRepo
    {
        Name = 'MyRepo-20210901-1'
        Ensure = 'Present'
        Priority = 0
        Source = 'https://mytenant.pkgs.visualstudio.com/MyCodeRepo/_packaging/MyRepo/nuget/v2/'
        Credentials = $ChocolateySourceCredential
        DependsOn = '[cChocoSource]RemoveMyRepo_Old'
    }

Example of what I'm okay with, but not ideal: I think this would be okay but as mentioned, it doesn't work due to repo name being a unique key.

    cChocoSource RemoveMyRepo
    {
        Name = 'MyRepo'
        Ensure = 'Absent'
        DependsOn = '[cChocoInstaller]ChocoInstaller'
    }
    cChocoSource AddMyRepo
    {
        Name = 'MyRepo
        Ensure = 'Present'
        Priority = 0
        Source = 'https://mytenant.pkgs.visualstudio.com/MyCodeRepo/_packaging/MyRepo/nuget/v2/'
        Credentials = $ChocolateySourceCredential
        DependsOn = '[cChocoSource]RemoveMyRepo'
    }

Example I'd like to see: Unsure if this is possible really, as the only thing that would change is the source credential, so it would need to test if the current credential on the host is different to the new one.

    cChocoSource AddMyRepo
    {
        Name = 'MyRepo
        Ensure = 'Present'
        Priority = 0
        Source = 'https://mytenant.pkgs.visualstudio.com/MyCodeRepo/_packaging/MyRepo/nuget/v2/'
        Credentials = $ChocolateySourceCredential
        DependsOn = '[cChocoSource]ChocoInstaller'
    }
bozho commented 2 years ago

@pauby Sorry for a late update.

@laoist gave a nice example of the problem.

Chocolatey does not support altering the URL. My patch removes and re-creates the source on URL changes.