You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ensures that all properties within a template named adminPassword are expressions, not literal strings
6
+
#>
7
+
param(
8
+
[Parameter(Mandatory=$true)]
9
+
[PSObject]
10
+
$TemplateObject
11
+
)
12
+
13
+
# Find all references to an adminPassword
14
+
# Filtering the complete $TemplateObject directly fails with "The script failed due to call depth overflow." errors
15
+
functionCheck-PasswordsInTemplate {
16
+
param (
17
+
[Parameter(Mandatory=$true)]
18
+
[PSObject]
19
+
$TemplateObject,
20
+
[Parameter(Mandatory=$true)]
21
+
[string]
22
+
$AdminPwd
23
+
)
24
+
if ("resources"-in$TemplateObject.PSobject.Properties.Name) {
25
+
$adminPwdRefsResources=$TemplateObject.resources|
26
+
Find-JsonContent-Key $AdminPwd-Value *-Like
27
+
28
+
foreach ($refin$adminPwdRefsResources) {
29
+
# Walk over each one
30
+
# if the property is not a string, then it's likely a param value for a nested deployment, and we should skip it.
31
+
$a=$ref.$AdminPwd
32
+
if ($a-isnot [string]) {
33
+
#check to see if this is a param value on a nested deployment - it will have a value property
34
+
if ($a.value-is [string]) {
35
+
$trimmedPwd="$($a.value)".Trim()
36
+
}
37
+
else {
38
+
continue# since we don't know what object shape we're testing at this point (could be a param declaration on a nested deployment)
39
+
}
40
+
}
41
+
else {
42
+
$trimmedPwd="$($a)".Trim()
43
+
}
44
+
if ($trimmedPwd-notmatch'\[[^\]]+\]') {
45
+
# If they aren't expressions
46
+
Write-Error-TargetObject $ref-Message "AdminPassword `"$trimmedPwd`" is not an expression"-ErrorId AdminPassword.Is.Literal # write an error
47
+
continue# and move onto the next
48
+
}
49
+
}
50
+
}
51
+
52
+
if ("variables"-in$TemplateObject.PSobject.Properties.Name) {
53
+
$adminPwdRefsVariables=$TemplateObject.variables|
54
+
Find-JsonContent-Key $AdminPwd-Value *-Like
55
+
56
+
foreach ($refin$adminPwdRefsVariables) {
57
+
# Walk over each one
58
+
# if the property is not a string, then it's likely a param value for a nested deployment, and we should skip it.
59
+
if ($ref.$AdminPwd-isnot [string]) { continue }
60
+
$trimmedPwd="$($ref.$AdminPwd)".Trim()
61
+
if ($trimmedPwd-notmatch'\[[^\]]+\]') {
62
+
# If they aren't expressions
63
+
Write-Error-TargetObject $ref-Message "AdminPassword `"$trimmedPwd`" is variable which is not an expression"-ErrorId AdminPassword.Var.Is.Literal # write an error
64
+
continue# and move onto the next
65
+
}
66
+
}
67
+
68
+
# TODO - irregular doesn't handle null gracefully so we need to test for it
Write-Error"AdminPassword references variable '$($PwdHasVariable.variableName)', which has a literal value. "-ErrorId AdminPassword.Is.Variable.Literal # write an error
# if the property is not a string, then it's likely a param value for a nested deployment, and we should skip it.
51
-
if ($ref.adminUserName-isnot [string]) { continue }
52
-
$trimmedUserName="$($ref.adminUserName)".Trim()
53
-
if ($trimmedUserName-notmatch'\[[^\]]+\]') {
54
-
# If they aren't expressions
55
-
Write-Error-TargetObject $ref-Message "AdminUsername `"$trimmedUserName`" is variable which is not an expression"-ErrorId AdminUsername.Var.Is.Literal # write an error
56
-
continue# and move onto the next
51
+
52
+
if ("variables"-in$TemplateObject.PSobject.Properties.Name) {
# if the property is not a string, then it's likely a param value for a nested deployment, and we should skip it.
59
+
if ($ref.$AdminUsername-isnot [string]) { continue }
60
+
$trimmedUserName="$($ref.$AdminUsername)".Trim()
61
+
if ($trimmedUserName-notmatch'\[[^\]]+\]') {
62
+
# If they aren't expressions
63
+
Write-Error-TargetObject $ref-Message "AdminUsername `"$trimmedUserName`" is variable which is not an expression"-ErrorId AdminUsername.Var.Is.Literal # write an error
64
+
continue# and move onto the next
65
+
}
57
66
}
58
-
}
59
-
60
-
# TODO - irregular doesn't handle null gracefully so we need to test for it
Write-Error"AdminUsername references variable '$($UserNameHasVariable.variableName)', which has a literal value. "-ErrorId AdminUserName.Is.Variable.Literal # write an error
0 commit comments