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

Fix double quoted expression stmts #488

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
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
42 changes: 42 additions & 0 deletions examples/grpc-samples/deploy-helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export PROJECT_PATH="$( dirname $( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) )"
Copy link
Collaborator

Choose a reason for hiding this comment

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

@sourishkrout are you sure you want to keep this file?

Copy link
Member Author

@sourishkrout sourishkrout Feb 5, 2024

Choose a reason for hiding this comment

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

export PROJECT_ID="$( gcloud config get-value project --format="value(.)" )"
export REGION="us-central1"

if [[ -z "$PROJECT_ID" ]]; then
echo "Set a gcloud project (via gcloud config or CLOUDSDK_CORE_PROJECT)" >&2
exit 1
fi

if ! python3 -c 'import cleverhans' &>/dev/null; then
echo "Run in project environment" >&2
exit 1
fi

prompt_deploy() {
read -p "Deploy ${JOB_NAME} to ${PROJECT_ID} [y/N]? " -n 1 -r
if [[ ! "$REPLY" =~ ^[Yy]$ ]]; then
exit 1
fi
echo
}

build_dist() {
rm -rf build dist
python3 setup.py sdist
}

build_dovecotes() {
pushd "$PROJECT_PATH/dovecotes" &>/dev/null
build_dist &>/dev/null
popd &>/dev/null
ls "$PROJECT_PATH/dovecotes/dist/"dovecotes-*.tar.gz
}

deploy() {
if [[ -n "${DEBUG:=}" ]]; then
echo "$@"
exit 0
else
exec "$@"
fi
}
24 changes: 23 additions & 1 deletion examples/grpc-samples/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,33 @@ $ grpcurl \

Resolve variables inside cell:

```sh {"id":"01HNGQS6TV8YKQAKE0ZD7TZREH","promptEnv":"false","terminalRows":"15"}
```sh {"id":"01HNGQS6TV8YKQAKE0ZD7TZREH","promptEnv":"false","terminalRows":"20"}
$ grpcurl \
-cacert /tmp/runme/tls/cert.pem \
-cert /tmp/runme/tls/cert.pem \
-key /tmp/runme/tls/key.pem \
-d @ \
127.0.0.1:9999 runme.runner.v1.RunnerService/ResolveVars < resolve-vars.json
```

### Complex script

```javascript {"id":"01HNQWVXY92G9KC9VYB17EMNR4","interactive":"false"}
const fs = require('node:fs')

const bytes = fs.readFileSync('./deploy-helpers.sh')
const payload = { script: bytes.toString('utf-8') }
const serialized = JSON.stringify(payload)

fs.writeFileSync('complex-script.json', serialized)
console.log(serialized)
```

```sh {"id":"01HNQVQB1H16B9QNV49BR0EJYY","promptEnv":"false","terminalRows":"15"}
grpcurl \
-cacert /tmp/runme/tls/cert.pem \
-cert /tmp/runme/tls/cert.pem \
-key /tmp/runme/tls/key.pem \
-d @ \
127.0.0.1:9999 runme.runner.v1.RunnerService/ResolveVars < complex-script.json
```
8 changes: 7 additions & 1 deletion internal/command/env_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ func (r *EnvResolver) findOriginalValue(decl *syntax.DeclClause) string {
// export FOO="bar"
case *syntax.DblQuoted:
if len(part.Parts) == 1 {
return part.Parts[0].(*syntax.Lit).Value
p, ok := part.Parts[0].(*syntax.Lit)
// break for quoted stmt, ie non-literal
// export FOO="$( echo 'this is a test' )"
if !ok {
break
}
return p.Value
}
// export FOO='bar'
case *syntax.SglQuoted:
Expand Down
7 changes: 7 additions & 0 deletions internal/command/env_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ func TestEnvResolverParsing(t *testing.T) {
{Name: "TEST_VALUE_EXPR"},
},
},
{
name: "double quoted value expression",
data: `export TEST_DBL_QUOTE_VALUE_EXPR="$(echo -n 'value')"`,
result: []*EnvResolverResult{
{Name: "TEST_DBL_QUOTE_VALUE_EXPR"},
},
},
{
name: "default value",
data: `export TEST_DEFAULT_VALUE=${TEST_DEFAULT_VALUE:-value}`,
Expand Down
Loading