[BUG] problem: PolicyAssignmentImpl does not expose .Inner.Parameters object. effect: cannot assign built in Azure Policies which take parameters
See original GitHub issueDescribe the bug Simple Azure Policy Definitions that are built into Azure are not assignable with this SDK (trivially) because Policy Parameters are not exposed through the PolicyAssignmentImpl.
Exception or Stack Trace
Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> Microsoft.Azure.Management.ResourceManager.Fluent.Models.ErrorResponseException: Operation returned an invalid status code 'BadRequest'
at Microsoft.Azure.Management.ResourceManager.Fluent.PolicyAssignmentsOperations.CreateWithHttpMessagesAsync(String scope, String policyAssignmentName, PolicyAssignmentInner parameters, Dictionary`2 customHeaders, CancellationToken cancellationToken)
at Microsoft.Azure.Management.ResourceManager.Fluent.PolicyAssignmentsOperationsExtensions.CreateAsync(IPolicyAssignmentsOperations operations, String scope, String policyAssignmentName, PolicyAssignmentInner parameters, CancellationToken cancellationToken)
at Microsoft.Azure.Management.ResourceManager.Fluent.PolicyAssignmentImpl.CreateResourceAsync(CancellationToken cancellationToken)
at Microsoft.Azure.Management.ResourceManager.Fluent.Core.ResourceActions.Creatable`4.Microsoft.Azure.Management.ResourceManager.Fluent.Core.ResourceActions.IResourceCreator<IResourceT>.CreateResourceAsync(CancellationToken cancellationToken)
at Microsoft.Azure.Management.ResourceManager.Fluent.Core.DAG.CreatorTaskItem`1.ExecuteAsync(CancellationToken cancellationToken)
at Microsoft.Azure.Management.ResourceManager.Fluent.Core.DAG.TaskGroupBase`1.ExecuteNodeTaskAsync(DAGNode`1 node, CancellationToken cancellationToken)
at My Code Entry Points Here...
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseErrorReporting>b__20_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Hosting.HostingExtensions.<>c__DisplayClass1_0.<<UseHost>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass24_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__21_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseDirective>b__19_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__11_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass13_0.<<UseExceptionHandler>b__0>d.MoveNext()
To Reproduce Steps to reproduce the behavior:
var name = "name";
var policyDefinitionId = "/providers/Microsoft.Authorization/policyDefinitions/1e30110a-5ceb-460c-a204-c1c3969c6d62";
var scope = "/subscriptions/000 your sub id / etc... arm ID of policy assignment scope";
var assignment = await Azure!.PolicyAssignments.Define(name)
.ForScope(scope)
.WithPolicyDefinitionId(policyDefinitionId)
.WithDefaultMode()
.CreateAsync();
Code Snippet above code reproduces the error… update to Impl object would allow proper fluent api use
Expected behavior
var name = "name";
var policyDefinitionId = "/providers/Microsoft.Authorization/policyDefinitions/1e30110a-5ceb-460c-a204-c1c3969c6d62";
var scope = "/subscriptions/000 your sub id / etc... arm ID of policy assignment scope";
var parametersObject = new Dictionary<string, object> // not sure which object type would be best here... the .Inner object takes object.
{
{ "paramName1", "value" },
{ "paramName2", "value" }
};
var assignment = await Azure!.PolicyAssignments.Define(name)
.ForScope(scope)
.WithPolicyDefinitionId(policyDefinitionId)
.WithDefaultMode()
.WithParameters(parametersObject)
.CreateAsync();
Screenshots If applicable, add screenshots to help explain your problem.
Setup (please complete the following information):
- OS: [e.g. iOS] OS Independent (currently on Windows 10)
- IDE : [e.g. IntelliJ] IDE Independent (using Visual Studio 2019)
- Version of the Library used - Microsoft.Azure.Management.Fluent nuget pkg version 1.34
Additional context Add any other context about the problem here.
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- [ x] Bug Description Added
- [ x] Repro Steps Added
- [ x] Setup information Added
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Shouldn’t the nuget paid packages be marked deprecated, then?
Please close… Will use other packages.
Get Outlook for Androidhttps://aka.ms/ghei36
From: nickzhums notifications@github.com Sent: Friday, October 23, 2020 8:00:32 AM To: Azure/azure-libraries-for-net azure-libraries-for-net@noreply.github.com Cc: Scott Gorlick scgorlic@microsoft.com; Mention mention@noreply.github.com Subject: Re: [Azure/azure-libraries-for-net] [BUG] problem: PolicyAssignmentImpl does not expose .Inner.Parameters object. effect: cannot assign built in Azure Policies which take parameters (#1155)
@scottgorlickhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fscottgorlick&data=04|01|scgorlic%40microsoft.com|21e710a4727e4780821d08d8776463a4|72f988bf86f141af91ab2d7cd011db47|1|0|637390620344448504|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&sdata=dzwx%2B9JpgLNDsviMCvb%2BERTDYSjERXzfQl8CHnMnCQ0%3D&reserved=0 Hi Scott, .NET Fluent SDK is currently in maintenance mode and development focus shifted to new generation of .NET SDK which can be found here: https://azure.github.io/azure-sdk/releases/latest/mgmt/dotnet.htmlhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fazure.github.io%2Fazure-sdk%2Freleases%2Flatest%2Fmgmt%2Fdotnet.html&data=04|01|scgorlic%40microsoft.com|21e710a4727e4780821d08d8776463a4|72f988bf86f141af91ab2d7cd011db47|1|0|637390620344448504|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&sdata=wZn6QKjr36PDaMmAGzAk7HHzvAo0Jy%2BXsSakC5g8hzE%3D&reserved=0
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAzure%2Fazure-libraries-for-net%2Fissues%2F1155%23issuecomment-715395804&data=04|01|scgorlic%40microsoft.com|21e710a4727e4780821d08d8776463a4|72f988bf86f141af91ab2d7cd011db47|1|0|637390620344458494|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&sdata=nDAxvhzSkfJGLTVcnRul9bSdOb4o3WSbyCbEn9ASErs%3D&reserved=0, or unsubscribehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAMUYR5VSWDZCO7HELX3DXW3SMGLBBANCNFSM4S4BQ74A&data=04|01|scgorlic%40microsoft.com|21e710a4727e4780821d08d8776463a4|72f988bf86f141af91ab2d7cd011db47|1|0|637390620344468490|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|1000&sdata=93XalYaNQcOQ6Hhccf2BEtJ9ESQ0zJpOOE%2B4SFCRgIA%3D&reserved=0.
@scottgorlick Hi Scott, .NET Fluent SDK is currently in maintenance mode and development focus shifted to new generation of .NET SDK which can be found here: https://azure.github.io/azure-sdk/releases/latest/mgmt/dotnet.html