Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Stability fixes
Browse files Browse the repository at this point in the history
- Fixed extra wide table output in Excel reports when there are too many Roles (role per user kind of thing)
- Fixed crash on output of graphviz diagrams when FUTURE GRANTS ON SCHEMA are present
  • Loading branch information
sfc-gh-dodievich committed Mar 29, 2022
1 parent d3e5106 commit 06998ef
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net5.0/SFGrantReport.dll",
//"args": ["-l", "C:\\snowflake\\SnowflakeGrantReport\\Reports\\aws_cas1", "-r", "C:\\snowflake\\SnowflakeGrantReport\\Reports\\aws_cas1.offline.08192021", "-o", "C:\\snowflake\\SnowflakeGrantReport\\Reports\\aws_cas1.offline.08192021.compare" ],
//"args": ["-i", "C:\\snowflake\\GrantReport\\ACCOUNT_USAGE_INPUT\\", "-o", "C:\\snowflake\\SnowflakeGrantReport\\Reports\\Avalera\\myReports", "-s"],
"args": ["-c", "sfgrantreport", "-o", "C:\\snowflake\\SnowflakeGrantReport\\Reports\\Avalera\\myReports", "-s"],
"args": ["-i", "C:\\snowflake\\SnowflakeGrantReport\\ACCOUNT_USAGE_INPUT\\COINBASE_Snowhouse", "-o", "C:\\snowflake\\SnowflakeGrantReport\\Reports\\COINBASE.20220314"],
//"args": ["-c", "sfgrantreport", "-o", "C:\\snowflake\\SnowflakeGrantReport\\Reports\\Avalera\\myReports", "-s"],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "externalTerminal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ public override bool Execute(ProgramOptions programOptions)
break;
}

sbGraphViz.AppendFormat(" <tr><td align=\"left\">{0}</td><td align=\"right\">{1}</td><td align=\"right\">{2}</td></tr>", schema.ShortName, schema.Tables.Count, schema.Views.Count); sbGraphViz.AppendLine();
// Do not output future grants which are in form of <SCHEMANAME>
if (schema.ShortName.StartsWith("<") && schema.ShortName.EndsWith(">")) continue;

sbGraphViz.AppendFormat(" <tr><td align=\"left\">{0}</td><td align=\"right\">{1}</td><td align=\"right\">{2}</td></tr>", System.Web.HttpUtility.HtmlEncode(schema.ShortName), schema.Tables.Count, schema.Views.Count); sbGraphViz.AppendLine();

schemaLimit++;
}
Expand Down
82 changes: 43 additions & 39 deletions ProcessingSteps/Report/ReportUserRoleGrantsTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -914,15 +914,15 @@ private void generateExcelReport(ProgramOptions programOptions, List<string> she
// Add another Role to the header
thisRoleColumnIndex = roleColumnMaxIndex;
roleToHeaderMapping.Add(firstGrant.GrantedTo, thisRoleColumnIndex);
sheet.Cells[headerRowIndex, thisRoleColumnIndex].Value = firstGrant.GrantedTo;
if (thisRoleColumnIndex <= 16384) sheet.Cells[headerRowIndex, thisRoleColumnIndex].Value = firstGrant.GrantedTo;
roleColumnMaxIndex++;
}
else
{
// Previously seen
thisRoleColumnIndex = roleToHeaderMapping[firstGrant.GrantedTo];
}
outputGrantstToCell(sheet.Cells[currentRowIndex, thisRoleColumnIndex], grantsByRoleNameGroup.ToList());
if (thisRoleColumnIndex <= 16384) outputGrantstToCell(sheet.Cells[currentRowIndex, thisRoleColumnIndex], grantsByRoleNameGroup.ToList());
}

