Skip to content

Commit

Permalink
added a way to reset api tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
regg00 committed Jul 11, 2023
1 parent 5dfab2c commit b3b0874
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions PSPsat.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,26 @@ function Connect-Psat {
#>
param (
[String] $ApiToken
)
[String] $ApiToken,
[Switch] $Force
)

if ($Force) {
# Reset the local file and environment variables
$env:PsatApiToken = ""
Remove-Item -Force -ErrorAction SilentlyContinue "$env:USERPROFILE/.psat/psat.json"
Write-Host -ForegroundColor Yellow "All Api Tokens removed. Run the Connect-Psat command again to reconnect."
Exit 0
}

if ($ApiToken) {
$env:PsatApiToken = $ApiToken
Save-Token -ApiToken $ApiToken

}
elseif (Test-Path "$env:USERPROFILE/.psat/psat.json") {
$env:PsatApiToken = (Get-Content "$env:USERPROFILE/.psat/psat.json" | Convertfrom-json).apiToken
Write-Host -ForegroundColor Yellow "Api Token automatically loaded from user profile."

}
else {
Expand Down Expand Up @@ -45,6 +56,8 @@ function Save-Token {
apiToken = $ApiToken
}
$JsonContent | ConvertTo-Json | Out-File ( New-Item -Path "$env:USERPROFILE/.psat/psat.json" -Force )

Write-Host -ForegroundColor Yellow "Api Token sucessfully saved into the user profile."
}

1 { Continue }
Expand Down

0 comments on commit b3b0874

Please sign in to comment.