Skip to content

Commit

Permalink
Add delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
vplauzon committed Oct 19, 2023
1 parent c97b795 commit d346005
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
2 changes: 2 additions & 0 deletions code/DeltaKustoLib/CommandModel/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Models ??? (unexisting documentation)
/// </summary>
[Command(20000, "Delete Row Level Security Policies")]
public class DeleteRowLevelSecurityPolicyCommand : TableOnlyPolicyCommandBase
{
public override string CommandFriendlyName => ".delete <entity> 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<NameReference>();

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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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<DeleteRowLevelSecurityPolicyCommand>(command);
}
}
}

0 comments on commit d346005

Please sign in to comment.