Skip to content

Commit

Permalink
feat(dgw): add [Get|Set|Reset]-DGatewayConfigPath cmdlets (#572)
Browse files Browse the repository at this point in the history
Issue: DGW-113
  • Loading branch information
awakecoding authored Oct 18, 2023
1 parent efe8019 commit d162015
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
4 changes: 3 additions & 1 deletion powershell/DevolutionsGateway/DevolutionsGateway.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@
'Set-DGatewayHostname', 'Get-DGatewayHostname',
'New-DGatewayListener', 'Get-DGatewayListeners', 'Set-DGatewayListeners',
'Set-DGatewayApplicationProtocols', 'Get-DGatewayApplicationProtocols',
'Get-DGatewayPath', 'Import-DGatewayCertificate',
'Get-DGatewayPath', 'Get-DGatewayRecordingPath',
'Set-DGatewayRecordingPath', 'Reset-DGatewayRecordingPath',
'Import-DGatewayCertificate',
'New-DGatewayProvisionerKeyPair', 'Import-DGatewayProvisionerKey',
'New-DGatewayDelegationKeyPair', 'Import-DGatewayDelegationKey',
'New-DGatewayToken',
Expand Down
44 changes: 44 additions & 0 deletions powershell/DevolutionsGateway/Public/DGateway.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ class DGatewayConfig {
[string] $FarmName
[string[]] $FarmMembers

[string] $RecordingPath

[string] $TlsCertificateFile
[string] $TlsPrivateKeyFile
[string] $ProvisionerPublicKeyFile
Expand Down Expand Up @@ -429,6 +431,48 @@ function Get-DGatewayPath() {
}
}

function Get-DGatewayRecordingPath {
[CmdletBinding()]
param(
[string] $ConfigPath
)

$ConfigPath = Find-DGatewayConfig -ConfigPath:$ConfigPath
$Config = Get-DGatewayConfig -ConfigPath:$ConfigPath -NullProperties

$RecordingPath = $Config.RecordingPath

if ([string]::IsNullOrEmpty($RecordingPath)) {
$RecordingPath = Join-Path $ConfigPath "recordings"
}

$RecordingPath
}

function Set-DGatewayRecordingPath {
[CmdletBinding()]
param(
[string] $ConfigPath,
[Parameter(Mandatory = $true, Position = 0)]
[string] $RecordingPath
)

$Config = Get-DGatewayConfig -ConfigPath:$ConfigPath -NullProperties
$Config.RecordingPath = $RecordingPath
Save-DGatewayConfig -ConfigPath:$ConfigPath -Config:$Config
}

function Reset-DGatewayRecordingPath {
[CmdletBinding()]
param(
[string] $ConfigPath
)

$Config = Get-DGatewayConfig -ConfigPath:$ConfigPath -NullProperties
$Config.RecordingPath = $null
Save-DGatewayConfig -ConfigPath:$ConfigPath -Config:$Config
}

function Get-DGatewayFarmName {
[CmdletBinding()]
param(
Expand Down
9 changes: 9 additions & 0 deletions powershell/pester/Config.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ Describe 'Devolutions Gateway config' {
$ActualListeners = Get-DGatewayListeners -ConfigPath:$ConfigPath
$ExpectedListeners.Count | Should -Be $ActualListeners.Count
}

It 'Sets gateway recording path' {
$RecordingPath = "C:\Users\Public\Gateway\Recordings"
$DefaultRecordingPath = Join-Path $ConfigPath "recordings"
Set-DGatewayRecordingPath -ConfigPath:$ConfigPath $RecordingPath
$(Get-DGatewayRecordingPath -ConfigPath:$ConfigPath) | Should -Be $RecordingPath
Reset-DGatewayRecordingPath -ConfigPath:$ConfigPath
$(Get-DGatewayRecordingPath -ConfigPath:$ConfigPath) | Should -Be $DefaultRecordingPath
}
}
}
}

0 comments on commit d162015

Please sign in to comment.