From d346005ef09f56ba27035c007f8d03402f0e2205 Mon Sep 17 00:00:00 2001 From: vplauzon Date: Thu, 19 Oct 2023 16:53:33 -0400 Subject: [PATCH] Add delete command --- .../DeltaKustoLib/CommandModel/CommandBase.cs | 2 + .../DeleteRowLevelSecurityPolicyCommand.cs | 45 +++++++++++++++++++ .../DeleteRowLevelSecurityPolicyTest.cs | 33 ++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 code/DeltaKustoLib/CommandModel/Policies/DeleteRowLevelSecurityPolicyCommand.cs create mode 100644 code/DeltaKustoUnitTest/CommandParsing/Policies/DeleteRowLevelSecurityPolicyTest.cs diff --git a/code/DeltaKustoLib/CommandModel/CommandBase.cs b/code/DeltaKustoLib/CommandModel/CommandBase.cs index e94c8f0..2c92f1a 100644 --- a/code/DeltaKustoLib/CommandModel/CommandBase.cs +++ b/code/DeltaKustoLib/CommandModel/CommandBase.cs @@ -191,6 +191,8 @@ public override int GetHashCode() return DeleteStreamingIngestionPolicyCommand.FromCode(commandBlock); case "AlterTablePolicyRowLevelSecurity": return AlterRowLevelSecurityPolicyCommand.FromCode(commandBlock); + case "DeleteTablePolicyRowLevelSecurity": + return DeleteRowLevelSecurityPolicyCommand.FromCode(commandBlock); #endregion default: diff --git a/code/DeltaKustoLib/CommandModel/Policies/DeleteRowLevelSecurityPolicyCommand.cs b/code/DeltaKustoLib/CommandModel/Policies/DeleteRowLevelSecurityPolicyCommand.cs new file mode 100644 index 0000000..1008d57 --- /dev/null +++ b/code/DeltaKustoLib/CommandModel/Policies/DeleteRowLevelSecurityPolicyCommand.cs @@ -0,0 +1,45 @@ +using Kusto.Language.Syntax; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace DeltaKustoLib.CommandModel.Policies +{ + /// + /// Models ??? (unexisting documentation) + /// + [Command(20000, "Delete Row Level Security Policies")] + public class DeleteRowLevelSecurityPolicyCommand : TableOnlyPolicyCommandBase + { + public override string CommandFriendlyName => ".delete policy row_level_security"; + + public override string ScriptPath => "tables/policies/row_level_security/delete"; + + public DeleteRowLevelSecurityPolicyCommand(EntityName tableName) + : base(tableName) + { + } + + internal static CommandBase FromCode(SyntaxElement rootElement) + { + var tableName = rootElement.GetFirstDescendant(); + + return new DeleteRowLevelSecurityPolicyCommand(EntityName.FromCode(tableName.Name)); + } + + public override string ToScript(ScriptingContext? context) + { + var builder = new StringBuilder(); + + builder.Append(".delete table "); + builder.Append(TableName.ToScript()); + builder.Append(" policy row_level_security"); + + return builder.ToString(); + } + } +} \ No newline at end of file diff --git a/code/DeltaKustoUnitTest/CommandParsing/Policies/DeleteRowLevelSecurityPolicyTest.cs b/code/DeltaKustoUnitTest/CommandParsing/Policies/DeleteRowLevelSecurityPolicyTest.cs new file mode 100644 index 0000000..1cb37b5 --- /dev/null +++ b/code/DeltaKustoUnitTest/CommandParsing/Policies/DeleteRowLevelSecurityPolicyTest.cs @@ -0,0 +1,33 @@ +using DeltaKustoLib.CommandModel; +using DeltaKustoLib.CommandModel.Policies; +using System; +using System.Linq; +using System.Text.Json; +using Xunit; + +namespace DeltaKustoUnitTest.CommandParsing.Policies +{ + public class DeleteRowLevelSecurityPolicyTest : ParsingTestBase + { + [Fact] + public void SimpleTable() + { + TestAutoDeletePolicy("A"); + } + + [Fact] + public void FunkyTable() + { + TestAutoDeletePolicy("A- 1"); + } + + private void TestAutoDeletePolicy(string tableName) + { + var commandText = new DeleteRowLevelSecurityPolicyCommand(new EntityName(tableName)) + .ToScript(null); + var command = ParseOneCommand(commandText); + + Assert.IsType(command); + } + } +} \ No newline at end of file