MethodsAndPractices / vsteam

PowerShell module for accessing Azure DevOps Services and Azure DevOps Server (formerly VSTS or TFS)
https://methodsandpractices.github.io/vsteam-docs/
MIT License
444 stars 155 forks source link

Update Single Variable #423

Closed sevaa closed 1 year ago

sevaa commented 2 years ago

There is no cmdlet to update/create a single variable in a variable group. I'd like one, please. There is a task to get and save the whole group, but I'm after a one liner. This is not for me, this is for a community of users, so instructing them to write a multiline powershell script would not be elegant.

That said, a cmdlet like this would go against what seems to be the convention in this module, specifically that each cmdlet wraps a single REST API call and the consumers are expected to do the rest.

What's the best path forward?

  1. Leave this issue here, hope the maintainers implement one
  2. Implement a cmdlet myself, submit a PR
  3. Implement a cmdlet, publish in my own module

Please advice.

SebastianSchuetze commented 2 years ago

Hi @sevaa,

Third one is not a very good option when it comes to helping the community :-)

But a while ago we went away from only wrapping one API call. So we already have cmdlets the reuse more basic cmdlets of the same module. So I would suggest the same.

Make a cmdlet for every API call you need if it's not already existing and then make your e.g. Update-VSTeamVariableGroupVariable (redundant name, but it's an example)

So I looked further and I think you would just wrap the *-VSTeamVariableGroup cmdlets.

#updates a variable and marks it as a secret
Update-VSTeamVariableGroupVariable -Name "var1" -Value "mysecret" -IsSecret

# updates a clear text variable
Update-VSTeamVariableGroupVariable -Name "var1" -Value "val"

#other examples
Add-VSTeamVariableGroupVariable -Name "var1" -Value "val"
Add-VSTeamVariableGroupVariable -Name "var1" -Value "mysecret" -IsSecret
Remove-VSTeamVariableGroupVariable -Name "var1"

Long story short: Go ahead and make a PR

SebastianSchuetze commented 2 years ago

That said, a cmdlet like this would go against what seems to be the convention in this module, specifically that each cmdlet wraps a single REST API call and the consumers are expected to do the rest.

Btw. is this stated somewhere in text? If yes then I need to adjust that!

sevaa commented 2 years ago

each cmdlet wraps a single REST API call

is this stated somewhere in text?

I don't think it's ever stated explicitly, but at least at some point, maybe early on, the guiding principle of this module's design seemed to be, well, exactly that.

Understood re: the rest, it's forking time :) I think it'd be a "Set"-type command, since I expect it to either add variable if one doesn't exist, or update the value if it does.

SebastianSchuetze commented 2 years ago

Yes maybe and also setting a variable might be destructive. So, a ShouldProcess could be a good thing to do.

sevaa commented 2 years ago

Explain please.

SebastianSchuetze commented 2 years ago

You can look at a code example here: https://github.com/MethodsAndPractices/vsteam/blob/trunk/Source/Public/Set-VSTeamApproval.ps1

Any cmdlet using "Set" should implement the "ShouldProcess". Because "Set" is something like doing a setting. This is also activated when we run "PSScriptAnalyzer" which states this.

More Info:

sevaa commented 1 year ago

Done, see PR #495. No support for secret vars, though.

sevaa commented 1 year ago

Hello, are any maintainers reading this? PR #495 is (I think) ready.