Skip to content

Commit

Permalink
fix for all power platform commands giving error (#3687)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* fix for build error

Co-Authored-By: Kunj Balkrishna Sangani <[email protected]>

---------

Co-authored-by: Kunj Balkrishna Sangani <[email protected]>
Co-authored-by: Gautam Sheth <[email protected]>
  • Loading branch information
3 people authored Jan 17, 2024
1 parent 30f03cd commit 5304dcd
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Commands/PnP.PowerShell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<PackageReference Include="Microsoft.Graph" Version="3.33.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.50.0" />
<PackageReference Include="Microsoft.SharePointOnline.CSOM" Version="16.1.*" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.27.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.34.0" />
<PackageReference Include="PnP.Framework" Version="1.14.*-*" Condition="'$(PnPFrameworkPath)' == '' and '$(IsRelease)' != '1'" />
<PackageReference Include="PnP.Framework" Version="1.14.*-*" Condition="'$(IsRelease)' == '1'" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ 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();
WriteVerbose($"Using environment as provided '{environmentName}'");
}
else
{
var environments = GraphHelper.GetResultCollectionAsync<Model.PowerPlatform.Environment.Environment>(Connection, "https://management.azure.com/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult();
var environments = GraphHelper.GetResultCollectionAsync<Model.PowerPlatform.Environment.Environment>(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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class GetPowerPlatformEnvironment : PnPAzureManagementApiCmdlet

protected override void ExecuteCmdlet()
{
var environments = GraphHelper.GetResultCollectionAsync<Model.PowerPlatform.Environment.Environment>(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<Model.PowerPlatform.Environment.Environment>(Connection, baseUrl + "/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult();

if(ParameterSpecified(nameof(IsDefault)) && IsDefault.ToBool())
{
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/PowerPlatform/PowerApps/GetPowerApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ protected override void ExecuteCmdlet()
}
else
{
var environments = GraphHelper.GetResultCollectionAsync<Model.PowerPlatform.Environment.Environment>(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<Model.PowerPlatform.Environment.Environment>(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))
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/PowerPlatform/PowerAutomate/DisableFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/PowerPlatform/PowerAutomate/EnableFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/PowerPlatform/PowerAutomate/ExportFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected override void ExecuteCmdlet()
throw new PSArgumentException("Flow not found.", nameof(Identity));
}

var flowOwners = GraphHelper.GetResultCollectionAsync<FlowPermission>(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<FlowPermission>(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);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Commands/PowerPlatform/PowerAutomate/GetFlowRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -35,12 +36,12 @@ protected override void ExecuteCmdlet()
if (ParameterSpecified(nameof(Identity)))
{
var flowRunName = Identity.GetName();
var flowRun = GraphHelper.GetAsync<FlowRun>(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<FlowRun>(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<FlowRun>(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<FlowRun>(Connection, baseUrl + $"providers/Microsoft.ProcessSimple/environments/{environmentName}/flows/{flowName}/runs?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult();
WriteObject(flowRuns, true);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/Commands/PowerPlatform/PowerAutomate/RemoveFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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<Model.PowerPlatform.PowerAutomate.Flow>(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<Model.PowerPlatform.PowerAutomate.Flow>(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");
}
}
Expand All @@ -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");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Commands/PowerPlatform/PowerAutomate/RestartFlowRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -46,8 +47,8 @@ protected override void ExecuteCmdlet()
if (!Force && !ShouldContinue($"Restart flow run with name '{flowRunName}'?", Resources.Confirm))
return;

var triggers = GraphHelper.GetResultCollectionAsync<FlowRunTrigger>(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<FlowRunTrigger>(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();
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/PowerPlatform/PowerAutomate/StopFlowRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/PnP.PowerShell.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="PnP.Framework" Version="1.14.*-*" Condition="'$(LocalDebug)' != 'true'" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.27.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.34.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="6.0.0" />
Expand Down

0 comments on commit 5304dcd

Please sign in to comment.