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

refactor pipe script and improve debug mode #201

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions apps/scripts/pipe
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@

#main function that ends up being called by this client
function do_curl() {
curlCommand="curl -u $user -s $verbose -S $opts $server$uri"
if [ "$pipe_debug" ]; then
echo "$curlCommand"
set -x
fi
eval "$curlCommand"
curl \
--user $user \
--show-error --silent \
$verbose \
--form "$cmd" \
$opts \
$server$uri
}

#function to generate transform arg1=val1,arg2=val2 into {"arg1":"val1","arg2":"val2"}
Expand Down Expand Up @@ -66,8 +71,8 @@ if [ -z "$uri" ]; then
uri=/apps/dx/scripts/exec.$ext
fi
if [ -z "$verbose" ]; then
verbose=" --fail "
pipe_debug=1
verbose="--fail"
pipe_debug=true
fi

while [ $# -gt 0 ]; do
Expand All @@ -89,13 +94,13 @@ while [ $# -gt 0 ]; do
h) show_help; exit ;;
s) server=$2; shift ;;
u) user=$2; shift ;;
v) verbose=' -v '; shift ;;
d) opts="-F dryRun=true $opts";;
b) opts="-F bindings='`generate_json "$2"`' $opts"; shift ;;
v) verbose="--verbose"; shift ;;
d) opts="--form dryRun=true $opts";;
b) opts="--form bindings='$(generate_json "$2")' $opts"; shift ;;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukdz I observe that the bindings to the content script are failing with the latest pull.
For example:
./pipe test.txt -n 1000 -b modifiedDate=2023-08-30T10:20:20.206Z

The script generates curl command like this for the binding and the script at AEM is failing with binding parameter not availalble:
-form ‘bindings=‘\’‘{“modifiedDate”:“2023-08-30T10:20:20.206Z”}‘\’’'

cc: @npeltier

Copy link
Contributor Author

@lukdz lukdz Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested example providede:

$ ./pipe test.txt -n 1000 -b modifiedDate=2023-08-30T10:20:20.206Z
+ curl --user admin:admin --show-error --silent --fail --form pipe_cmd=test.txt --form 'bindings='\''{"modifiedDate":"2023-08-30T10:20:20.206Z"}'\''' --form size=1000 http://localhost:4502/apps/dx/scripts/exec.json

Reverting:

-                b)  opts="--form bindings='$(generate_json "$2")' $opts"; shift ;;
+                b)  opts="-F bindings='`generate_json "$2"`' $opts"; shift ;;

Doesn't change the result:

$ ./pipe test.txt -n 1000 -b modifiedDate=2023-08-30T10:20:20.206Z
+ curl --user admin:admin --show-error --silent --fail --form pipe_cmd=test.txt -F 'bindings='\''{"modifiedDate":"2023-08-30T10:20:20.206Z"}'\''' --form size=1000 http://localhost:4502/apps/dx/scripts/exec.json

But adding back eval:

-  curl \
+ eval curl \

Does change the result:

$ ./pipe test.txt -n 1000 -b modifiedDate=2023-08-30T10:20:20.206Z
+ eval curl --user admin:admin --show-error --silent --fail --form pipe_cmd=test.txt -F 'bindings='\''{"modifiedDate":"2023-08-30T10:20:20.206Z"}'\''' --form size=1000 http://localhost:4502/apps/dx/scripts/exec.json
++ curl --user admin:admin --show-error --silent --fail --form pipe_cmd=test.txt -F 'bindings={"modifiedDate":"2023-08-30T10:20:20.206Z"}' --form size=1000 http://localhost:4502/apps/dx/scripts/exec.json

Looks like eval is removing '\''.
The proper fix seems to be removal of single quotes:

-                b)  opts="--form bindings='$(generate_json "$2")' $opts"; shift ;;
+                b)  opts="--form bindings=$(generate_json "$2") $opts"; shift ;;

Which results in (without adding back eval):

$ ./pipe test.txt -n 1000 -b modifiedDate=2023-08-30T10:20:20.206Z
+ curl --user admin:admin --show-error --silent --fail --form pipe_cmd=test.txt --form 'bindings={"modifiedDate":"2023-08-30T10:20:20.206Z"}' --form size=1000 http://localhost:4502/apps/dx/scripts/exec.json

This fix would require validation from @praveenrv
afterwards, it can be merged: #202

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukdz thanks for the details and fix. I see it working after removing the single quotes.

opts="--form bindings=$(generate_json "$2") $opts"; shift ;;

test:

./pipe test.txt -n 1000 -b modifiedDate=2023-08-30T10:20:20.206Z
+ curl --user admin:admin --show-error --silent --fail --form [email protected] --form 'bindings={"modifiedDate":"2023-08-30T10:20:20.206Z"}' --form size=1000 http://localhost:4502/apps/dx/scripts/exec.json

cc: @npeltier 

c) uri=/apps/dx/scripts/exec.csv ;;
n) opts="-F size=$2 $opts"; shift ;;
f) opts="-F pipes_inputFile=@$2"; shift ;;
o) opts="-F writer=$2 $opts"; shift ;;
n) opts="--form size=$2 $opts"; shift ;;
f) opts="--form pipes_inputFile=@$2"; shift ;;
o) opts="--form writer=$2 $opts"; shift ;;
*) userfail "Unrecognized option." ;;
esac
done
Expand All @@ -107,9 +112,9 @@ while [ $# -gt 0 ]; do
done

if [ -f "$cmd" ]; then
opts="-F pipe_cmdfile=@$cmd $opts"
do_curl
cmd="pipe_cmdfile=@$cmd"
else
opts="-F pipe_cmd=\"$cmd\" $opts"
do_curl
cmd="pipe_cmd=$cmd"
fi

do_curl
Loading