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

apigeecli environments debugmask set uses POST instead of PATCH and does not handle JSON arrays correctly #530

Closed
narhen opened this issue Sep 4, 2024 · 3 comments · Fixed by #531
Labels
bug Something isn't working

Comments

@narhen
Copy link

narhen commented Sep 4, 2024

Version: apigeecli version 2.4.0 date: 2024-08-21T16:56:04Z [commit: e96358f]

When running the command:

apigeecli environments debugmask set --token <token> --org <organisation> --env <environment> --mask-file debugmask.json

with the contents of the debugmask.json being:

{
    "variables": [
        "request.header.x-api-key",
        "request.header.x-apikey"
    ]
}

(taken from the samples/debugmask.json file in the repository), the following error is thrown by apigeecli:

Error: json: cannot unmarshal array into Go value of type string

It seems that this happens because the tool is trying to deserialize the JSON into a string-string key-value pair, as seen in the following part of the code: https://github.com/apigee/apigeecli/blob/main/internal/client/env/debugmask.go#L35-L39.

When I modify the JSON file to specify a string key-value pair like this:

{
    "variables": "request.header.x-apikey"
}

the deserialization error disappears, but the command still fails, returning a 404 error page from Google:

Error: Not found - the server cannot find the requested resource

Reproduction Steps

  1. Run the following command:
apigeecli environments debugmask set --token <token> --org <organisation> --env <environment> --mask-file debugmask.json

With debugmask.json containing:

{
    "variables": [
        "request.header.x-api-key",
        "request.header.x-apikey"
    ]
}
  1. The following error occurs:
Error: json: cannot unmarshal array into Go value of type string
  1. After changing the debugmask.json to a string:
{
    "variables": "request.header.x-apikey"
}
  1. The command returns:
Error 404 (Not Found)

Additional Information

  • When running apigeecli in debug mode, it shows that a POST request is sent to the API:
APIGEECLI_DEBUG=true apigeecli environments debugmask set --token <token> --org example-org --env example-env --mask-file debugmask.json

Debug output:

DEBUG: Connecting to: POST - https://apigee.googleapis.com/v1/organizations/example-org/environments/example-env/debugmask

Suggested Fix

  • Change the HTTP method from POST to PATCH as per the official documentation.
  • Update the JSON handling logic to follow the correct structure from the documentation, where arrays like "variables" should be supported rather than string key-value pairs.
@srinandan srinandan linked a pull request Sep 4, 2024 that will close this issue
@srinandan srinandan added the bug Something isn't working label Sep 4, 2024
@srinandan
Copy link
Collaborator

Thanks for the detailed issue. I have created a fix, it will be part of v2.4.1

@ssvaidyanathan
Copy link
Collaborator

@narhen - pls test using 2.4.1 and let us know if you still see the issue.

@narhen
Copy link
Author

narhen commented Sep 5, 2024

Works perfectly with 2.4.1. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants