Skip to content

Commit

Permalink
Moving code from constructor to separate method (#42)
Browse files Browse the repository at this point in the history
* Moving code from constructor to separate method

* Moving code from constructor to separate method

* Updated changelog
  • Loading branch information
raandree authored Sep 28, 2020
1 parent 6b99b18 commit 67b12a6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Moving code from constructor to separate method.

## [0.7.1] - 2020-08-26

- Renamed 'Test-DscParameterState' to 'Test-DscParameterState2' for a conflict with 'DscResource.Common'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,35 +143,13 @@ class JeaSessionConfiguration
[Dscproperty()]
[int] $HungRegistrationTimeout = 10

JeaSessionConfiguration()
{
if (-not $this.SessionType)
{
$this.SessionType = 'RestrictedRemoteServer'
}

if ($this.RunAsVirtualAccountGroups -and $this.GroupManagedServiceAccount)
{
throw $script:localizedData.ConflictRunAsVirtualAccountGroupsAndGroupManagedServiceAccount
}

if ($this.GroupManagedServiceAccount -and $this.RunAsVirtualAccount)
{
throw $script:localizedData.ConflictRunAsVirtualAccountAndGroupManagedServiceAccount
}

if (-not $this.GroupManagedServiceAccount)
{
$this.RunAsVirtualAccount = $true
Write-Warning "'GroupManagedServiceAccount' and 'RunAsVirtualAccount' are not defined, setting 'RunAsVirtualAccount' to 'true'."
}
}

[void] Set()
{
$ErrorActionPreference = 'Stop'

$psscPath = Join-Path ([IO.Path]::GetTempPath()) ([IO.Path]::GetRandomFileName() + ".pssc")
$this.TestParameters()

$psscPath = Join-Path ([IO.Path]::GetTempPath()) ([IO.Path]::GetRandomFileName() + '.pssc')
Write-Verbose "Storing PSSessionConfigurationFile in file '$psscPath'"
$desiredState = Convert-ObjectToHashtable -Object $this
$desiredState.Add('Path', $psscPath)
Expand All @@ -188,9 +166,9 @@ class JeaSessionConfiguration
try
{
## If we are replacing Microsoft.PowerShell, create a 'break the glass' endpoint
if ($this.Name -eq "Microsoft.PowerShell")
if ($this.Name -eq 'Microsoft.PowerShell')
{
$breakTheGlassName = "Microsoft.PowerShell.Restricted"
$breakTheGlassName = 'Microsoft.PowerShell.Restricted'
if (-not ($this.GetPSSessionConfiguration($breakTheGlassName)))
{
$this.RegisterPSSessionConfiguration($breakTheGlassName, $null, $this.HungRegistrationTimeout)
Expand Down Expand Up @@ -230,6 +208,8 @@ class JeaSessionConfiguration
# Tests if the resource is in the desired state.
[bool] Test()
{
$this.TestParameters()

$currentState = Convert-ObjectToHashtable -Object $this.Get()
$desiredState = Convert-ObjectToHashtable -Object $this

Expand Down Expand Up @@ -271,6 +251,32 @@ class JeaSessionConfiguration
return $compare
}

hidden [bool] TestParameters()
{
if (-not $this.SessionType)
{
$this.SessionType = 'RestrictedRemoteServer'
}

if ($this.RunAsVirtualAccountGroups -and $this.GroupManagedServiceAccount)
{
throw $script:localizedData.ConflictRunAsVirtualAccountGroupsAndGroupManagedServiceAccount
}

if ($this.GroupManagedServiceAccount -and $this.RunAsVirtualAccount)
{
throw $script:localizedData.ConflictRunAsVirtualAccountAndGroupManagedServiceAccount
}

if (-not $this.GroupManagedServiceAccount)
{
$this.RunAsVirtualAccount = $true
Write-Warning "'GroupManagedServiceAccount' and 'RunAsVirtualAccount' are not defined, setting 'RunAsVirtualAccount' to 'true'."
}

return $true
}

## Get a PS Session Configuration based on its name
hidden [object] GetPSSessionConfiguration($Name)
{
Expand Down

0 comments on commit 67b12a6

Please sign in to comment.