Skip to content

Commit

Permalink
Register-TssDistributedEngine - new command to activate a DE for a Site
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Oct 13, 2021
1 parent a48e482 commit 0c9334b
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 0 deletions.
120 changes: 120 additions & 0 deletions docs/commands/distributed-engines/Register-TssDistributedEngine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Register-TssDistributedEngine

## SYNOPSIS
Activate a Distributed Engine for a Site

## SYNTAX

```
Register-TssDistributedEngine [-TssSession] <Session> -Id <Int32[]> -SiteId <Int32> [-WhatIf] [-Confirm]
[<CommonParameters>]
```

## DESCRIPTION
Activate a Distributed Engine for a Site

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Register-TssDistributedEngine -TssSession $session -EngineId 6 -SiteId 5
```

Activate Engine ID 6 on Site ID 5

## 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
```
### -Id
Engine ID
```yaml
Type: Int32[]
Parameter Sets: (All)
Aliases: EngineId

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -SiteId
Site ID
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: 0
Accept pipeline input: True (ByPropertyName)
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.DistributedEngines.EngineActivation
## NOTES
Requires TssSession object returned by New-TssSession
## RELATED LINKS
[https://thycotic-ps.github.io/thycotic.secretserver/commands/distributed-engines/Register-TssDistributedEngine](https://thycotic-ps.github.io/thycotic.secretserver/commands/distributed-engines/Register-TssDistributedEngine)
[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/distributed-engines/Register-TssDistributedEngine.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/distributed-engines/Register-TssDistributedEngine.ps1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace Thycotic.PowerShell.DistributedEngines
{
public class EngineActivation
{
public int EngineId { get; set; }
public string EngineName { get; set; }
public string Error { get; set; }
public bool IsSuccessful { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
function Register-TssDistributedEngine {
<#
.SYNOPSIS
Activate a Distributed Engine for a Site
.DESCRIPTION
Activate a Distributed Engine for a Site
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Register-TssDistributedEngine -TssSession $session -EngineId 6 -SiteId 5
Activate Engine ID 6 on Site ID 5
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/distributed-engines/Register-TssDistributedEngine
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/distributed-engines/Register-TssDistributedEngine.ps1
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding(SupportsShouldProcess)]
[OutputType('Thycotic.PowerShell.DistributedEngines.EngineActivation')]
param (
# TssSession object created by New-TssSession for authentication
[Parameter(Mandatory, ValueFromPipeline, Position = 0)]
[Thycotic.PowerShell.Authentication.Session]
$TssSession,

# Engine ID
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[Alias('EngineId')]
[int[]]
$Id,

# Site ID
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[int]
$SiteId
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeApiParams $TssSession
}
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'distributed-engine', 'update-engine-status' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'POST'

$registerBody = @{data = @{} }
$allEngines = @()
foreach ($engine in $Id) {
$cEngine = @{}
$cEngine.Add('changeType','Activate')
$cEngine.Add('engineId',$engine)
$cEngine.Add('siteId',$SiteId)
$allEngines += $cEngine
}
$registerBody.data.Add('engines',$allEngines)

$invokeParams.Body = $registerBody | ConvertTo-Json -Depth 100
if ($PSCmdlet.ShouldProcess("description: $", "$($invokeParams.Method) $uri with: `n$($invokeParams.Body)")) {
Write-Verbose "$($invokeParams.Method) $uri with: `n$($invokeParams.Body)"
try {
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning 'Issue warning message'
$err = $_
. $ErrorHandling $err
}

if ($restResponse.results) {
foreach ($record in $restResponse.results) {
[Thycotic.PowerShell.DistributedEngines.EngineActivation]@{
EngineId = $record.engineId
EngineName = $record.engineName
Error = $record.error
IsSuccessful = $record.success
}
}

}
}
} else {
Write-Warning 'No valid session found'
}
}
}
24 changes: 24 additions & 0 deletions tests/distributed-engines/Register-TssDistributedEngine.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'Id', 'SiteId'
[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.EngineActivation" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.DistributedEngines.EngineActivation'
}
}
}

0 comments on commit 0c9334b

Please sign in to comment.