From 8cf433278dec51c15b3ac20da78a7e76d4dec99b Mon Sep 17 00:00:00 2001 From: Shawn Melton <11204251+wsmelton@users.noreply.github.com> Date: Tue, 31 Aug 2021 20:55:56 -0500 Subject: [PATCH] Get-TssSecretDependencyScript - new command --- .../Get-TssSecretDependencyScript.md | 58 ++++++++++++++++++ src/Thycotic.SecretServer.Format.ps1xml | 34 +++++++++++ .../OdbcConnectionArgument.cs | 13 ++++ .../classes/secret-dependencies/Script.cs | 15 +++++ .../secret-dependencies/ScriptArgument.cs | 14 +++++ .../Get-TssSecretDependencyScript.ps1 | 61 +++++++++++++++++++ .../Get-TssSecretDependencyScript.Tests.ps1 | 24 ++++++++ 7 files changed, 219 insertions(+) create mode 100644 docs/commands/secret-dependencies/Get-TssSecretDependencyScript.md create mode 100644 src/Thycotic.SecretServer/classes/secret-dependencies/OdbcConnectionArgument.cs create mode 100644 src/Thycotic.SecretServer/classes/secret-dependencies/Script.cs create mode 100644 src/Thycotic.SecretServer/classes/secret-dependencies/ScriptArgument.cs create mode 100644 src/functions/secret-dependencies/Get-TssSecretDependencyScript.ps1 create mode 100644 tests/secret-dependencies/Get-TssSecretDependencyScript.Tests.ps1 diff --git a/docs/commands/secret-dependencies/Get-TssSecretDependencyScript.md b/docs/commands/secret-dependencies/Get-TssSecretDependencyScript.md new file mode 100644 index 00000000..4d8a5c17 --- /dev/null +++ b/docs/commands/secret-dependencies/Get-TssSecretDependencyScript.md @@ -0,0 +1,58 @@ +# Get-TssSecretDependencyScript + +## SYNOPSIS +Get Scripts that are possible to use for Dependencies + +## SYNTAX + +``` +Get-TssSecretDependencyScript [-TssSession] [] +``` + +## DESCRIPTION +Get Scripts that are possible to use for Dependencies + +## EXAMPLES + +### EXAMPLE 1 +``` +$session = New-TssSession -SecretServer https://alpha -Credential $ssCred +Get-TssSecretDependencyScript -TssSession $session - some test value +``` + +Return Dependency scripts available for use + +## PARAMETERS + +### -TssSession +TssSession object created by New-TssSession for authentication + +```yaml +Type: Session +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +### Thycotic.PowerShell.SecretDependencies.Script +## NOTES +Requires TssSession object returned by New-TssSession + +## RELATED LINKS + +[https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-dependencies/Get-TssSecretDependencyScript](https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-dependencies/Get-TssSecretDependencyScript) + +[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-dependencies/Get-TssSecretDependencyScript.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-dependencies/Get-TssSecretDependencyScript.ps1) + diff --git a/src/Thycotic.SecretServer.Format.ps1xml b/src/Thycotic.SecretServer.Format.ps1xml index 4bcbed4c..a8650eb6 100644 --- a/src/Thycotic.SecretServer.Format.ps1xml +++ b/src/Thycotic.SecretServer.Format.ps1xml @@ -3081,5 +3081,39 @@ + + + SecretDependencies.Script + + Thycotic.PowerShell.SecretDependencies.Script + + + + + + + + + + + + + Id + + + Name + + + Arguments + + + OdbcConnectionArguments + + + + + + + diff --git a/src/Thycotic.SecretServer/classes/secret-dependencies/OdbcConnectionArgument.cs b/src/Thycotic.SecretServer/classes/secret-dependencies/OdbcConnectionArgument.cs new file mode 100644 index 00000000..68050897 --- /dev/null +++ b/src/Thycotic.SecretServer/classes/secret-dependencies/OdbcConnectionArgument.cs @@ -0,0 +1,13 @@ +using System; +using System.Threading.Tasks; +using System.Management.Automation; +using System.Management.Automation.Runspaces; + +namespace Thycotic.PowerShell.SecretDependencies +{ + public class OdbcConnectionArgument + { + public string Name { get; set; } + public string Value { get; set;} + } +} \ No newline at end of file diff --git a/src/Thycotic.SecretServer/classes/secret-dependencies/Script.cs b/src/Thycotic.SecretServer/classes/secret-dependencies/Script.cs new file mode 100644 index 00000000..f44b2a49 --- /dev/null +++ b/src/Thycotic.SecretServer/classes/secret-dependencies/Script.cs @@ -0,0 +1,15 @@ +using System; +using System.Threading.Tasks; +using System.Management.Automation; +using System.Management.Automation.Runspaces; + +namespace Thycotic.PowerShell.SecretDependencies +{ + public class Script + { + public ScriptArgument[] Arguments { get; set; } + public int Id { get; set; } + public string Name { get; set; } + public OdbcConnectionArgument[] OdbcConnectionArguments { get; set; } + } +} \ No newline at end of file diff --git a/src/Thycotic.SecretServer/classes/secret-dependencies/ScriptArgument.cs b/src/Thycotic.SecretServer/classes/secret-dependencies/ScriptArgument.cs new file mode 100644 index 00000000..2613090f --- /dev/null +++ b/src/Thycotic.SecretServer/classes/secret-dependencies/ScriptArgument.cs @@ -0,0 +1,14 @@ +using System; +using System.Threading.Tasks; +using System.Management.Automation; +using System.Management.Automation.Runspaces; + +namespace Thycotic.PowerShell.SecretDependencies +{ + public class ScriptArgument + { + public string Name { get; set; } + public string Type { get; set; } + public string Value { get; set; } + } +} \ No newline at end of file diff --git a/src/functions/secret-dependencies/Get-TssSecretDependencyScript.ps1 b/src/functions/secret-dependencies/Get-TssSecretDependencyScript.ps1 new file mode 100644 index 00000000..b3757021 --- /dev/null +++ b/src/functions/secret-dependencies/Get-TssSecretDependencyScript.ps1 @@ -0,0 +1,61 @@ +function Get-TssSecretDependencyScript { + <# + .SYNOPSIS + Get Scripts that are possible to use for Dependencies + + .DESCRIPTION + Get Scripts that are possible to use for Dependencies + + .EXAMPLE + $session = New-TssSession -SecretServer https://alpha -Credential $ssCred + Get-TssSecretDependencyScript -TssSession $session - some test value + + Return Dependency scripts available for use + + .LINK + https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-dependencies/Get-TssSecretDependencyScript + + .LINK + https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-dependencies/Get-TssSecretDependencyScript.ps1 + + .NOTES + Requires TssSession object returned by New-TssSession + #> + [CmdletBinding()] + [OutputType('Thycotic.PowerShell.SecretDependencies.Script')] + param ( + # TssSession object created by New-TssSession for authentication + [Parameter(Mandatory,ValueFromPipeline,Position = 0)] + [Thycotic.PowerShell.Authentication.Session] + $TssSession + ) + begin { + $tssParams = $PSBoundParameters + $invokeParams = . $GetInvokeApiParams $TssSession + } + process { + Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" + if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { + . $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation + $uri = $TssSession.ApiUrl, 'secret-dependencies', 'scripts' -join '/' + $invokeParams.Uri = $uri + $invokeParams.Method = 'GET' + + Write-Verbose "Performing the operation $($invokeParams.Method) $($invokeParams.Uri)" + try { + $apiResponse = Invoke-TssApi @invokeParams + $restResponse = . $ProcessResponse $apiResponse + } catch { + Write-Warning "Issue getting dependency scripts" + $err = $_ + . $ErrorHandling $err + } + + if ($restResponse.model) { + [Thycotic.PowerShell.SecretDependencies.Script[]]$restResponse.model + } + } else { + Write-Warning "No valid session found" + } + } +} \ No newline at end of file diff --git a/tests/secret-dependencies/Get-TssSecretDependencyScript.Tests.ps1 b/tests/secret-dependencies/Get-TssSecretDependencyScript.Tests.ps1 new file mode 100644 index 00000000..0d92c755 --- /dev/null +++ b/tests/secret-dependencies/Get-TssSecretDependencyScript.Tests.ps1 @@ -0,0 +1,24 @@ +BeforeDiscovery { + $commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf +} +Describe "$commandName verify parameters" { + BeforeDiscovery { + [object[]]$knownParameters = 'TssSession' + [object[]]$currentParams = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function')).Parameters.Keys + [object[]]$commandDetails = [System.Management.Automation.CommandInfo]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function') + $unknownParameters = Compare-Object -ReferenceObject $knownParameters -DifferenceObject $currentParams -PassThru + } + Context "Verify parameters" -Foreach @{currentParams = $currentParams } { + It "$commandName should contain <_> parameter" -TestCases $knownParameters { + $_ -in $currentParams | Should -Be $true + } + It "$commandName should not contain parameter: <_>" -TestCases $unknownParameters { + $_ | Should -BeNullOrEmpty + } + } + Context "Command specific details" { + It "$commandName should set OutputType to Thycotic.PowerShell.SecretDependencies.Script" -TestCases $commandDetails { + $_.OutputType.Name | Should -Be 'Thycotic.PowerShell.SecretDependencies.Script' + } + } +} \ No newline at end of file