Skip to content

Commit

Permalink
Implement changes recommended in PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
RWebster-Noble committed Jun 28, 2024
1 parent 0629e90 commit 8817be5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function Get-TargetResource
$PhysicalPath,

[Parameter()]
[pscredential]
[System.Management.Automation.PSCredential]
$Credential
)

Expand All @@ -57,19 +57,18 @@ function Get-TargetResource
$PhysicalPath = $virtualDirectory.PhysicalPath
$Ensure = 'Present'

if ($WebApplication.Length -gt 0)
if ([System.String]::IsNullOrEmpty($WebApplication))
{
$ItemPath = "IIS:Sites\$Website\$WebApplication\$Name"
$itemPath = "IIS:Sites\$Website\$Name"
}
else
{
$ItemPath = "IIS:Sites\$Website\$Name"
$itemPath = "IIS:Sites\$Website\$WebApplication\$Name"
}

$userName = (Get-ItemProperty $ItemPath -Name userName).Value
if ($userName -ne '')
$userName = (Get-ItemProperty $itemPath -Name UserName).Value
if (-not [System.String]::IsNullOrEmpty($userName))
{
#$password = (Get-ItemProperty $ItemPath -Name password).Value
$password = New-Object System.Security.SecureString # Blank Password
$secStringPassword = $password | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($userName, $secStringPassword)
Expand Down Expand Up @@ -122,7 +121,7 @@ function Set-TargetResource
$PhysicalPath,

[Parameter()]
[pscredential]
[System.Management.Automation.PSCredential]
$Credential
)

Expand All @@ -143,13 +142,13 @@ function Set-TargetResource
$WebApplication = ''
}

if ($WebApplication.Length -gt 0)
if ([System.String]::IsNullOrEmpty($WebApplication))
{
$ItemPath = "IIS:Sites\$Website\$WebApplication\$Name"
$itemPath = "IIS:Sites\$Website\$Name"
}
else
{
$ItemPath = "IIS:Sites\$Website\$Name"
$itemPath = "IIS:Sites\$Website\$WebApplication\$Name"
}

$virtualDirectory = Get-WebVirtualDirectory -Site $Website `
Expand Down Expand Up @@ -182,15 +181,17 @@ function Set-TargetResource
{
Write-Verbose -Message ($script:localizedData.VerboseSetTargetPhysicalPath -f $Name)

Set-ItemProperty -Path $ItemPath `
Set-ItemProperty -Path $itemPath `
-Name physicalPath `
-Value $PhysicalPath
}

if ($Credential)
{
Set-ItemProperty $ItemPath -Name userName -Value $Credential.UserName
Set-ItemProperty $ItemPath -Name password -Value $Credential.GetNetworkCredential().Password
Write-Verbose -Message ($script:localizedData.VerboseSetTargetCredential -f $Name)

Set-ItemProperty $itemPath -Name UserName -Value $Credential.UserName
Set-ItemProperty $itemPath -Name Password -Value $Credential.GetNetworkCredential().Password
}
}

Expand Down Expand Up @@ -249,7 +250,7 @@ function Test-TargetResource
$PhysicalPath,

[Parameter()]
[pscredential]
[System.Management.Automation.PSCredential]
$Credential
)

Expand All @@ -269,17 +270,17 @@ function Test-TargetResource
return $true
}

if ($WebApplication.Length -gt 0)
if ([System.String]::IsNullOrEmpty($WebApplication))
{
$ItemPath = "IIS:Sites\$Website\$WebApplication\$Name"
$itemPath = "IIS:Sites\$Website\$Name"
}
else
{
$ItemPath = "IIS:Sites\$Website\$Name"
$itemPath = "IIS:Sites\$Website\$WebApplication\$Name"
}

$userName = (Get-ItemProperty $ItemPath -Name userName).Value
$password = (Get-ItemProperty $ItemPath -Name password).Value
$userName = (Get-ItemProperty $itemPath -Name UserName).Value
$password = (Get-ItemProperty $itemPath -Name Password).Value

if (($Credential.UserName -eq $userName -and $Credential.GetNetworkCredential().Password -eq $password))
{
Expand All @@ -288,13 +289,13 @@ function Test-TargetResource
}
else
{
Write-Verbose -Message ($script:localizedData.VerboseTestTargetFalse -f $PhysicalPath, $Name)
Write-Verbose -Message ($script:localizedData.VerboseTestTargetCredentialFalse -f $PhysicalPath, $Name)
return $false
}
}
else
{
Write-Verbose -Message ($script:localizedData.VerboseTestTargetFalse -f $PhysicalPath, $Name)
Write-Verbose -Message ($script:localizedData.VerboseTestTargetPhysicalPathFalse -f $Credential.UserName, $Name)
return $false
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# culture ="en-US"
ConvertFrom-StringData -StringData @'
VerboseGetTargetResource = Get-TargetResource has been run.
VerboseSetTargetPhysicalPath = Updating PhysicalPath and Credential for Web Virtual Directory '{0}'.
VerboseSetTargetPhysicalPath = Updating PhysicalPath for Web Virtual Directory '{0}'.
VerboseSetTargetCredential = Updating Credential for Web Virtual Directory '{0}'.
VerboseSetTargetCreateVirtualDirectory = Creating new Web Virtual Directory '{0}'.
VerboseSetTargetRemoveVirtualDirectory = Removing existing Virtual Directory '{0}'.
VerboseTestTargetFalse = Physical path '{0}' and Credential for Web Virtual Directory '{1}' is not in desired state.
VerboseTestTargetPhysicalPathFalse = Physical path '{0}' for Web Virtual Directory '{1}' is not in desired state.
VerboseTestTargetCredentialFalse = Credential {0} for Web Virtual Directory '{1}' is not in desired state.
VerboseTestTargetTrue = Web Virtual Directory is in desired state.
VerboseTestTargetAbsentTrue = Web Virtual Directory '{0}' should be Absent and is Absent.
'@

0 comments on commit 8817be5

Please sign in to comment.