currentRowIndex++;
Expand All @@ -944,15 +944,15 @@ private void generateExcelReport(ProgramOptions programOptions, List<string> she
// Add another Role to the header
thisRoleColumnIndex = roleColumnMaxIndex;
roleToHeaderMapping.Add(firstGrant.GrantedTo, thisRoleColumnIndex);
sheet.Cells[headerRowIndex, thisRoleColumnIndex].Value = firstGrant.GrantedTo;
if (thisRoleColumnIndex <= 16384) sheet.Cells[headerRowIndex, thisRoleColumnIndex].Value = firstGrant.GrantedTo;
roleColumnMaxIndex++;
}
else
{
// Previously seen
thisRoleColumnIndex = roleToHeaderMapping[firstGrant.GrantedTo];
}
outputGrantstToCell(sheet.Cells[currentRowIndex, thisRoleColumnIndex], grantsByRoleNameGroup.ToList());
if (thisRoleColumnIndex <= 16384) outputGrantstToCell(sheet.Cells[currentRowIndex, thisRoleColumnIndex], grantsByRoleNameGroup.ToList());
}

currentRowIndex++;
Expand All @@ -974,15 +974,15 @@ private void generateExcelReport(ProgramOptions programOptions, List<string> she
// Add another Role to the header
thisRoleColumnIndex = roleColumnMaxIndex;
roleToHeaderMapping.Add(firstGrant.GrantedTo, thisRoleColumnIndex);
sheet.Cells[headerRowIndex, thisRoleColumnIndex].Value = firstGrant.GrantedTo;
if (thisRoleColumnIndex <= 16384) sheet.Cells[headerRowIndex, thisRoleColumnIndex].Value = firstGrant.GrantedTo;
roleColumnMaxIndex++;
}
else
{
// Previously seen
thisRoleColumnIndex = roleToHeaderMapping[firstGrant.GrantedTo];
}
outputGrantstToCell(sheet.Cells[currentRowIndex, thisRoleColumnIndex], grantsByRoleNameGroup.ToList());
if (thisRoleColumnIndex <= 16384) outputGrantstToCell(sheet.Cells[currentRowIndex, thisRoleColumnIndex], grantsByRoleNameGroup.ToList());
}

sheet.Row(currentRowIndex).OutlineLevel = 1;
Expand All @@ -1006,15 +1006,15 @@ private void generateExcelReport(ProgramOptions programOptions, List<string> she
// Add another Role to the header
thisRoleColumnIndex = roleColumnMaxIndex;
roleToHeaderMapping.Add(firstGrant.GrantedTo, thisRoleColumnIndex);
sheet.Cells[headerRowIndex, thisRoleColumnIndex].Value = firstGrant.GrantedTo;
if (thisRoleColumnIndex <= 16384) sheet.Cells[headerRowIndex, thisRoleColumnIndex].Value = firstGrant.GrantedTo;
roleColumnMaxIndex++;
}
else
{
// Previously seen
thisRoleColumnIndex = roleToHeaderMapping[firstGrant.GrantedTo];
}
outputGrantstToCell(sheet.Cells[currentRowIndex, thisRoleColumnIndex], grantsByRoleNameGroup.ToList());
if (thisRoleColumnIndex <= 16384) outputGrantstToCell(sheet.Cells[currentRowIndex, thisRoleColumnIndex], grantsByRoleNameGroup.ToList());
}

sheet.Row(currentRowIndex).OutlineLevel = 1;
Expand Down Expand Up @@ -1050,39 +1050,43 @@ private void generateExcelReport(ProgramOptions programOptions, List<string> she
}

// Format the cells
ExcelRangeBase rangeToFormat = sheet.Cells[headerRowIndex + 1, 4, sheet.Dimension.Rows, sheet.Dimension.Columns];
rangeToFormat.StyleName = "ShortPermissionStyle";

var cfR = sheet.ConditionalFormatting.AddEqual(rangeToFormat);
cfR.Style.Font.Color.Color = Color.Green;
cfR.Style.Fill.BackgroundColor.Color = Color.LightGreen;
cfR.Formula = "=\"R\"";

var cfCRUD = sheet.ConditionalFormatting.AddContainsText(rangeToFormat);
cfCRUD.Style.Font.Color.Color = Color.DarkRed;
cfCRUD.Style.Fill.BackgroundColor.Color = Color.Pink;
cfCRUD.Text = "C,R,U,D";

