aws / aws-cli

Universal Command Line Interface for Amazon Web Services
Other
15.6k stars 4.14k forks source link

Bug on CLI input parsing #7502

Open manickgm opened 1 year ago

manickgm commented 1 year ago

Describe the bug

When the short hard syntax has open and closed curly braces in one of the values to the key, the CLI throws following error.

awscli.argprocess.ParamError: Error parsing parameter '--patch-operations': Expected: ',', received: '}' for input:

Expected Behavior

CLI should process the string value as it is.

Current Behavior

@https://github.com/aws/aws-cli/blob/9b6e981407138dc21c4546be10b3eba2a3a61740/awscli/shorthand.py#L136

at this line, regex computed only takes till the closed parenthesis.

e.g, for a key-value of

value=arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:xxxxxxxxxx:function:Say-hello-world:${stageVariables.version}/invocations

value extracted by the regex is 'arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:xxxxxxxxxx:function:Say-hello-world:${stageVariables.version'

Reproduction Steps

Create API Gateway REST API with a resource path and method with lambda integration.

try the following command: newuri='arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:xxxxxxxxxx:function:Say-hello-world:${stageVariables.version}/invocations'

aws apigateway update-integration --rest-api-id xxxxxx --resource-id xxxxx --http-method ANY --patch-operation op="replace",path="/uri",value="$newuri" --debug

This command gives following output:

Traceback (most recent call last):
  File "/usr/local/Cellar/awscli/2.8.13/libexec/lib/python3.11/site-packages/awscli/argprocess.py", line 345, in _parse_as_shorthand
    parsed = [self._parser.parse(v) for v in value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/awscli/2.8.13/libexec/lib/python3.11/site-packages/awscli/argprocess.py", line 345, in <listcomp>
    parsed = [self._parser.parse(v) for v in value]
              ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/awscli/2.8.13/libexec/lib/python3.11/site-packages/awscli/shorthand.py", line 172, in parse
    return self._parameter()
           ^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/awscli/2.8.13/libexec/lib/python3.11/site-packages/awscli/shorthand.py", line 181, in _parameter
    self._expect(',', consume_whitespace=True)
  File "/usr/local/Cellar/awscli/2.8.13/libexec/lib/python3.11/site-packages/awscli/shorthand.py", line 355, in _expect
    raise ShorthandParseSyntaxError(self._input_value, char,
awscli.shorthand.ShorthandParseSyntaxError: Expected: ',', received: '}' for input:
op=replace,path=/uri,value=arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:xxxxxxxx:function:Say-hello-world:${stageVariables.version}/invocations

Possible Solution

This problem does not occur when the value is quoted.

Additional Information/Context

No response

CLI version used

aws-cli/2.8.13 Python/3.11.0 Darwin/21.6.0 source/x86_64 prompt/off

Environment details (OS name and version, etc.)

MacOS

RyanFitzSimmonsAK commented 1 year ago

Hi @manickgm, thanks for raising this issue. I was able to reproduce this bug; any shorthand parameter containing a ']' or a '}' threw an error. I'll raise this issue with the team.