Skip to content

Commit

Permalink
Module - adjust how version check is performed
Browse files Browse the repository at this point in the history
This removes calling the version endpoint in every command, only called once now.
  • Loading branch information
wsmelton committed May 28, 2021
1 parent 4795cf3 commit fb317ba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/classes/auth/TssSession.class.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ class TssSession {
[string]
$SecretServer

[string]
$SecretServerVersion

[string]
$ApiVersion = 'api/v1'

Expand Down
8 changes: 8 additions & 0 deletions src/functions/auth/New-Session.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ function New-Session {
}
}
$outputTssSession.StartTime = [datetime]::Now
try {
$uri = $outputTssSession.ApiUrl, 'version' -join '/'
$versionResponse = . $InvokeApi -Uri $uri -Method GET -PersonalAccessToken $outputTssSession.AccessToken

$outputTssSession.SecretServerVersion = $versionResponse.model.version
} catch {
Write-Warning "Issue reading version of [$SecretServer], this may be due to Hide Secret Server Version Numbers being disabled. Version support is limited in the module and may affect functionality of some functions."
}
return $outputTssSession
} else {
Write-Warning "SecretServer argument not found"
Expand Down
13 changes: 1 addition & 12 deletions src/parts/CheckVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,7 @@ begin {
}
process {
$source = $Invocation.MyCommand
$uri = $TssSession.ApiUrl, 'version' -join '/'

$invokeParams.Uri = $Uri
$invokeParams.Method = 'GET'

try {
$restResponse = . $InvokeApi @invokeParams
} catch {
Write-Warning "Issue reading version of [$source], verify Hide Secret Server Version Numbers is disabled in Secret Server"
}

$currentVersion = $restResponse.model.version
$currentVersion = $TssSession.SecretServerVersion

if ($currentVersion -lt $MinimumSupported) {
Write-Warning "[$source] is only supported on [$MinimumSupported]+ of Secret Server. Secret Server host [$($TssSession.SecretServer)] version: [$currentVersion]"
Expand Down

0 comments on commit fb317ba

Please sign in to comment.