var cfCRU = sheet.ConditionalFormatting.AddContainsText(rangeToFormat);
cfCRU.Style.Font.Color.Color = Color.OrangeRed;
cfCRU.Style.Fill.BackgroundColor.Color = Color.Gold;
cfCRU.Text = "C,R,U";

var cfO = sheet.ConditionalFormatting.AddEqual(rangeToFormat);
cfO.Style.Font.Color.Color = Color.DarkBlue;
cfO.Style.Fill.BackgroundColor.Color = Color.Azure;
cfO.Formula = "=\"O\"";

var cfOPlus = sheet.ConditionalFormatting.AddEqual(rangeToFormat);
cfOPlus.Style.Font.Color.Color = Color.DarkBlue;
cfOPlus.Style.Fill.BackgroundColor.Color = Color.LightBlue;
cfOPlus.Formula = "=\"O+\"";
// But only if the number of columns isn't insanely high
if (sheet.Dimension.Columns <=10000)
{
ExcelRangeBase rangeToFormat = sheet.Cells[headerRowIndex + 1, 4, sheet.Dimension.Rows, sheet.Dimension.Columns];
rangeToFormat.StyleName = "ShortPermissionStyle";

var cfR = sheet.ConditionalFormatting.AddEqual(rangeToFormat);
cfR.Style.Font.Color.Color = Color.Green;
cfR.Style.Fill.BackgroundColor.Color = Color.LightGreen;
cfR.Formula = "=\"R\"";

var cfCRUD = sheet.ConditionalFormatting.AddContainsText(rangeToFormat);
cfCRUD.Style.Font.Color.Color = Color.DarkRed;
cfCRUD.Style.Fill.BackgroundColor.Color = Color.Pink;
cfCRUD.Text = "C,R,U,D";

var cfCRU = sheet.ConditionalFormatting.AddContainsText(rangeToFormat);
cfCRU.Style.Font.Color.Color = Color.OrangeRed;
cfCRU.Style.Fill.BackgroundColor.Color = Color.Gold;
cfCRU.Text = "C,R,U";

var cfO = sheet.ConditionalFormatting.AddEqual(rangeToFormat);
cfO.Style.Font.Color.Color = Color.DarkBlue;
cfO.Style.Fill.BackgroundColor.Color = Color.Azure;
cfO.Formula = "=\"O\"";

var cfOPlus = sheet.ConditionalFormatting.AddEqual(rangeToFormat);
cfOPlus.Style.Font.Color.Color = Color.DarkBlue;
cfOPlus.Style.Fill.BackgroundColor.Color = Color.LightBlue;
cfOPlus.Formula = "=\"O+\"";

rangeToFormat = sheet.Cells[headerRowIndex + 1, 3, sheet.Dimension.Rows, 3];
rangeToFormat = sheet.Cells[headerRowIndex + 1, 3, sheet.Dimension.Rows, 3];

var cfFuture = sheet.ConditionalFormatting.AddContainsText(rangeToFormat);
cfFuture.Style.Fill.BackgroundColor.Color = Color.GreenYellow;
cfFuture.Text = "<";
var cfFuture = sheet.ConditionalFormatting.AddContainsText(rangeToFormat);
cfFuture.Style.Fill.BackgroundColor.Color = Color.GreenYellow;
cfFuture.Text = "<";
}

logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows);
Expand Down
6 changes: 3 additions & 3 deletions Snowflake.GrantReport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<AssemblyName>SFGrantReport</AssemblyName>
<RootNamespace>Snowflake.GrantReport</RootNamespace>

<Version>2021.10.12.0</Version>
<FileVersion>2021.10.12.0</FileVersion>
<AssemblyVersion>2021.10.12.0</AssemblyVersion>
<Version>2022.3.29.0</Version>
<FileVersion>2022.3.29.0</FileVersion>
<AssemblyVersion>2022.3.29.0</AssemblyVersion>
<Authors>Daniel Odievich ([email protected])</Authors>
<Company>Snowflake Computing</Company>
<Product>Snowflake Grant Report</Product>
Expand Down

0 comments on commit 06998ef

Please sign in to comment.