Skip to content

Commit

Permalink
Added support for replicating FIlters
Browse files Browse the repository at this point in the history
- Read filters
- New/Update Filter
- Delete Filter
- Change from net5 to net6 target
- Changes to signature of functions in snowflake driver
- Change in URL for the query for the Get-SFQueryProfile
  • Loading branch information
sfc-gh-dodievich committed Apr 8, 2022
1 parent 01993a7 commit d47d26a
Show file tree
Hide file tree
Showing 36 changed files with 1,598 additions and 266 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"-NoExit",
"-NoProfile",
"-Command",
"Import-Module ${workspaceFolder}/bin/Debug/net5.0/SnowflakePS.psd1",
"Import-Module ${workspaceFolder}/bin/Debug/net6.0/SnowflakePS.psd1",
],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
Expand Down
4 changes: 2 additions & 2 deletions Commands/Authentication/ConnectAppCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Snowflake Inc. All rights reserved.
// Copyright (c) 2021-2022 Snowflake Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
Expand Down Expand Up @@ -617,7 +617,7 @@ protected override void ProcessRecord()
loggerConsole.Info("Getting Organization and User context for user {0} in account {1}", appUserContext.UserName, appUserContext.AccountName);

// Get Org ID and User ID for future use
string organizationAndUserContextResult = SnowflakeDriver.GetOrganizationAndUserContext(appUserContext.MainAppUrl, appUserContext.AppServerUrl, appUserContext.AccountUrl, appUserContext.Region, appUserContext.AccountName, appUserContext.UserName, appUserContext.AuthTokenSnowsight);
string organizationAndUserContextResult = SnowflakeDriver.GetOrganizationAndUserContext(appUserContext);
if (organizationAndUserContextResult.Length == 0)
{
throw new ItemNotFoundException(String.Format("Invalid response from getting organization context for user {0}@{1}", appUserContext.UserName, appUserContext.AccountName));
Expand Down
10 changes: 4 additions & 6 deletions Commands/Dashboard/GetDashboardsCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Snowflake Inc. All rights reserved.
// Copyright (c) 2021-2022 Snowflake Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
Expand Down Expand Up @@ -72,10 +72,10 @@ protected override void ProcessRecord()
{
try
{
string dashboardsApiResult = SnowflakeDriver.GetDashboards(this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.OrganizationID, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight);
string dashboardsApiResult = SnowflakeDriver.GetDashboards(this.AuthContext);
if (dashboardsApiResult.Length == 0)
{
throw new ItemNotFoundException("Invalid response from listing dashboard entities");
throw new ItemNotFoundException("Invalid response from listing Dashboard entities");
}

JObject dashboardsPayloadObject = JObject.Parse(dashboardsApiResult);
Expand Down Expand Up @@ -113,9 +113,7 @@ protected override void ProcessRecord()
loggerConsole.Trace("Worksheet {0} ({1}), details of Chart {2} ({3})", worksheet.WorksheetName, worksheet.WorksheetID, chart.ChartName, chart.ChartID);

// Get chart details
string chartDetailApiResult = SnowflakeDriver.GetChart(
this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.OrganizationID, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight,
chart.WorksheetID, chart.ChartID);
string chartDetailApiResult = SnowflakeDriver.GetChart(this.AuthContext, chart.WorksheetID, chart.ChartID);

if (chartDetailApiResult.Length == 0)
{
Expand Down
8 changes: 4 additions & 4 deletions Commands/Dashboard/InvokeDashboardCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Snowflake Inc. All rights reserved.
// Copyright (c) 2021-2022 Snowflake Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
Expand Down Expand Up @@ -141,10 +141,10 @@ protected override void ProcessRecord()
}

// Get all Dashboards already present
string dashboardsApiResult = SnowflakeDriver.GetDashboards(this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.OrganizationID, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight);
string dashboardsApiResult = SnowflakeDriver.GetDashboards(this.AuthContext);
if (dashboardsApiResult.Length == 0)
{
throw new ItemNotFoundException("Invalid response from listing dashboard entities");
throw new ItemNotFoundException("Invalid response from listing Dashboard entities");
}

JObject dashboardsPayloadObject = JObject.Parse(dashboardsApiResult);
Expand Down Expand Up @@ -213,7 +213,7 @@ protected override void ProcessRecord()
logger.Info("Running {0}", dashboard);
loggerConsole.Trace("Running Dashboard {0} ({1}) with {2} Worksheets", dashboard.DashboardName, dashboard.DashboardID, dashboard.Worksheets.Count);

string dashboardsRefreshResult = SnowflakeDriver.ExecuteDashboard(this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight, dashboard.DashboardID);
string dashboardsRefreshResult = SnowflakeDriver.ExecuteDashboard(this.AuthContext, dashboard.DashboardID);
if (dashboardsRefreshResult .Length == 0)
{
throw new ItemNotFoundException("Invalid response from refreshing dashboard");
Expand Down
41 changes: 13 additions & 28 deletions Commands/Dashboard/NewDashboardCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Snowflake Inc. All rights reserved.
// Copyright (c) 2021-2022 Snowflake Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
Expand Down Expand Up @@ -128,10 +128,10 @@ protected override void ProcessRecord()
}

// Get all Dashboards already present
string dashboardsApiResult = SnowflakeDriver.GetDashboards(this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.OrganizationID, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight);
string dashboardsApiResult = SnowflakeDriver.GetDashboards(this.AuthContext);
if (dashboardsApiResult.Length == 0)
{
throw new ItemNotFoundException("Invalid response from listing dashboard entities");
throw new ItemNotFoundException("Invalid response from listing Dashboard entities");
}

Dashboard targetDashboardToReplace = null;
Expand Down Expand Up @@ -208,7 +208,7 @@ protected override void ProcessRecord()

case "Skip":
logger.Info("Found {0} to overwrite but ActionIfExists={1}, will skip", targetDashboardToReplace, this.ActionIfExists);
loggerConsole.Info("Existing Dashboard {0} ({1}) will be ignored and nothing will be done because ActionIfExists is {1}", targetDashboardToReplace.DashboardName, targetDashboardToReplace.DashboardID, this.ActionIfExists);
loggerConsole.Info("Existing Dashboard {0} ({1}) will be ignored and nothing will be done because ActionIfExists is {2}", targetDashboardToReplace.DashboardName, targetDashboardToReplace.DashboardID, this.ActionIfExists);

return;

Expand All @@ -218,7 +218,7 @@ protected override void ProcessRecord()
}
else
{
logger.Info("No match for {0}, new one will be created", this.Dashboard);
logger.Info("No match for Dashboard {0}, new one will be created", this.Dashboard);
loggerConsole.Info("Creating new Dashboard {0}", this.Dashboard.DashboardName);
}

Expand All @@ -233,9 +233,7 @@ protected override void ProcessRecord()
else
{
// Creating new Dashboard
string createDashboardApiResult = SnowflakeDriver.CreateDashboard(
this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.OrganizationID, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight,
this.Dashboard.DashboardName, this.Dashboard.Role, this.Dashboard.Warehouse);
string createDashboardApiResult = SnowflakeDriver.CreateDashboard(this.AuthContext, this.Dashboard.DashboardName, this.Dashboard.Role, this.Dashboard.Warehouse);

if (createDashboardApiResult.Length == 0)
{
Expand All @@ -257,9 +255,7 @@ protected override void ProcessRecord()
loggerConsole.Trace("{0}/{1}: Creating new Worksheet for {2} ({3})", i + 1, this.Dashboard.Worksheets.Count, worksheetToCreate.WorksheetName, worksheetToCreate.WorksheetID);

// Creating new worksheet
string createWorksheetApiResult = SnowflakeDriver.CreateWorksheet(
this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.OrganizationID, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight,
worksheetToCreate.WorksheetName, newDashboardID);
string createWorksheetApiResult = SnowflakeDriver.CreateWorksheet(this.AuthContext, worksheetToCreate.WorksheetName, newDashboardID);

if (createWorksheetApiResult.Length == 0)
{
Expand All @@ -270,9 +266,7 @@ protected override void ProcessRecord()
string newWorksheetID = JSONHelper.getStringValueFromJToken(createWorksheetPayloadObject, "pid");
logger.Info("Original WorksheetID={0} -> New WorksheetID={1}", worksheetToCreate.WorksheetID, newWorksheetID);

string updateWorksheetApiResult = SnowflakeDriver.UpdateWorksheet(
this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight,
newWorksheetID, worksheetToCreate.Query, worksheetToCreate.Role, worksheetToCreate.Warehouse, worksheetToCreate.Database, worksheetToCreate.Schema);
string updateWorksheetApiResult = SnowflakeDriver.UpdateWorksheet(this.AuthContext, newWorksheetID, worksheetToCreate.Query, worksheetToCreate.Role, worksheetToCreate.Warehouse, worksheetToCreate.Database, worksheetToCreate.Schema);

if (updateWorksheetApiResult.Length == 0)
{
Expand All @@ -298,9 +292,7 @@ protected override void ProcessRecord()
loggerConsole.Trace("Creating new Chart {0} ({1}) in {2} ({3})", chartToCreate.ChartName, chartToCreate.ChartID, worksheetCreated.WorksheetName, worksheetCreated.WorksheetID);

// Creating new worksheet
string createChartApiResult = SnowflakeDriver.CreateChartFromWorksheet(
this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight,
worksheetCreated.WorksheetID, chartToCreate.Configuration.ToString(Newtonsoft.Json.Formatting.None));
string createChartApiResult = SnowflakeDriver.CreateChartFromWorksheet(this.AuthContext, worksheetCreated.WorksheetID, chartToCreate.Configuration.ToString(Newtonsoft.Json.Formatting.None));
}
}

Expand Down Expand Up @@ -336,16 +328,12 @@ protected override void ProcessRecord()
if (cellIndex == 0)
{
// Insert new row into the first cell
string newRowApiResult = SnowflakeDriver.UpdateDashboardNewRowWithWorksheet(
this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight,
newDashboardID, worksheetCreated.WorksheetID, displayMode, rowIndex, rowHeight);
string newRowApiResult = SnowflakeDriver.UpdateDashboardNewRowWithWorksheet(this.AuthContext, newDashboardID, worksheetCreated.WorksheetID, displayMode, rowIndex, rowHeight);
}
else
{
// Insert new cell into existing row
string newCEllApiResult = SnowflakeDriver.UpdateDashboardInsertNewCellWithWorksheet(
this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight,
newDashboardID, worksheetCreated.WorksheetID, displayMode, rowIndex, rowHeight, cellIndex);
string newCEllApiResult = SnowflakeDriver.UpdateDashboardInsertNewCellWithWorksheet(this.AuthContext, newDashboardID, worksheetCreated.WorksheetID, displayMode, rowIndex, rowHeight, cellIndex);
}
}

Expand All @@ -365,8 +353,7 @@ protected override void ProcessRecord()
logger.Info("Running new Worksheet {0}", worksheetCreated);
loggerConsole.Trace("Running new Worksheet {0} ({1})", worksheetCreated.WorksheetName, worksheetCreated.WorksheetID);

string executeWorksheetApiResult = SnowflakeDriver.ExecuteWorksheet(
this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight,
string executeWorksheetApiResult = SnowflakeDriver.ExecuteWorksheet(this.AuthContext,
worksheetCreated.WorksheetID, worksheetCreated.Query, worksheetToCreate.Parameters.ToString(Newtonsoft.Json.Formatting.None),
worksheetCreated.Role, worksheetCreated.Warehouse, worksheetCreated.Database, worksheetCreated.Schema);

Expand Down Expand Up @@ -417,9 +404,7 @@ protected override void ProcessRecord()
}

// Get final dashboard
string getDashboardApiResult = SnowflakeDriver.GetDashboard(
this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight,
newDashboardID);
string getDashboardApiResult = SnowflakeDriver.GetDashboard(this.AuthContext, newDashboardID);

if (getDashboardApiResult.Length == 0)
{
Expand Down
10 changes: 5 additions & 5 deletions Commands/Dashboard/RemoveDashboardCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Snowflake Inc. All rights reserved.
// Copyright (c) 2021-2022 Snowflake Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
Expand Down Expand Up @@ -140,10 +140,10 @@ protected override void ProcessRecord()
}

// Get all dashboards already present
string dashboardsApiResult = SnowflakeDriver.GetDashboards(this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.OrganizationID, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight);
string dashboardsApiResult = SnowflakeDriver.GetDashboards(this.AuthContext);
if (dashboardsApiResult.Length == 0)
{
throw new ItemNotFoundException("Invalid response from listing dashboard entities");
throw new ItemNotFoundException("Invalid response from listing Dashboard entities");
}

JObject dashboardsPayloadObject = JObject.Parse(dashboardsApiResult);
Expand Down Expand Up @@ -214,10 +214,10 @@ protected override void ProcessRecord()
loggerConsole.Trace("Deleting Dashboard {0} ({1})", dashboard.DashboardName, dashboard.DashboardID);

// Delete the Worksheet
string dashboardDeleteApiResult = SnowflakeDriver.DeleteDashboard(this.AuthContext.MainAppUrl, this.AuthContext.AppServerUrl, this.AuthContext.AccountUrl, this.AuthContext.UserName, this.AuthContext.AuthTokenSnowsight, dashboard.DashboardID);
string dashboardDeleteApiResult = SnowflakeDriver.DeleteDashboard(this.AuthContext, dashboard.DashboardID);
if (dashboardDeleteApiResult.Length == 0)
{
throw new ItemNotFoundException("Invalid response from deleting dashboard entity");
throw new ItemNotFoundException("Invalid response from deleting Dashboard entity");
}
}

Expand Down
Loading

0 comments on commit d47d26a

Please sign in to comment.