Add support for reading XML files
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 474
- Forks
- 65
- Avg merge
- 22h 25m
- Merged PRs (30d)
- 26
Description
I would like to be able to read XML files so I can create custom rules to check the XML. In particular, I want to check my Azure API Management policies. We define our policies in separate XML files, so I would like to be able to load these and check them with PSRule.
An extra XML option for Input.Format would most likely be the best approach. Handling both elements & attributes might be a bit tricky, but both should be supported. Also note that elements with the same name can occur multiple times, while attribute names should be unique for a given element.
Alternatives I looked at:
The PSRule.Rules.Azure suite provides the Azure.APIM.PolicyBase rule that asserts the contents of a policy. This rule expects the policy XML to be defined directly in the Bicep file. We use separate XML files for our policies because these are more readable and maintainable. So, the approach used for Azure.APIM.PolicyBase doesn't work for us.
I've tried converting the Bicep into an JSON ARM template and then using a similar approach as is done by Azure.APIM.PolicyBase, but the policy contents is set via a generated variable as you can see in the sample below. Most likely because we use the loadTextContent Bicep function when loading the policy XML file.
"variables": {
"$fxv#1": "<policies>\r\n ... \r\n</policies>"
},
"resources": [
{
"type": "Microsoft.ApiManagement/service/apis/policies",
"apiVersion": "2022-08-01",
"name": "[format('{0}/{1}/{2}', parameters('apimResourceName'), parameters('apiName'), 'policy')]",
"properties": {
"format": "rawxml",
"value": "[variables('$fxv#1')]"
},
"dependsOn": [
"[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimResourceName'), parameters('apiName'))]"
]
},
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the Input.Format documentation and tracing how existing input formats are loaded in PSRule. Define the expected handling for XML elements, repeated element names, and attributes, then add coverage for the supported XML input behavior. Done means separate XML policy files can be loaded and checked by custom rules.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell, xml
- Domain
- devops, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100