Skip to content

Commit 67b12a6

Browse files
authored
Moving code from constructor to separate method (#42)
* Moving code from constructor to separate method * Moving code from constructor to separate method * Updated changelog
1 parent 6b99b18 commit 67b12a6

File tree

2 files changed

+37
-27
lines changed

2 files changed

+37
-27
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## [Unreleased]
77

8+
### Changed
9+
10+
- Moving code from constructor to separate method.
11+
812
## [0.7.1] - 2020-08-26
913

1014
- Renamed 'Test-DscParameterState' to 'Test-DscParameterState2' for a conflict with 'DscResource.Common'.

source/DSCClassResources/JeaSessionConfiguration/JeaSessionConfiguration.psm1

+33-27
Original file line numberDiff line numberDiff line change
@@ -143,35 +143,13 @@ class JeaSessionConfiguration
143143
[Dscproperty()]
144144
[int] $HungRegistrationTimeout = 10
145145

146-
JeaSessionConfiguration()
147-
{
148-
if (-not $this.SessionType)
149-
{
150-
$this.SessionType = 'RestrictedRemoteServer'
151-
}
152-
153-
if ($this.RunAsVirtualAccountGroups -and $this.GroupManagedServiceAccount)
154-
{
155-
throw $script:localizedData.ConflictRunAsVirtualAccountGroupsAndGroupManagedServiceAccount
156-
}
157-
158-
if ($this.GroupManagedServiceAccount -and $this.RunAsVirtualAccount)
159-
{
160-
throw $script:localizedData.ConflictRunAsVirtualAccountAndGroupManagedServiceAccount
161-
}
162-
163-
if (-not $this.GroupManagedServiceAccount)
164-
{
165-
$this.RunAsVirtualAccount = $true
166-
Write-Warning "'GroupManagedServiceAccount' and 'RunAsVirtualAccount' are not defined, setting 'RunAsVirtualAccount' to 'true'."
167-
}
168-
}
169-
170146
[void] Set()
171147
{
172148
$ErrorActionPreference = 'Stop'
173149

174-
$psscPath = Join-Path ([IO.Path]::GetTempPath()) ([IO.Path]::GetRandomFileName() + ".pssc")
150+
$this.TestParameters()
151+
152+
$psscPath = Join-Path ([IO.Path]::GetTempPath()) ([IO.Path]::GetRandomFileName() + '.pssc')
175153
Write-Verbose "Storing PSSessionConfigurationFile in file '$psscPath'"
176154
$desiredState = Convert-ObjectToHashtable -Object $this
177155
$desiredState.Add('Path', $psscPath)
@@ -188,9 +166,9 @@ class JeaSessionConfiguration
188166
try
189167
{
190168
## If we are replacing Microsoft.PowerShell, create a 'break the glass' endpoint
191-
if ($this.Name -eq "Microsoft.PowerShell")
169+
if ($this.Name -eq 'Microsoft.PowerShell')
192170
{
193-
$breakTheGlassName = "Microsoft.PowerShell.Restricted"
171+
$breakTheGlassName = 'Microsoft.PowerShell.Restricted'
194172
if (-not ($this.GetPSSessionConfiguration($breakTheGlassName)))
195173
{
196174
$this.RegisterPSSessionConfiguration($breakTheGlassName, $null, $this.HungRegistrationTimeout)
@@ -230,6 +208,8 @@ class JeaSessionConfiguration
230208
# Tests if the resource is in the desired state.
231209
[bool] Test()
232210
{
211+
$this.TestParameters()
212+
233213
$currentState = Convert-ObjectToHashtable -Object $this.Get()
234214
$desiredState = Convert-ObjectToHashtable -Object $this
235215

@@ -271,6 +251,32 @@ class JeaSessionConfiguration
271251
return $compare
272252
}
273253

254+
hidden [bool] TestParameters()
255+
{
256+
if (-not $this.SessionType)
257+
{
258+
$this.SessionType = 'RestrictedRemoteServer'
259+
}
260+
261+
if ($this.RunAsVirtualAccountGroups -and $this.GroupManagedServiceAccount)
262+
{
263+
throw $script:localizedData.ConflictRunAsVirtualAccountGroupsAndGroupManagedServiceAccount
264+
}
265+
266+
if ($this.GroupManagedServiceAccount -and $this.RunAsVirtualAccount)
267+
{
268+
throw $script:localizedData.ConflictRunAsVirtualAccountAndGroupManagedServiceAccount
269+
}
270+
271+
if (-not $this.GroupManagedServiceAccount)
272+
{
273+
$this.RunAsVirtualAccount = $true
274+
Write-Warning "'GroupManagedServiceAccount' and 'RunAsVirtualAccount' are not defined, setting 'RunAsVirtualAccount' to 'true'."
275+
}
276+
277+
return $true
278+
}
279+
274280
## Get a PS Session Configuration based on its name
275281
hidden [object] GetPSSessionConfiguration($Name)
276282
{

0 commit comments

Comments
 (0)