1
- // Copyright (c) Microsoft Corporation.
1
+ // Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
4
using System ;
@@ -52,8 +52,9 @@ private TemplateAnalyzer(JsonRuleEngine jsonRuleEngine, PowerShellRuleEngine pow
52
52
/// <param name="includeNonSecurityRules">Whether or not to run also non-security rules against the template.</param>
53
53
/// <param name="logger">A logger to report errors and debug information</param>
54
54
/// <param name="customJsonRulesPath">An optional custom rules json file path.</param>
55
+ /// <param name="includePowerShellRules">Whether or not to run also powershell rules against the template.</param>
55
56
/// <returns>A new <see cref="TemplateAnalyzer"/> instance.</returns>
56
- public static TemplateAnalyzer Create ( bool includeNonSecurityRules , ILogger logger = null , FileInfo customJsonRulesPath = null )
57
+ public static TemplateAnalyzer Create ( bool includeNonSecurityRules , ILogger logger = null , FileInfo customJsonRulesPath = null , bool includePowerShellRules = true )
57
58
{
58
59
string rules ;
59
60
try
@@ -72,7 +73,7 @@ public static TemplateAnalyzer Create(bool includeNonSecurityRules, ILogger logg
72
73
? new BicepSourceLocationResolver ( templateContext )
73
74
: new JsonSourceLocationResolver ( templateContext ) ,
74
75
logger ) ,
75
- new PowerShellRuleEngine ( includeNonSecurityRules , logger ) ,
76
+ includePowerShellRules ? new PowerShellRuleEngine ( includeNonSecurityRules , logger ) : null ,
76
77
logger ) ;
77
78
}
78
79
@@ -158,7 +159,11 @@ private IEnumerable<IEvaluation> AnalyzeAllIncludedTemplates(string populatedTem
158
159
try
159
160
{
160
161
IEnumerable < IEvaluation > evaluations = this . jsonRuleEngine . AnalyzeTemplate ( templateContext ) ;
161
- evaluations = evaluations . Concat ( this . powerShellRuleEngine . AnalyzeTemplate ( templateContext ) ) ;
162
+
163
+ if ( this . powerShellRuleEngine is not null )
164
+ {
165
+ evaluations = evaluations . Concat ( this . powerShellRuleEngine . AnalyzeTemplate ( templateContext ) ) ;
166
+ }
162
167
163
168
// Recursively handle nested templates
164
169
var jsonTemplate = JObject . Parse ( populatedTemplate ) ;
@@ -187,7 +192,7 @@ private IEnumerable<IEvaluation> AnalyzeAllIncludedTemplates(string populatedTem
187
192
// Variables, parameters and functions inherited from parent template
188
193
string functionsKey = populatedNestedTemplate . InsensitiveToken ( "functions" ) ? . Parent . Path ?? "functions" ;
189
194
string variablesKey = populatedNestedTemplate . InsensitiveToken ( "variables" ) ? . Parent . Path ?? "variables" ;
190
- string parametersKey = populatedNestedTemplate . InsensitiveToken ( "parameters" ) ? . Parent . Path ?? "parameters" ;
195
+ string parametersKey = populatedNestedTemplate . InsensitiveToken ( "parameters" ) ? . Parent . Path ?? "parameters" ;
191
196
192
197
populatedNestedTemplate [ functionsKey ] = jsonTemplate . InsensitiveToken ( "functions" ) ;
193
198
populatedNestedTemplate [ variablesKey ] = jsonTemplate . InsensitiveToken ( "variables" ) ;
0 commit comments