From 5304dcdd9c2db545e0d633c3668b71ed5eacfdfd Mon Sep 17 00:00:00 2001 From: Siddharth Vaghasia Date: Wed, 17 Jan 2024 11:43:53 +0530 Subject: [PATCH] fix for all power platform commands giving error (#3687) * fix for all power platform commands giving error fix for all power platform commands giving error due to ARM is no longer supported. Co-Authored-By: Kunj Balkrishna Sangani * fix for build error Co-Authored-By: Kunj Balkrishna Sangani --------- Co-authored-by: Kunj Balkrishna Sangani Co-authored-by: Gautam Sheth --- src/Commands/PnP.PowerShell.csproj | 2 +- .../PowerPlatform/Environment/GetPowerPlatformConnector.cs | 3 ++- .../Environment/GetPowerPlatformEnvironment.cs | 3 ++- src/Commands/PowerPlatform/PowerApps/GetPowerApp.cs | 3 ++- src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs | 2 +- src/Commands/PowerPlatform/PowerAutomate/DisableFlow.cs | 2 +- src/Commands/PowerPlatform/PowerAutomate/EnableFlow.cs | 2 +- src/Commands/PowerPlatform/PowerAutomate/ExportFlow.cs | 2 +- src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs | 2 +- src/Commands/PowerPlatform/PowerAutomate/GetFlowRun.cs | 5 +++-- src/Commands/PowerPlatform/PowerAutomate/RemoveFlow.cs | 7 ++++--- .../PowerPlatform/PowerAutomate/RemoveFlowOwner.cs | 2 +- src/Commands/PowerPlatform/PowerAutomate/RestartFlowRun.cs | 5 +++-- src/Commands/PowerPlatform/PowerAutomate/StopFlowRun.cs | 2 +- src/Tests/PnP.PowerShell.Tests.csproj | 2 +- 15 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/Commands/PnP.PowerShell.csproj b/src/Commands/PnP.PowerShell.csproj index 2ccc12072..6d7bd9604 100644 --- a/src/Commands/PnP.PowerShell.csproj +++ b/src/Commands/PnP.PowerShell.csproj @@ -58,7 +58,7 @@ - + diff --git a/src/Commands/PowerPlatform/Environment/GetPowerPlatformConnector.cs b/src/Commands/PowerPlatform/Environment/GetPowerPlatformConnector.cs index 870b9ae25..bdd85ca35 100644 --- a/src/Commands/PowerPlatform/Environment/GetPowerPlatformConnector.cs +++ b/src/Commands/PowerPlatform/Environment/GetPowerPlatformConnector.cs @@ -23,6 +23,7 @@ public class GetPowerPlatformConnector : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { string environmentName = null; + string baseUrl = "https://api.flow.microsoft.com/"; if (ParameterSpecified(nameof(Environment))) { environmentName = Environment.GetName(); @@ -30,7 +31,7 @@ protected override void ExecuteCmdlet() } else { - var environments = GraphHelper.GetResultCollectionAsync(Connection, "https://management.azure.com/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + var environments = GraphHelper.GetResultCollectionAsync(Connection, baseUrl + "/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); environmentName = environments.FirstOrDefault(e => e.Properties.IsDefault.HasValue && e.Properties.IsDefault == true)?.Name; if (string.IsNullOrEmpty(environmentName)) diff --git a/src/Commands/PowerPlatform/Environment/GetPowerPlatformEnvironment.cs b/src/Commands/PowerPlatform/Environment/GetPowerPlatformEnvironment.cs index 3d42e54f4..277872b23 100644 --- a/src/Commands/PowerPlatform/Environment/GetPowerPlatformEnvironment.cs +++ b/src/Commands/PowerPlatform/Environment/GetPowerPlatformEnvironment.cs @@ -21,7 +21,8 @@ public class GetPowerPlatformEnvironment : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { - var environments = GraphHelper.GetResultCollectionAsync(Connection, "https://management.azure.com/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + string baseUrl = "https://api.flow.microsoft.com/"; + var environments = GraphHelper.GetResultCollectionAsync(Connection, baseUrl + "/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); if(ParameterSpecified(nameof(IsDefault)) && IsDefault.ToBool()) { diff --git a/src/Commands/PowerPlatform/PowerApps/GetPowerApp.cs b/src/Commands/PowerPlatform/PowerApps/GetPowerApp.cs index 68c569df6..59162d830 100644 --- a/src/Commands/PowerPlatform/PowerApps/GetPowerApp.cs +++ b/src/Commands/PowerPlatform/PowerApps/GetPowerApp.cs @@ -31,7 +31,8 @@ protected override void ExecuteCmdlet() } else { - var environments = GraphHelper.GetResultCollectionAsync(Connection, "https://management.azure.com/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + string baseUrl = "https://api.flow.microsoft.com/"; + var environments = GraphHelper.GetResultCollectionAsync(Connection, baseUrl + "/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); environmentName = environments.FirstOrDefault(e => e.Properties.IsDefault.HasValue && e.Properties.IsDefault == true)?.Name; if(string.IsNullOrEmpty(environmentName)) diff --git a/src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs b/src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs index 12f7a62eb..8577a5676 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs @@ -81,7 +81,7 @@ protected override void ExecuteCmdlet() }; WriteVerbose($"Assigning user {Role} permissions to flow {flowName} in environment {environmentName}"); - RestHelper.PostAsync(Connection.HttpClient, $"https://management.azure.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}/modifyPermissions?api-version=2016-11-01", AccessToken, payload).GetAwaiter().GetResult(); + RestHelper.PostAsync(Connection.HttpClient, $"https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}/modifyPermissions?api-version=2016-11-01", AccessToken, payload).GetAwaiter().GetResult(); } } } diff --git a/src/Commands/PowerPlatform/PowerAutomate/DisableFlow.cs b/src/Commands/PowerPlatform/PowerAutomate/DisableFlow.cs index 24c5d28cb..50d060d05 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/DisableFlow.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/DisableFlow.cs @@ -21,7 +21,7 @@ protected override void ExecuteCmdlet() { var environmentName = Environment.GetName(); var flowName = Identity.GetName(); - RestHelper.PostAsync(Connection.HttpClient, $"https://management.azure.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}/stop?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + RestHelper.PostAsync(Connection.HttpClient, $"https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}/stop?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); } } } \ No newline at end of file diff --git a/src/Commands/PowerPlatform/PowerAutomate/EnableFlow.cs b/src/Commands/PowerPlatform/PowerAutomate/EnableFlow.cs index 19247c99e..0adbcecd1 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/EnableFlow.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/EnableFlow.cs @@ -21,7 +21,7 @@ protected override void ExecuteCmdlet() { var environmentName = Environment.GetName(); var flowName = Identity.GetName(); - RestHelper.PostAsync(Connection.HttpClient, $"https://management.azure.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}/start?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + RestHelper.PostAsync(Connection.HttpClient, $"https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}/start?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); } } } \ No newline at end of file diff --git a/src/Commands/PowerPlatform/PowerAutomate/ExportFlow.cs b/src/Commands/PowerPlatform/PowerAutomate/ExportFlow.cs index 1672d3e81..c64ad3aac 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/ExportFlow.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/ExportFlow.cs @@ -161,7 +161,7 @@ protected override void ExecuteCmdlet() } else { - var json = RestHelper.PostAsync(Connection.HttpClient, $"https://management.azure.com/providers/Microsoft.ProcessSimple/environments/{environmentName}/flows/{flowName}/exportToARMTemplate?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + var json = RestHelper.PostAsync(Connection.HttpClient, $"https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple/environments/{environmentName}/flows/{flowName}/exportToARMTemplate?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); WriteObject(json); } } diff --git a/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs b/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs index 82f76842d..d8df71757 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs @@ -32,7 +32,7 @@ protected override void ExecuteCmdlet() throw new PSArgumentException("Flow not found.", nameof(Identity)); } - var flowOwners = GraphHelper.GetResultCollectionAsync(Connection, $"https://management.azure.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}/permissions?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + var flowOwners = GraphHelper.GetResultCollectionAsync(Connection, $"https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}/permissions?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); WriteObject(flowOwners, true); } } diff --git a/src/Commands/PowerPlatform/PowerAutomate/GetFlowRun.cs b/src/Commands/PowerPlatform/PowerAutomate/GetFlowRun.cs index 5f103bcf6..5f9a0c403 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/GetFlowRun.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/GetFlowRun.cs @@ -20,6 +20,7 @@ public class GetFlowRun : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { + string baseUrl = "https://api.flow.microsoft.com/"; var environmentName = Environment.GetName(); if (string.IsNullOrEmpty(environmentName)) { @@ -35,12 +36,12 @@ protected override void ExecuteCmdlet() if (ParameterSpecified(nameof(Identity))) { var flowRunName = Identity.GetName(); - var flowRun = GraphHelper.GetAsync(Connection, $"https://management.azure.com/providers/Microsoft.ProcessSimple/environments/{environmentName}/flows/{flowName}/runs/{flowRunName}?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + var flowRun = GraphHelper.GetAsync(Connection, baseUrl + $"providers/Microsoft.ProcessSimple/environments/{environmentName}/flows/{flowName}/runs/{flowRunName}?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); WriteObject(flowRun, false); } else { - var flowRuns = GraphHelper.GetResultCollectionAsync(Connection, $"https://management.azure.com/providers/Microsoft.ProcessSimple/environments/{environmentName}/flows/{flowName}/runs?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + var flowRuns = GraphHelper.GetResultCollectionAsync(Connection, baseUrl + $"providers/Microsoft.ProcessSimple/environments/{environmentName}/flows/{flowName}/runs?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); WriteObject(flowRuns, true); } } diff --git a/src/Commands/PowerPlatform/PowerAutomate/RemoveFlow.cs b/src/Commands/PowerPlatform/PowerAutomate/RemoveFlow.cs index 2165089a2..5b50704ef 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/RemoveFlow.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/RemoveFlow.cs @@ -26,6 +26,7 @@ public class RemoveFlow : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { + string baseUrl = "https://api.flow.microsoft.com/"; var environmentName = Environment.GetName(); var flowName = Identity.GetName(); @@ -38,10 +39,10 @@ protected override void ExecuteCmdlet() { // Had to add this because DELETE doesn't throw error if invalid Flow Id or Name is provided WriteVerbose($"Retrieving Flow with name {flowName} in environment ${environmentName}"); - var result = GraphHelper.GetAsync(Connection, $"https://management.azure.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + var result = GraphHelper.GetAsync(Connection, baseUrl + $"providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); if (result != null) { - RestHelper.DeleteAsync(Connection.HttpClient, $"https://management.azure.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + RestHelper.DeleteAsync(Connection.HttpClient, baseUrl + $"providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); WriteVerbose($"Flow with name {flowName} deleted"); } } @@ -52,7 +53,7 @@ protected override void ExecuteCmdlet() } else { - RestHelper.DeleteAsync(Connection.HttpClient, $"https://management.azure.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + RestHelper.DeleteAsync(Connection.HttpClient, baseUrl + $"providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); WriteVerbose($"Flow with name {flowName} deleted"); } } diff --git a/src/Commands/PowerPlatform/PowerAutomate/RemoveFlowOwner.cs b/src/Commands/PowerPlatform/PowerAutomate/RemoveFlowOwner.cs index 751526b0d..0fbde3b3c 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/RemoveFlowOwner.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/RemoveFlowOwner.cs @@ -75,7 +75,7 @@ protected override void ExecuteCmdlet() if(Force || ShouldContinue($"Remove flow owner with id '{user.Id.Value}' from flow '{flowName}'?", "Remove flow owner")) { WriteVerbose($"Removing user {user.Id.Value} permissions from flow {flowName} in environment {environmentName}"); - RestHelper.PostAsync(Connection.HttpClient, $"https://management.azure.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}/modifyPermissions?api-version=2016-11-01", AccessToken, payload).GetAwaiter().GetResult(); + RestHelper.PostAsync(Connection.HttpClient, $"https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}/modifyPermissions?api-version=2016-11-01", AccessToken, payload).GetAwaiter().GetResult(); } } } diff --git a/src/Commands/PowerPlatform/PowerAutomate/RestartFlowRun.cs b/src/Commands/PowerPlatform/PowerAutomate/RestartFlowRun.cs index 990820517..c1ffe0a7e 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/RestartFlowRun.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/RestartFlowRun.cs @@ -25,6 +25,7 @@ public class RestartFlowRun : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { + string baseUrl = "https://api.flow.microsoft.com/"; var environmentName = Environment.GetName(); if (string.IsNullOrEmpty(environmentName)) { @@ -46,8 +47,8 @@ protected override void ExecuteCmdlet() if (!Force && !ShouldContinue($"Restart flow run with name '{flowRunName}'?", Resources.Confirm)) return; - var triggers = GraphHelper.GetResultCollectionAsync(Connection, $"https://management.azure.com/providers/Microsoft.ProcessSimple/environments/{environmentName}/flows/{flowName}/triggers?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); - RestHelper.PostAsync(Connection.HttpClient, $"https://management.azure.com/providers/Microsoft.ProcessSimple/environments/{environmentName}/flows/{flowName}/triggers/{triggers.First().Name}/histories/{flowRunName}/resubmit?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + var triggers = GraphHelper.GetResultCollectionAsync(Connection, baseUrl + $"providers/Microsoft.ProcessSimple/environments/{environmentName}/flows/{flowName}/triggers?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + RestHelper.PostAsync(Connection.HttpClient, baseUrl + $"providers/Microsoft.ProcessSimple/environments/{environmentName}/flows/{flowName}/triggers/{triggers.First().Name}/histories/{flowRunName}/resubmit?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); } } } diff --git a/src/Commands/PowerPlatform/PowerAutomate/StopFlowRun.cs b/src/Commands/PowerPlatform/PowerAutomate/StopFlowRun.cs index 61019b1b1..c56a566d4 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/StopFlowRun.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/StopFlowRun.cs @@ -43,7 +43,7 @@ protected override void ExecuteCmdlet() if (Force || ShouldContinue($"Stop flow run with name '{flowRunName}'?", Resources.Confirm)) { - RestHelper.PostAsync(Connection.HttpClient, $"https://management.azure.com/providers/Microsoft.ProcessSimple/environments/{environmentName}/flows/{flowName}/runs/{flowRunName}/cancel?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + RestHelper.PostAsync(Connection.HttpClient, $"https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple/environments/{environmentName}/flows/{flowName}/runs/{flowRunName}/cancel?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); } } } diff --git a/src/Tests/PnP.PowerShell.Tests.csproj b/src/Tests/PnP.PowerShell.Tests.csproj index 6b4ba1813..bb0b1baf5 100644 --- a/src/Tests/PnP.PowerShell.Tests.csproj +++ b/src/Tests/PnP.PowerShell.Tests.csproj @@ -24,7 +24,7 @@ - +