Skip to content

Commit ad5da48

Browse files
committed
DDM ruleId validation
1 parent d893608 commit ad5da48

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/ResourceManager/Sql/Commands.Sql/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Sql/Commands.Sql/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,7 @@
231231
<data name="DeprecatedCmdletUsageWarning" xml:space="preserve">
232232
<value>The {0} cmdlet is deprecated and will be removed in a future release.</value>
233233
</data>
234+
<data name="NewDataMaskingRuleIdIsNotValid" xml:space="preserve">
235+
<value>Rule Id cannot contain '&lt;,&gt;,+,=,#,*,%,&amp;,\,/,?' and cannot end with a '.'</value>
236+
</data>
234237
</root>

src/ResourceManager/Sql/Commands.Sql/Security/Cmdlet/DataMasking/NewAzureSqlDatabaseDataMaskingRule.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Globalization;
2020
using System.Linq;
2121
using System.Management.Automation;
22+
using System.Text.RegularExpressions;
2223

2324
namespace Microsoft.Azure.Commands.Sql.Security.Cmdlet.DataMasking
2425
{
@@ -66,6 +67,12 @@ protected override IEnumerable<DatabaseDataMaskingRuleModel> GetEntity()
6667
/// <returns>An error message or null if all is fine</returns>
6768
protected override string ValidateOperation(IEnumerable<DatabaseDataMaskingRuleModel> rules)
6869
{
70+
var ruleIdRegex = new Regex("^[^/\\\\#+=<>*%&:?]*[^/\\\\#+=<>*%&:?.]$");
71+
72+
if (!ruleIdRegex.IsMatch(RuleId)) // an invalid rule name
73+
{
74+
return string.Format(CultureInfo.InvariantCulture, Resources.NewDataMaskingRuleIdIsNotValid, RuleId);
75+
}
6976
if(rules.Any(r=> r.RuleId == RuleId))
7077
{
7178
return string.Format(CultureInfo.InvariantCulture, Resources.NewDataMaskingRuleIdAlreadyExistError, RuleId);

0 commit comments

Comments
 (0)