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

APIM cannot retrieve policy using JavaScript SDK #31566

Closed
6 tasks
shivshankar1111 opened this issue Oct 28, 2024 · 16 comments
Closed
6 tasks

APIM cannot retrieve policy using JavaScript SDK #31566

shivshankar1111 opened this issue Oct 28, 2024 · 16 comments
Assignees
Labels
API Management customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-author-feedback Workflow: More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@shivshankar1111
Copy link

  • Package Name: JavaScript SDK
  • Package Version: latest stable
  • Operating system: windows
  • nodejs
    • version:
  • browser
    • name/version:
  • typescript
    • version:
  • Is the bug related to documentation :No

Describe the bug
A clear and concise description of what the bug is.
Hi this was logged to APIM team and was told to create a bug here. More details of the bug can be found in the internal icm portal
https://portal.microsofticm.com/imp/v5/incidents/details/557079604/summary

Cannot retrieve APIM API policy value using Azure SDK for JavaScript.

This is the customer verbose for full transparency:
We have issue with the APIM Javascript SDK
We try to read the policy in the API but we don't get back PolicyContract.

client.apiPolicy.get(
resourceGroupName,
serviceName,
apiId,
policyId,
{ format: 'rawxml' },
),

Does not return PolicyContract value

client: ApiManagementClient
library: '@azure/arm-apimanagement': '9.0.0'

--

'policyContract': { 'id': '/subscriptions/94486d6b-b366-4da1-b059-3883b469f51f/resourceGroups/apimgmt-dev-apim-we/providers/Microsoft.ApiManagement/service/apimgmt-dev-apim-01/apis/2895d73c-049e-405f-8c34-4a9d6f4eeef6/policies/policy', 'eTag': '\'AAAAAAAhguU=\'', 'name': 'policy', 'type': 'Microsoft.ApiManagement/service/apis/policies', 'format': 'xml' }

by contract it should return:
/** Current entity state version. Should be treated as opaque and used to make conditional HTTP requests. /
eTag?: string;
/
* Contents of the Policy as defined by the format. */
value?: string;

/** Format of the policyContent. */
format?: PolicyContentFormat;

To Reproduce
Steps to reproduce the behavior:

  1. Install VS Code, Node and NPM if you don't have them already. Node should include NPM as well, link: https://nodejs.org/en/download/package-manager
  2. Save the following code as "getPolicy.js" (make sure to replace your subscription ID and resource name)
  3. Log in to Azure CLI using the terminal in VS code: az login --tenant 16b3c013-d300-468d-ac64-7eda0820b6d3 (replace with your own tenant ID)
  4. Run it by using "node getPolicy.js" in the terminal:
    Image

Image

Expected behavior
A clear and concise description of what you expected to happen.
Expected behavior is for this to return the policy.
this is the documentation: https://learn.microsoft.com/en-us/javascript/api/@azure/arm-apimanagement/apipolicy?view=azure-node-latest#@azure-arm-apimanagement-apipolicy-get

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
log level was set to verbosity to get the exact call being made and made exactly the same request through postman and got the policy value so this seems contract mapping issue in the SDK code and need a fix.Image
same call postman
Image

@github-actions github-actions bot added API Management customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. labels Oct 28, 2024
Copy link

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @miaojiang.

@kazrael2119
Copy link
Contributor

will check

@kazrael2119
Copy link
Contributor

kazrael2119 commented Nov 1, 2024

I can repo this issue, and I tried to use rest api to investigate,
Image
but the result is not PolicyContract it only be the policy value

@shivshankar1111 I can't find the response from the screenshot of the log with verbosity level , could you re-upload?
another question, could you find any other properties in the response by using the postman? like etag, id ..

@xirzec xirzec added the needs-author-feedback Workflow: More information is needed from author to address the issue. label Nov 1, 2024
Copy link

github-actions bot commented Nov 1, 2024

Hi @shivshankar1111. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

@github-actions github-actions bot removed the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Nov 1, 2024
Copy link

github-actions bot commented Nov 8, 2024

Hi @shivshankar1111, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

@github-actions github-actions bot added the no-recent-activity There has been no recent activity on this issue. label Nov 8, 2024
@shivshankar1111
Copy link
Author

