Skip to content

Commit

Permalink
New-TssDistributedEngineSiteConnector - new command to create a Site …
Browse files Browse the repository at this point in the history
…Connector
  • Loading branch information
wsmelton committed Oct 13, 2021
1 parent de7f664 commit 05db5d6
Show file tree
Hide file tree
Showing 3 changed files with 334 additions and 0 deletions.
@@ -0,0 +1,196 @@
# New-TssDistributedEngineSiteConnector

## SYNOPSIS
Create a new Site Connector

## SYNTAX

```
New-TssDistributedEngineSiteConnector [-TssSession] <Session> [-TransportType <String>] [-Port <Int32>]
-Name <String> -Hostname <String> [-Disable] [-UseSsl] [-SslThumbprint <String>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```

## 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)

@@ -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"
}
}
}
@@ -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'
}
}
}

0 comments on commit 05db5d6

Please sign in to comment.