Skip to content

Commit

Permalink
Compare-TssVersion (internal command) - fixes #243
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Oct 8, 2021
1 parent a0a989a commit 28f64d1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
38 changes: 38 additions & 0 deletions src/Thycotic.SecretServer.Format.ps1xml
@@ -1,6 +1,44 @@
<?xml version="1.0" encoding="utf-16"?>
<Configuration>
<ViewDefinitions>
<!-- Thycotic.PowerShell.Authentication.Session -->
<View>
<Name>Authentication.Session</Name>
<ViewSelectedBy>
<TypeName>Thycotic.PowerShell.Authentication.Session</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>SecretServer</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>SecretServerVersion</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>TokenType</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>StartTime</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>TimeOfDeath</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

<View>
<Name>Secrets.Secret</Name>
<ViewSelectedBy>
Expand Down
Expand Up @@ -22,7 +22,7 @@ public class CompareVersionCmdlet : PSCmdlet
///<para type="description">Minimum supported version for the command</para>
///</summary>
[Parameter(Mandatory = true, Position = 1)]
public Version MinimumSupported { get; set; }
public string MinimumSupported { get; set; }

///<summary>
///<para type="description">Invocation from calling command</para>
Expand All @@ -34,15 +34,16 @@ protected override void ProcessRecord()
{
var ignoreVersion = SessionState.PSVariable.GetValue("ignoreVersion");
var tssIgnoreVersionCheck = SessionState.PSVariable.GetValue("tss_ignoreversioncheck");
if (!Convert.ToBoolean(ignoreVersion) || !Convert.ToBoolean(tssIgnoreVersionCheck))
if ((!Convert.ToBoolean(ignoreVersion) || !Convert.ToBoolean(tssIgnoreVersionCheck)) && !String.IsNullOrEmpty(TssSession.SecretServerVersion))
{
var minSupproted = new Version(MinimumSupported);
string sourceCommand = Invocation.MyCommand.ToString();
var currentVersion = new Version(TssSession.SecretServerVersion.ToString());
var result = currentVersion.CompareTo(MinimumSupported);
var result = currentVersion.CompareTo(minSupproted);

if (result < 0)
{
WriteVerbose("[" + sourceCommand + "]: Detected version, [" + currentVersion + "], lower than command's supported version of [" + MinimumSupported + "].");
WriteVerbose("[" + sourceCommand + "]: Detected version, [" + currentVersion + "], lower than command's supported version of [" + minSupproted + "].");
return;
}
}
Expand Down
14 changes: 6 additions & 8 deletions src/functions/authentication/New-TssSession.ps1
Expand Up @@ -238,14 +238,12 @@ function New-TssSession {
if ($ignoreVersion -or ((Test-Path variable:tss_ignoreversioncheck) -and $tss_ignoreversioncheck)) {
Write-Verbose "tss_ignoreversioncheck set to true, module will not perform Secret Server version check"
} else {
try {
Write-Verbose "Attempting to retrieve Secret Server host version"
$versionResponse = Get-TssVersion -TssSession $outputTssSession
$outputTssSession.SecretServerVersion = $versionResponse.Version
if ($outputTssSession.SecretServerVersion) {
Write-Verbose "Version info received successfully: $($outputTssSession.SecretServerVersion)"
}
} catch {
Write-Verbose "Attempting to retrieve Secret Server host version"
$versionResponse = Get-TssVersion -TssSession $outputTssSession -ErrorAction SilentlyContinue
$outputTssSession.SecretServerVersion = $versionResponse.Version
if ($outputTssSession.SecretServerVersion) {
Write-Verbose "Version info received successfully: $($outputTssSession.SecretServerVersion)"
} else {
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."
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/version/Get-TssVersion.ps1
Expand Up @@ -52,7 +52,7 @@ function Get-TssVersion {
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue getting audits for [$secret]"
Write-Warning "Issue getting version details for [$($TssSession.SecretServer)]"
$err = $_
. $ErrorHandling $err
}
Expand Down

0 comments on commit 28f64d1

Please sign in to comment.