Yes looks like customer is looking for policy value as response.

@github-actions github-actions bot added needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-author-feedback Workflow: More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. labels Nov 11, 2024
@kazrael2119
Copy link
Contributor

kazrael2119 commented Nov 15, 2024

I try to set the request header like
Image
and the response is Image

service defined three content-type in rest https://github.com/Azure/azure-rest-api-specs/blob/main/specification/apimanagement/resource-manager/Microsoft.ApiManagement/stable/2022-08-01/apimapis.json#L2620-L2624

may have some issues in sdk analysis

@qiaozha
Copy link
Member

qiaozha commented Nov 15, 2024

@shivshankar1111 Can you try to create the client like below

import { parseXML } from "@azure/core-xml";
const client = new ApiManagementClient(credential, subscriptionId, { 
  deserializationOptions: { 
    expectedContentTypes: {
      xml:["application/vnd.ms-azure-apim.policy+xml"]
    },
    parseXML: parseXML
}} as any);

And pass the accept headers in the operation options

    const result = await client.apiPolicy.get(
      resourceGroup,
      resourcename,
      apiId,
      policyId,
      {format: "xml", requestOptions: {customHeaders: {Accept: "application/vnd.ms-azure-apim.policy+xml"}}}
    );

and see if it satisfies your requirement?

@xirzec I found the deserializationOptions are not really being exposed to our customer, that's why we have the as any in the above create client code, I wonder why? Are we expect customers to add their own deserialization policy instead of leveraging those options for cases like that? the reason it works because we didn't really filter those extra options out.

And core-client doesn't provide a default parser for xml kinda content type, however we do have core-xml library now, wonder if we should remove the limitation here

@xirzec
Copy link
Member

xirzec commented Nov 15, 2024

Is there value in the SDK actually parsing the XML value into JSON or can we simply return it to the customer as a string like how it is sent over the wire?

deserializationOptions is intended to be a private feature for SDK authors to configure advanced ServiceClient behavior when it comes to autorest generated mappers, not something that SDK consumers should have to worry about. This will go away completely once we move to TypeSpec/modular.

XML isn't built into core-client like it was in core-http since it was a very large dependency for the bundle size and most services do not need it.

@xirzec
Copy link
Member

xirzec commented Nov 15, 2024

The mapper even lists the value as a simple string:

export const PolicyContract: coreClient.CompositeMapper = {

export const PolicyContract: coreClient.CompositeMapper = {
  serializedName: "PolicyContract",
  type: {
    name: "Composite",
    className: "PolicyContract",
    modelProperties: {
      ...ProxyResource.type.modelProperties,
      value: {
        serializedName: "properties.value",
        xmlName: "properties.value",
        type: {
          name: "String"
        }
      },
      format: {
        defaultValue: "xml",
        serializedName: "properties.format",
        xmlName: "properties.format",
        type: {
          name: "String"
        }
      }
    }
  }
};

So it would work just fine, except the operation says it's XML when it's not:

I think if we removed isXML and xmlSerializer from the operation spec it would work as intended and produce a simple string value

@vlad610
Copy link

vlad610 commented Nov 20, 2024

Workaround is to use policy.lisByApi() method, which returns the policies, but requires more coding around it to parse the response

@kazrael2119
Copy link
Contributor

will try to remove isXML and try again

@kazrael2119
Copy link
Contributor

isXML: true,
I think if we removed isXML and xmlSerializer from the operation spec it would work as intended and produce a simple string value

it works if remove these two lines
Image

@kazrael2119
Copy link
Contributor

@shivshankar1111 we have released a new version here https://www.npmjs.com/package/@azure/arm-apimanagement/v/9.2.0 to fix this issue, could you try to use this package to verify? thanks

@kazrael2119 kazrael2119 added needs-author-feedback Workflow: More information is needed from author to address the issue. and removed Service Attention Workflow: This issue is responsible by Azure service team. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels Nov 26, 2024
Copy link

Hi @shivshankar1111. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

Copy link

github-actions bot commented Dec 3, 2024

Hi @shivshankar1111, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

@github-actions github-actions bot added the no-recent-activity There has been no recent activity on this issue. label Dec 3, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Management customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-author-feedback Workflow: More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

5 participants