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

JSONPath not fully supported in CLI #199

Open
lukeemery opened this issue Jan 2, 2022 · 1 comment
Open

JSONPath not fully supported in CLI #199

lukeemery opened this issue Jan 2, 2022 · 1 comment
Labels
bug This issue is a bug. module/cli-ext p2 This is a standard priority issue queued

Comments

@lukeemery
Copy link

Description

Template substitutions use JSONPath, which supports adding filters. Filters may include operators such as the equal sign. The underlying key-value utility will break on every = and ;

Reproduce using dotnet lambda package-ci --output-template test.json --template-substitutions "$.Resources.*.[?(@.Type =~ 'AWS::Serverless::Function')].Properties=test"

Newtonsoft support doc: https://www.newtonsoft.com/json/help/html/QueryJsonSelectTokenJsonPath.htm

Stack Trace

Processing 1 substitutions.
Processing substitution: $.Resources.*.[?(@.Type 
Unknown error executing command: Path ended with open query.
   at Newtonsoft.Json.Linq.JsonPath.JPath.EnsureLength(String message)
   at Newtonsoft.Json.Linq.JsonPath.JPath.ParseSide()
   at Newtonsoft.Json.Linq.JsonPath.JPath.ParseExpression()
   at Newtonsoft.Json.Linq.JsonPath.JPath.ParseQuery(Char indexerCloseChar, Boolean scan)
   at Newtonsoft.Json.Linq.JsonPath.JPath.ParsePath(List`1 filters, Int32 currentPartStartIndex, Boolean query)
   at Newtonsoft.Json.Linq.JsonPath.JPath.ParseMain()
   at Newtonsoft.Json.Linq.JToken.SelectToken(String path, Boolean errorWhenNoMatch)
   at Amazon.Lambda.Tools.LambdaUtilities.ProcessTemplateSubstitions(IToolLogger logger, String templateBody, IDictionary`2 substitutions, String workingDirectory) in C:\codebuild\tmp\output\src181780091\src\src\Amazon.Lambda.Tools\LambdaUtilities.cs:line 139
   at Amazon.Lambda.Tools.Commands.PackageCICommand.PerformActionAsync() in C:\codebuild\tmp\output\src181780091\src\src\Amazon.Lambda.Tools\Commands\PackageCICommand.cs:line 115
   at Amazon.Common.DotNetCli.Tools.Commands.BaseCommand`1.ExecuteAsync() in C:\codebuild\tmp\output\src181780091\src\src\Amazon.Common.DotNetCli.Tools\Commands\BaseCommand.cs:line 46

Location

templateBody = LambdaUtilities.ProcessTemplateSubstitions(this.Logger, templateBody, this.GetKeyValuePairOrDefault(this.TemplateSubstitutions, LambdaDefinedCommandOptions.ARGUMENT_CLOUDFORMATION_TEMPLATE_SUBSTITUTIONS, false), Utilities.DetermineProjectLocation(this.WorkingDirectory, projectLocation));

public Dictionary<string, string> GetKeyValuePairOrDefault(Dictionary<string, string> propertyValue, CommandOption option, bool required)

public static Dictionary<string, string> ParseKeyValueOption(string option)
{
var parameters = new Dictionary<string, string>();
if (string.IsNullOrWhiteSpace(option))
return parameters;
try
{
var currentPos = 0;
while (currentPos != -1 && currentPos < option.Length)
{
string name;
GetNextToken(option, '=', ref currentPos, out name);
string value;
GetNextToken(option, ';', ref currentPos, out value);
if (string.IsNullOrEmpty(name))
throw new ToolsException($"Error parsing option ({option}), format should be <key1>=<value1>;<key2>=<value2>", ToolsException.CommonErrorCode.CommandLineParseError);

@lukeemery lukeemery changed the title JsonPath JSONPath not fully supported in CLI Jan 2, 2022
@aaoswal aaoswal added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. module/cli-ext labels Jan 3, 2022
@ashishdhingra ashishdhingra added feature-request A feature should be added or improved. A bug This issue is a bug. needs-reproduction This issue needs reproduction. and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. feature-request A feature should be added or improved. labels Jan 7, 2022
@ashishdhingra ashishdhingra added p2 This is a standard priority issue and removed A labels Nov 1, 2022
@ashishdhingra
Copy link
Contributor

Reproducible

@ashishdhingra ashishdhingra removed the needs-reproduction This issue needs reproduction. label Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. module/cli-ext p2 This is a standard priority issue queued
Projects
None yet
Development

No branches or pull requests

4 participants