-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Insufficient documentation or examples for parameters
in policy_assignments.update_by_id
#38909
Comments
Thanks for your feedback. @ChenxiJiang333 Please help to clarify @mlcooper's question about how to set |
got it |
Hi @mlcooper, operation |
I believe that the fact I should have been using I found that in the New Error:
Code used: policy_client = PolicyClient(
api_version="2023-04-01",
credential=credential,
subscription_id=os.getenv("SUBSCRIPTION_ID"),
)
policy_assignment_ids = [
{
f"providers/Microsoft.Management/managementGroups/{os.getenv("TENANT_ID")}/providers/Microsoft.Authorization/policyAssignments/AiModelControlBuiltInCst": "allowedModels"
},
{
f"providers/Microsoft.Management/managementGroups/{os.getenv("TENANT_ID")}/providers/Microsoft.Authorization/policyAssignments/AiModelControlBuiltIn": "allowedAssetIds"
},
]
for dict_item in policy_assignment_ids:
for assignment, v in dict_item.items():
k = policy_client.policy_assignments.get_by_id(
policy_assignment_id=assignment
)
policy_definition_id = k.policy_definition_id
m = k.parameters[v]
current_models = m.value
new_models = np.setdiff1d(
new_model_list, current_models, assume_unique=True
).tolist()
if len(new_models) > 0:
print(f"new models to add: {new_models}")
update_response = policy_client.policy_assignments.create_by_id(
policy_assignment_id=assignment,
parameters={
"parameters": {v: {"value": new_models}, "effect": "Deny"},
"policyDefinitionId": policy_definition_id,
},
)
r = update_response.parameters
resp = r[v]
print(resp)
print("\n") I have tried many things to fix this error, but none of it has worked. Can you please tell me what the error is complaining about? |
Hi @mlcooper, try update code
|
Thank you, this helped me to fix it, and I can now update the Array I have in one of my parameters. However, when I update it, it overwrites the array instead of doing a Is there a |
I'm afraid you cannot do it through SDK. If you don't want to overwrite the old policy assignment, I guess to create a new one with newly added items would share the same effect. And I'm sorry for not pointing out a mistake last time that policy effects are used in policy definitions & overrides creation (see: https://learn.microsoft.com/en-us/azure/governance/policy/concepts/effect-basics), they would not take any efforts in this code, so |
If I remove
|
My bad, seems the |
Thanks for your help with this issue. My script is working now. I do feel that documentation for the API methods discussed above could be improved.
|
Hi @mlcooper, sdk is auto generated by swagger definition, so we can not make any change on it. I have transferred your advice to the service team, please follow: Azure/azure-rest-api-specs#31956. Once swagger is fixed, python SDK will release new version to support it. |
Type of issue
Missing information
Description
My goal is to update a parameter of a policy with the
policy_assignments.update_by_id
method. The parameter happens to be of type Array (of strings).My code executes cleanly, and I print the response successfully. No errors are returned. It is very unclear from the documentation about what content should go into the
parameters
parameter. Is it the full JSON structure of the Azure Policy and I only specify what I want to change in theparameter
of the policy I am interested in? Is it just the name of theparameter
in the policy and the value I want to add to its array? I have tried many different variations of the JSON in theparameters
of this method, however none of them have been successful.Why is my code not returning any errors if it fails to update the values in the array of the parameter?
No examples are given of
policy_assignments.update_by_id
in the examples repo maintained by Microsoft.My code:
The response:
The model,
'mlc,1'
is NOT successfully added to the parameter, which is an Array, in either of the policies I'm trying to update. No error is given. No logging is available.The lack of documentation has made this a bit more difficult than I had expected.
Page URL
https://learn.microsoft.com/en-us/python/api/azure-mgmt-resource/azure.mgmt.resource.policy.v2023_04_01.operations.policyassignmentsoperations?view=azure-python
Content source URL
https://github.com/MicrosoftDocs/azure-docs-sdk-python/blob/main/docs-ref-autogen/azure-mgmt-resource/azure.mgmt.resource.policy.v2023_04_01.operations.PolicyAssignmentsOperations.yml
Document Version Independent Id
a80f2b64-ba8e-f571-9d2c-e7d0fcb9ac40
Article author
@lmazuel
Metadata
The text was updated successfully, but these errors were encountered: