Skip to content

Commit

Permalink
module CheckVersion - convert to private binary command, Compare-TssV…
Browse files Browse the repository at this point in the history
…ersion
  • Loading branch information
wsmelton committed Sep 29, 2021
1 parent 2e5ceac commit 0568794
Show file tree
Hide file tree
Showing 204 changed files with 260 additions and 233 deletions.
6 changes: 6 additions & 0 deletions .vscode/tss.code-snippets
Expand Up @@ -955,6 +955,12 @@
" [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]",
" public Thycotic.PowerShell.Authentication.Session TssSession {get; set;}",
" }",
"",
"",
" protected override void ProcessRecord()",
" {",
" base.ProcessRecord();",
" }",
"}"
],
"description": "cmdlet base"
Expand Down
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace Thycotic.SecretServer.Cmdlets
{
/// <summary>
/// <para type="synopsis">Comparing Secret Server version to supported version for a given command</para>
/// <para type="description">Comparing Secret Server version to supported version for a given command</para>
/// </summary>
[Cmdlet(VerbsData.Compare, "TssVersion")]
public class CompareVersionCmdlet : PSCmdlet
{
///<summary>
///<para type="description">TssSession object created by New-TssSession for authentication</para>
///</summary>
[Parameter(Mandatory = true, Position = 0)]
public Thycotic.PowerShell.Authentication.Session TssSession {get; set;}

///<summary>
///<para type="description">Minimum supported version for the command</para>
///</summary>
[Parameter(Mandatory = true, Position = 1)]
public Version MinimumSupported { get; set; }

///<summary>
///<para type="description">Invocation from calling command</para>
///</summary>
[Parameter(Mandatory = true, Position = 2)]
public InvocationInfo Invocation { get; set; }

protected override void ProcessRecord()
{
var ignoreVersion = SessionState.PSVariable.GetValue("ignoreVersion");
var tssIgnoreVersionCheck = SessionState.PSVariable.GetValue("tss_ignoreversioncheck");
if (!Convert.ToBoolean(ignoreVersion) || !Convert.ToBoolean(tssIgnoreVersionCheck))
{
string sourceCommand = Invocation.MyCommand.ToString();
var currentVersion = new Version(TssSession.SecretServerVersion.ToString());
var result = currentVersion.CompareTo(MinimumSupported);

if (result < 0)
{
WriteVerbose("[" + sourceCommand + "]: Detected version, [" + currentVersion + "], lower than command's supported version of [" + MinimumSupported + "].");
return;
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/functions/configurations/Disable-TssUnlimitedAdmin.ps1
Expand Up @@ -41,7 +41,7 @@ function Disable-TssUnlimitedAdmin {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'unlimited-admin' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'PATCH'
Expand Down
2 changes: 1 addition & 1 deletion src/functions/configurations/Enable-TssUnlimitedAdmin.ps1
Expand Up @@ -41,7 +41,7 @@ function Enable-TssUnlimitedAdmin {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'unlimited-admin' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'PATCH'
Expand Down
Expand Up @@ -58,7 +58,7 @@ function Export-TssAutoExportStorageItem {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'auto-export-storage', 'item', $Id -join '/'
$itemFilename = $Filename + '.zip'
$outFile = [System.IO.Path]::Combine($Output, $itemFilename)
Expand Down
2 changes: 1 addition & 1 deletion src/functions/configurations/Get-TssConfiguration.ps1
Expand Up @@ -42,7 +42,7 @@ function Get-TssConfiguration {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000032' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000032' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'general' -join '/'

$uriParams = @()
Expand Down
Expand Up @@ -36,7 +36,7 @@ function Get-TssConfigurationAutoExport {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation
$restResponse = $null
$uri = $TssSession.ApiUrl, 'configuration', 'auto-export' -join '/'
$invokeParams.Uri = $uri
Expand Down
Expand Up @@ -36,7 +36,7 @@ function Get-TssConfigurationBackup {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'backup' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'
Expand Down
Expand Up @@ -36,7 +36,7 @@ function Get-TssConfigurationLocalUserPassword {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'local-user-passwords' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'
Expand Down
2 changes: 1 addition & 1 deletion src/functions/configurations/Get-TssConfigurationLogin.ps1
Expand Up @@ -36,7 +36,7 @@ function Get-TssConfigurationLogin {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'login' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'
Expand Down
2 changes: 1 addition & 1 deletion src/functions/configurations/Get-TssConfigurationRpc.ps1
Expand Up @@ -36,7 +36,7 @@ function Get-TssConfigurationRpc {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'rpc' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'
Expand Down
2 changes: 1 addition & 1 deletion src/functions/configurations/Get-TssConfigurationSaml.ps1
Expand Up @@ -36,7 +36,7 @@ function Get-TssConfigurationSaml {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'saml' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'
Expand Down
Expand Up @@ -36,7 +36,7 @@ function Get-TssConfigurationSearchIndex {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'secret-search-indexer' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'
Expand Down
Expand Up @@ -36,7 +36,7 @@ function Get-TssConfigurationSecurity {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'security' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'
Expand Down
Expand Up @@ -40,7 +40,7 @@ function Get-TssConfigurationSiteConnector {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$restResponse = $null
$uri = $TssSession.ApiUrl, 'configuration', 'site-connector' -join '/'
$invokeParams.Uri = $uri
Expand Down
Expand Up @@ -36,7 +36,7 @@ function Search-TssAutoExportStorage {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'auto-export-storage' -join '/'
$uri = $uri, "sortBy[0].direction=desc&sortBy[0].name=Id&take=$($TssSession.Take)" -join '?'
$invokeParams.Uri = $uri
Expand Down
Expand Up @@ -51,7 +51,7 @@ function Search-TssConfigurationAudit {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration','audit' -join '/'
$uri = $uri, "sortBy[0].direction=desc&sortBy[0].name=$SortBy&take=$($TssSession.Take)" -join '?'
$invokeParams.Method = 'GET'
Expand Down
Expand Up @@ -40,7 +40,7 @@ function Search-TssConfigurationBackupLog {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation
$uri = ($TssSession.ApiUrl -replace 'v1','v2'), 'configuration', 'backup-logs' -join '/'
$uri = $uri, "sortBy[0].direction=desc&sortBy[0].name=$SortBy&take=$($TssSession.Take)" -join '?'
$invokeParams.Uri = $uri
Expand Down
Expand Up @@ -79,7 +79,7 @@ function Set-TssConfigurationAutoExport {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($setParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '11.0.0005' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '11.0.0005' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'auto-export' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'PATCH'
Expand Down
Expand Up @@ -181,7 +181,7 @@ function Set-TssConfigurationGeneral {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($setParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'general' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'PATCH'
Expand Down
Expand Up @@ -99,7 +99,7 @@ function Set-TssConfigurationLocalUserPassword {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($setParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'local-user-passwords' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'PATCH'
Expand Down
2 changes: 1 addition & 1 deletion src/functions/configurations/Set-TssConfigurationLogin.ps1
Expand Up @@ -79,7 +79,7 @@ function Set-TssConfigurationLogin {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($setParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'login' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'PATCH'
Expand Down
2 changes: 1 addition & 1 deletion src/functions/configurations/Set-TssConfigurationRpc.ps1
Expand Up @@ -70,7 +70,7 @@ function Set-TssConfigurationRpc {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($setParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'rpc' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'PATCH'
Expand Down
Expand Up @@ -93,7 +93,7 @@ function Set-TssConfigurationSecurity {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($setParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'security' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'PATCH'
Expand Down
Expand Up @@ -35,7 +35,7 @@ function Start-TssConfigurationBackup {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'backup', 'run-now' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'POST'
Expand Down
Expand Up @@ -35,7 +35,7 @@ function Start-TssConfigurationSearchIndex {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'configuration', 'secret-search-indexer', 'rebuild-index' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'POST'
Expand Down
2 changes: 1 addition & 1 deletion src/functions/diagnostics/Search-TssSystemLog.ps1
Expand Up @@ -54,7 +54,7 @@ function Search-TssSystemLog {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '11.0.000000' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '11.0.000000' $PSCmdlet.MyInvocation
$uri = ($TssSession.ApiUrl -replace 'v1','v2'), 'diagnostics', 'system-logs' -join '/'
$uri = $uri, "sortBy[0].direction=desc&sortBy[0].name=$SortBy&take=$($TssSession.Take)" -join '?'
$invokeParams.Method = 'GET'
Expand Down
Expand Up @@ -58,7 +58,7 @@ function Add-TssDirectoryServiceGroup {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'directory-services', 'domains', $DomainId, 'group' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'POST'
Expand Down
Expand Up @@ -48,7 +48,7 @@ function Get-TssDirectoryServiceDomain {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
foreach ($domain in $Id) {
$uri = $TssSession.ApiUrl, 'directory-services', 'domains', $domain -join '/'
$invokeParams.Uri = $uri
Expand Down
Expand Up @@ -36,7 +36,7 @@ function Get-TssDirectoryServiceSyncStatus {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'directory-services', 'synchronization' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'
Expand Down
Expand Up @@ -133,7 +133,7 @@ function New-TssDirectoryService {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssNewParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$restResponse = $null
$uri = $TssSession.ApiUrl, 'directory-services', 'domains' -join '/'
$invokeParams.Uri = $uri
Expand Down
Expand Up @@ -52,7 +52,7 @@ function Remove-TssDirectoryServiceGroup {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
foreach ($group in $GroupId) {
$restResponse = $null
$uri = $TssSession.ApiUrl, 'directory-services', 'domains', $DomainId, 'group', $group -join '/'
Expand Down
Expand Up @@ -49,7 +49,7 @@ function Search-TssDirectoryServiceDomain {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation
$restResponse = $null
$uri = $TssSession.ApiUrl, 'directory-services', 'domains' -join '/'
$uri = $uri, "sortBy[0].direction=asc&sortBy[0].name=$SortBy&take=$($TssSession.Take)&filter.includeInactive=$([boolean]$IncludeInactive)" -join '?'
Expand Down
Expand Up @@ -52,7 +52,7 @@ function Search-TssDirectoryServiceGroup {
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'directory-services', 'domains', $DomainId, 'groups', 'search-directory' -join '/'
$uri = $uri, "searchText=$SearchText" -join '?'
$invokeParams.Uri = $uri
Expand Down

0 comments on commit 0568794

Please sign in to comment.