|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using System.Management.Automation.Language; |
| 8 | +using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic; |
| 9 | +#if !CORECLR |
| 10 | +using System.ComponentModel.Composition; |
| 11 | +#endif |
| 12 | +using System.Globalization; |
| 13 | + |
| 14 | +namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules |
| 15 | +{ |
| 16 | + /// <summary> |
| 17 | + /// AvoidUsingAllowUnencryptedAuthentication: Avoid sending credentials and secrets over unencrypted connections. |
| 18 | + /// </summary> |
| 19 | +#if !CORECLR |
| 20 | +[Export(typeof(IScriptRule))] |
| 21 | +#endif |
| 22 | + public class AvoidUsingAllowUnencryptedAuthentication : AvoidParameterGeneric |
| 23 | + { |
| 24 | + /// <summary> |
| 25 | + /// Condition on the cmdlet that must be satisfied for the error to be raised |
| 26 | + /// </summary> |
| 27 | + /// <param name="CmdAst"></param> |
| 28 | + /// <returns></returns> |
| 29 | + public override bool CommandCondition(CommandAst CmdAst) |
| 30 | + { |
| 31 | + return true; |
| 32 | + } |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Condition on the parameter that must be satisfied for the error to be raised. |
| 36 | + /// </summary> |
| 37 | + /// <param name="CmdAst"></param> |
| 38 | + /// <param name="CeAst"></param> |
| 39 | + /// <returns></returns> |
| 40 | + public override bool ParameterCondition(CommandAst CmdAst, CommandElementAst CeAst) |
| 41 | + { |
| 42 | + return CeAst is CommandParameterAst && String.Equals((CeAst as CommandParameterAst).ParameterName, "AllowUnencryptedAuthentication", StringComparison.OrdinalIgnoreCase); |
| 43 | + } |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// Retrieves the error message |
| 47 | + /// </summary> |
| 48 | + /// <param name="FileName"></param> |
| 49 | + /// <param name="CmdAst"></param> |
| 50 | + /// <returns></returns> |
| 51 | + public override string GetError(string fileName, CommandAst cmdAst) |
| 52 | + { |
| 53 | + return String.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingAllowUnencryptedAuthenticationError); |
| 54 | + } |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// GetName: Retrieves the name of this rule. |
| 58 | + /// </summary> |
| 59 | + /// <returns>The name of this rule</returns> |
| 60 | + public override string GetName() |
| 61 | + { |
| 62 | + return string.Format(CultureInfo.CurrentCulture, Strings.NameSpaceFormat, GetSourceName(), Strings.AvoidUsingAllowUnencryptedAuthenticationName); |
| 63 | + } |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// GetCommonName: Retrieves the common name of this rule. |
| 67 | + /// </summary> |
| 68 | + /// <returns>The common name of this rule</returns> |
| 69 | + public override string GetCommonName() |
| 70 | + { |
| 71 | + return string.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingAllowUnencryptedAuthenticationCommonName); |
| 72 | + } |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// GetDescription: Retrieves the description of this rule. |
| 76 | + /// </summary> |
| 77 | + /// <returns>The description of this rule</returns> |
| 78 | + public override string GetDescription() |
| 79 | + { |
| 80 | + return string.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingAllowUnencryptedAuthenticationDescription); |
| 81 | + } |
| 82 | + |
| 83 | + /// <summary> |
| 84 | + /// GetSourceType: Retrieves the type of the rule: builtin, managed or module. |
| 85 | + /// </summary> |
| 86 | + public override SourceType GetSourceType() |
| 87 | + { |
| 88 | + return SourceType.Builtin; |
| 89 | + } |
| 90 | + |
| 91 | + /// <summary> |
| 92 | + /// GetSeverity: Retrieves the severity of the rule: error, warning or information. |
| 93 | + /// </summary> |
| 94 | + /// <returns></returns> |
| 95 | + public override RuleSeverity GetSeverity() |
| 96 | + { |
| 97 | + return RuleSeverity.Warning; |
| 98 | + } |
| 99 | + |
| 100 | + /// <summary> |
| 101 | + /// DiagnosticSeverity: Retrieves the severity of the rule of type DiagnosticSeverity: error, warning or information. |
| 102 | + /// </summary> |
| 103 | + /// <returns></returns> |
| 104 | + public override DiagnosticSeverity GetDiagnosticSeverity() |
| 105 | + { |
| 106 | + return DiagnosticSeverity.Warning; |
| 107 | + } |
| 108 | + |
| 109 | + /// <summary> |
| 110 | + /// GetSourceName: Retrieves the module/assembly name the rule is from. |
| 111 | + /// </summary> |
| 112 | + public override string GetSourceName() |
| 113 | + { |
| 114 | + return string.Format(CultureInfo.CurrentCulture, Strings.SourceName); |
| 115 | + } |
| 116 | + } |
| 117 | +} |
0 commit comments