From 05db5d6809e4b73c7014750505b8862ac11a41d0 Mon Sep 17 00:00:00 2001 From: Shawn Melton <11204251+wsmelton@users.noreply.github.com> Date: Wed, 13 Oct 2021 09:49:59 -0500 Subject: [PATCH] New-TssDistributedEngineSiteConnector - new command to create a Site Connector --- .../New-TssDistributedEngineSiteConnector.md | 196 ++++++++++++++++++ .../New-TssDistributedEngineSiteConnector.ps1 | 113 ++++++++++ ...ssDistributedEngineSiteConnector.Tests.ps1 | 25 +++ 3 files changed, 334 insertions(+) create mode 100644 docs/commands/distributed-engines/New-TssDistributedEngineSiteConnector.md create mode 100644 src/functions/distributed-engines/New-TssDistributedEngineSiteConnector.ps1 create mode 100644 tests/distributed-engines/New-TssDistributedEngineSiteConnector.Tests.ps1 diff --git a/docs/commands/distributed-engines/New-TssDistributedEngineSiteConnector.md b/docs/commands/distributed-engines/New-TssDistributedEngineSiteConnector.md new file mode 100644 index 00000000..22744b9b --- /dev/null +++ b/docs/commands/distributed-engines/New-TssDistributedEngineSiteConnector.md @@ -0,0 +1,196 @@ +# New-TssDistributedEngineSiteConnector + +## SYNOPSIS +Create a new Site Connector + +## SYNTAX + +``` +New-TssDistributedEngineSiteConnector [-TssSession] [-TransportType ] [-Port ] + -Name -Hostname [-Disable] [-UseSsl] [-SslThumbprint ] [-WhatIf] [-Confirm] + [] +``` + +## DESCRIPTION +Create a new Site Connector + +## EXAMPLES + +### EXAMPLE 1 +``` +$session = New-TssSession -SecretServer https://alpha -Credential $ssCred +New-TssDistributedEngineSiteConnector -TssSession $session -Name 'New Site Connector 1' +``` + +Add minimum example for each parameter + +## 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 +``` + +### -TransportType +Service Bus Transport Type (allowed: MemoryMq, RabbitMq) + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Port +Service Bus Transport Port + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Name +Site Connector Name + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Hostname +Hostname + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Disable +Do not activate on creation + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UseSsl +Use SSL + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SslThumbprint +SSL Certificate Thumbprint + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +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.DistributedEngine.SiteConnector +## NOTES +Requires TssSession object returned by New-TssSession + +## RELATED LINKS + +[https://thycotic-ps.github.io/thycotic.secretserver/commands/distributed-engines/New-TssDistributedEngineSiteConnector](https://thycotic-ps.github.io/thycotic.secretserver/commands/distributed-engines/New-TssDistributedEngineSiteConnector) + +[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/distributed-engines/New-TssDistributedEngineSiteConnector.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/distributed-engines/New-TssDistributedEngineSiteConnector.ps1) + diff --git a/src/functions/distributed-engines/New-TssDistributedEngineSiteConnector.ps1 b/src/functions/distributed-engines/New-TssDistributedEngineSiteConnector.ps1 new file mode 100644 index 00000000..73774296 --- /dev/null +++ b/src/functions/distributed-engines/New-TssDistributedEngineSiteConnector.ps1 @@ -0,0 +1,113 @@ +function New-TssDistributedEngineSiteConnector { + <# + .SYNOPSIS + Create a new Site Connector + + .DESCRIPTION + Create a new Site Connector + + .LINK + https://thycotic-ps.github.io/thycotic.secretserver/commands/distributed-engines/New-TssDistributedEngineSiteConnector + + .LINK + https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/distributed-engines/New-TssDistributedEngineSiteConnector.ps1 + + .EXAMPLE + $session = New-TssSession -SecretServer https://alpha -Credential $ssCred + New-TssDistributedEngineSiteConnector -TssSession $session -Name 'New Site Connector 1' + + Add minimum example for each parameter + + .NOTES + Requires TssSession object returned by New-TssSession + #> + [CmdletBinding(SupportsShouldProcess)] + [OutputType('Thycotic.PowerShell.DistributedEngine.SiteConnector')] + param ( + # TssSession object created by New-TssSession for authentication + [Parameter(Mandatory,ValueFromPipeline,Position = 0)] + [Thycotic.PowerShell.Authentication.Session] + $TssSession, + + # Service Bus Transport Type (allowed: MemoryMq, RabbitMq) + [ValidateSet('MemoryMq','RabbitMq')] + [string] + $TransportType, + + # Service Bus Transport Port + [int] + $Port, + + # Site Connector Name + [Parameter(Mandatory)] + [string] + $Name, + + # Hostname + [Parameter(Mandatory)] + [string] + $Hostname, + + # Do not activate on creation + [switch] + $Disable, + + # Use SSL + [switch] + $UseSsl, + + # SSL Certificate Thumbprint + [string] + $SslThumbprint + ) + begin { + $tssNewParams = $PSBoundParameters + $invokeParams = . $GetInvokeApiParams $TssSession + } + process { + Get-TssInvocation $PSCmdlet.MyInvocation + if ($tssNewParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { + Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation + $restResponse = $null + $uri = $TssSession.ApiUrl, 'distributed-engine', 'site-connector' -join '/' + $invokeParams.Uri = $uri + $invokeParams.Method = 'POST' + + $newBody = @{data = @{}} + switch ($tssNewParams.Keys) { + 'TransportType' { $newBody.data.Add('queueType',$TransportType)} + 'Port' {$newBody.data.Add('port',$Port)} + 'Name' {$newBody.data.Add('siteConnectorName',$Name)} + 'Hostname' {$newBody.data.Add('hostName',$Hostname)} + 'Disable' {$newBody.data.Add('active',$false)} + 'UseSsl' { + if ($tssNewParams.ContainsKey('SslThumbprint')) { + $newBody.data.Add('useSsl',$UseSsl) + $newBody.data.Add('sslCertificateThumbprint') + } else { + Write-Warning "SslThumbprint must be provided when using SSL" + return + } + } + } + $invokeParams.Body = ($newBody | ConvertTo-Json) + + Write-Verbose "Performing the operation $($invokeParams.Method) $($invokeParams.Uri) with:`n $newBody" + if (-not $PSCmdlet.ShouldProcess("Reference $Name", "$($invokeParams.Method) $($invokeParams.Uri) with $($invokeParams.Body)")) { return } + try { + $apiResponse = Invoke-TssApi @invokeParams + $restResponse = . $ProcessResponse $apiResponse + } catch { + Write-Warning "Issue creating Reference [Name]" + $err = $_ + . $ErrorHandling $err + } + + if ($restResponse) { + . $GetSiteConnector $restResponse + } + } else { + Write-Warning "No valid session found" + } + } +} \ No newline at end of file diff --git a/tests/distributed-engines/New-TssDistributedEngineSiteConnector.Tests.ps1 b/tests/distributed-engines/New-TssDistributedEngineSiteConnector.Tests.ps1 new file mode 100644 index 00000000..c3941f93 --- /dev/null +++ b/tests/distributed-engines/New-TssDistributedEngineSiteConnector.Tests.ps1 @@ -0,0 +1,25 @@ +BeforeDiscovery { + $commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf +} +Describe "$commandName verify parameters" { + BeforeDiscovery { + [object[]]$knownParameters = 'TssSession','TransportType','Port','Name','Hostname','Disable','UseSsl','SslThumbprint' + + [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.DistributedEngines.SiteConnector" -TestCases $commandDetails { + $_.OutputType.Name | Should -Be 'Thycotic.PowerShell.DistributedEngines.SiteConnector' + } + } +} \ No newline at end of file