Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import-module vsteam loses previously stored configuration #493

Closed
mnieto opened this issue Sep 21, 2022 · 2 comments · Fixed by #508
Closed

import-module vsteam loses previously stored configuration #493

mnieto opened this issue Sep 21, 2022 · 2 comments · Fixed by #508
Labels
bug when a bug has been identified or filed

Comments

@mnieto
Copy link
Contributor

mnieto commented Sep 21, 2022

Steps to reproduce

Once configured the module with Set-VSTeamAccount:

Set-VSTeamAccount -Account myOrganization -PersonalAccessToken myToken -Version AzD -Level User
Set-VSTeamDefaultProject MyProject

If we close the powersell session and open a new one:

 Get-ChildItem env:team*

output

Name                           Value
----                           -----
TEAM_PROJECT                   MyProject
TEAM_VERSION                   AzD
TEAM_ACCT                      https://dev.azure.com/myOrganization
TEAM_PAT                       OmljeH...................WE=

Then, import the module and test the env variables:

import-module vsteam
Get-ChildItem env:team*

output now is:

Name                           Value
----                           -----
TEAM_ACCT                      https://dev.azure.com/siemensgamesa
TEAM_PAT                       Ok9tbGplS..........................zk0WVhaM2RqSnJaemMxZEhwc2FHWTN…

We lost the version, default project and TEAM_PAT has changed
Because the last one, we cannot connect to azure services and we need to run Set-VSTeamAccount in each new powershell session

Expected behavior

Configuration is recovered from previous sessions

Actual behavior?

TEAM_PAT has change and default project name and Version are lost

We cannot connect to azure services and we need to run Set-VSTeamAccount in each new powershell session

This happen in version 7.9.0

On Which OS have you tried it?

Windows

What was your server version?

Azure DevOps Services

Other server version

No response

Log output of used API

Get-VSTeamAPIVersion

Billing                     : 5.1-preview.1
Build                       : 5.1
Core                        : 5.1
DistributedTask             : 6.0-preview
DistributedTaskReleased     : 5.1
ExtensionsManagement        : 6.0-preview
Git                         : 5.1
Graph                       : 6.0-preview
HierarchyQuery              : 5.1-preview
MemberEntitlementManagement : 6.0-preview
Packaging                   : 6.0-preview
Pipelines                   : 5.1-preview
Policy                      : 5.1
Processes                   : 6.0-preview
Release                     : 5.1
ServiceEndpoints            : 5.0-preview
TaskGroups                  : 6.0-preview
Tfvc                        : 5.1
VariableGroups              : 5.1-preview.1
Version                     : VSTS
Wiki                        : 6.0
WorkItemTracking            : 6.0-preview.1

Log output of $PSVersionTable

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
@mnieto mnieto added the bug when a bug has been identified or filed label Sep 21, 2022
@mnieto
Copy link
Contributor Author

mnieto commented Sep 21, 2022

I think the problem was introduced in commit 0528c76 due #467 and closed with #480

While loading the module, if there is a default project, it executes
Set-VSTeamAccount -Account $env:TEAM_ACCT -PersonalAccessToken $env:TEAM_PAT

But:

  • $env:TEAM_PAT already has been base64 encoded during the previous Set-VSTeamAccount.
  • The call has missing the -Version parameter, so it will take the default one: VSTS
  • If the previous Set-VSTeamAccount was called with -UserBearerToken, it will fail to initialize because the variable $env:TEAM_PAT is not set
  • Not sure how the default project is lost

I managed to make it work with

      # set vsteam account to initialize given variables properly
      $pat = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($env:TEAM_PAT))   #decode base64 stored pat
      $pat = $pat.Substring(1)                                                                           #remove the leading :
      $defaultProject = $env:TEAM_PROJECT                                                                #save temporary defalt project because is removed during Set-VSTeamAccount call
      Set-VSTeamAccount -Account $env:TEAM_ACCT -PersonalAccessToken $pat -Version $env:TEAM_VERSION
      # Make sure the value in the environment variable still exisits.
      if (Get-VSTeamProject | Where-Object ProjectName -eq $defaultProject) {
         Set-VSTeamDefaultProject -Project $defaultProject
      }
      else {
         Write-Warning "The default project '$defaultProject' stored in the environment variable TEAM_PROJECT does not exist."
      }

but still not resolved the issue that security was configured with -UserBearerToken parameter instead -PersonalAccessToken

@bmkaiser
Copy link

What's the best way to get this resolved? I'm currently working around this by adding the following to my PowerShell profile after importing the VSTeam module:

Set-VSTeamAccount -Account 'Foo' -Level 'User' -SecurePersonalAccessToken $securePAT
Set-VSTeamDefaultProject -Project 'Bar' -Level 'User'

Much thanks for @mnieto for identifying the issue and creating pull request #508!

SebastianSchuetze added a commit that referenced this issue May 20, 2023
This pull request resolves two main issues. First, it fixes bug #493 where the `import-module vsteam` command was causing loss of previously stored configurations. Second, it corrects the 'Versions' test failure on local setups when `Set-VSTeamAccount` is used with the `-Local` parameter. This issue didn't surface during GitHub builds due to the `TEAM_VERSION` variable not being set. In addition to these fixes, the pull request includes updates to the change log and documentation.

---------

Co-authored-by: Sebastian S Schütze <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug when a bug has been identified or filed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants