这是indexloc提供的服务,不要输入任何密码
Skip to content

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

@narhen

Description

@narhen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions