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

[FEATURE REQ] - Export Policy as XML instead of RAWXML #488

Closed
Banchio opened this issue Feb 22, 2024 · 4 comments
Closed

[FEATURE REQ] - Export Policy as XML instead of RAWXML #488

Banchio opened this issue Feb 22, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@Banchio
Copy link

Banchio commented Feb 22, 2024

Please describe the feature.

After exporting from an existing APIM, it is not always possible to programmatically parse policies files as regular xml because of validation errors.
A possible solution would be to include a flag (both in extractor and publisher) to treat policies as regular xml files and not rawxml, something similar to the OpenApi yaml/json formats basically

Copy link

  Thank you for opening this issue! Please be patient while we will look into it and get back to you as this is an open source project. In the meantime make sure you take a look at the [closed issues](https://github.com/Azure/apiops/issues?q=is%3Aissue+is%3Aclosed) in case your question has already been answered. Don't forget to provide any additional information if needed (e.g. scrubbed logs, detailed feature requests,etc.).
  Whenever it's feasible, please don't hesitate to send a Pull Request (PR) our way. We'd greatly appreciate it, and we'll gladly assess and incorporate your changes.

@Banchio
Copy link
Author

Banchio commented Feb 22, 2024

By looking at the code I found that the parameter format=rawxml is added in every type involving Policies (ApiOperationPolicy, ApiPolicy, PolicyFragment, ProductPolicy and ServicePolicy). However it is not clear to me how to retrieve a new config setting from DI in the classes that use these records. Will try to do a debug step-by-step to better understand it.

@guythetechie
Copy link
Contributor

@Banchio - APIM policies support .NET code within the XML files through policy expressions. Here's an example:

<fragment>
  <set-header name="x-request-over-limit" exists-action="override">
    <value>
      @((context.LastError == null) && (int.Parse(context.Request.Headers["Limit"][0]) > 100) ? "Over limit" : "Under limit")
    </value>
  </set-header>
</fragment>

We use rawxml to support these usecases. xml encodes many characters and makes the underlying file harder to read. The fragment above would turn into this:

@((context.LastError == null) &amp;&amp; (int.Parse(context.Request.Headers[\"Limit\"][0]) &gt; 100) ? \"Over limit\" : \"Under limit\")

If you want to include an XML parsing step in your pipelines, I would suggest first running the file through a step to escape invalid XML characters, and then parsing the escaped file.

@Banchio
Copy link
Author

Banchio commented Feb 22, 2024

totally agree that is harder to read but in this format I cannot use Powershell select-xml statement (or anything else that expect a well formatted xml). I tried to replace double quotes within the @( and ) as well as double quotes between @{ and } but gave up on multi-line dotnet code which needed to be escaped.
Especially for programmatically parsing that would be great, I read your comment on the PR will retry when new version will be published then, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants