Skip to content
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

Deserialization fails for com.microsoft.azure.ExpressionEvaluationDetails class #708

Open
petr-lindovsky opened this issue Jan 3, 2022 · 0 comments

Comments

@petr-lindovsky
Copy link

The ExpressionEvaluationDetails class (https://github.com/Azure/autorest-clientruntime-for-java/blob/a869a9a68d5730e76a469bbe10d0e83b1a5532e3/azure-client-runtime/src/main/java/com/microsoft/azure/ExpressionEvaluationDetails.java) defines targetValue as List<String> but when calling

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}?api-version=2021-04-01

we see response bodies where targetValue is a String, which causes deserialization failures.

Please fix the class to cover such response bodies.

Example exception:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList<java.lang.Object>` out of VALUE_STRING token
 at [Source: (String)"{"policyDefinitionDisplayName":"Require a tag on resource groups","evaluationDetails":{"evaluatedExpressions":[{"result":"True","expressionKind":"Field","expression":"type","path":"type","expressionValue":"Microsoft.Resources/subscriptions/resourcegroups","targetValue":"Microsoft.Resources/subscriptions/resourceGroups","operator":"Equals"},{"result":"True","expressionKind":"Field","expression":"tags[Owner]","path":"tags[Owner]","targetValue":"false","operator":"Exists"}]},"policyDefinitionId":"/"[truncated 533 chars]; line: 1, column: 271] (through reference chain: com.microsoft.azure.CloudError["additionalInfo"]->java.util.ArrayList[0]->com.microsoft.azure.PolicyViolationErrorInfo["evaluationDetails"]->com.microsoft.azure.EvaluationDetails["evaluatedExpressions"]->java.util.ArrayList[0]->com.microsoft.azure.ExpressionEvaluationDetails["targetValue"])
        at rx.exceptions.Exceptions.propagate(Exceptions.java:57) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:463) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.observables.BlockingObservable.single(BlockingObservable.java:340) ~[rxjava-1.3.8.jar:1.3.8]
        at com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableUpdatableImpl.create(CreatableUpdatableImpl.java:252) ~[azure-mgmt-resources-1.41.2.jar:1.41.2]
        at com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableUpdatableImpl.create(CreatableUpdatableImpl.java:34) ~[azure-mgmt-resources-1.41.2.jar:1.41.2]
...

Example response body:

{
    "error": {
        "code": "RequestDisallowedByPolicy",
        "target": "myresourcegroup",
        "message": "Resource 'myresourcegroup' was disallowed by policy. Policy identifiers: '[{\"policyAssignment\":{\"name\":\"Require Owner tag on resource groups\",\"id\":\"/subscriptions/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/providers/Microsoft.Authorization/policyAssignments/cccccccccccccccccccccccc\"},\"policyDefinition\":{\"name\":\"Require a tag on resource groups\",\"id\":\"/providers/Microsoft.Authorization/policyDefinitions/bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb\"}}]'.",
        "additionalInfo": [
            {
                "type": "PolicyViolation",
                "info": {
                    "policyDefinitionDisplayName": "Require a tag on resource groups",
                    "evaluationDetails": {
                        "evaluatedExpressions": [
                            {
                                "result": "True",
                                "expressionKind": "Field",
                                "expression": "type",
                                "path": "type",
                                "expressionValue": "Microsoft.Resources/subscriptions/resourcegroups",
                                "targetValue": "Microsoft.Resources/subscriptions/resourceGroups",
                                "operator": "Equals"
                            },
                            {
                                "result": "True",
                                "expressionKind": "Field",
                                "expression": "tags[Owner]",
                                "path": "tags[Owner]",
                                "targetValue": "false",
                                "operator": "Exists"
                            }
                        ]
                    },
                    "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
                    "policyDefinitionName": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
                    "policyDefinitionEffect": "deny",
                    "policyAssignmentId": "/subscriptions/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/providers/Microsoft.Authorization/policyAssignments/cccccccccccccccccccccccc",
                    "policyAssignmentName": "cccccccccccccccccccccccc",
                    "policyAssignmentDisplayName": "Require Owner tag on resource groups",
                    "policyAssignmentScope": "/subscriptions/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
                }
            }
        ]
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant