diff --git a/examples/grpc-samples/deploy-helpers.sh b/examples/grpc-samples/deploy-helpers.sh new file mode 100644 index 000000000..256fd5eac --- /dev/null +++ b/examples/grpc-samples/deploy-helpers.sh @@ -0,0 +1,42 @@ +export PROJECT_PATH="$( dirname $( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) )" +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 +} diff --git a/examples/grpc-samples/services.md b/examples/grpc-samples/services.md index 181c6fc14..81411e961 100644 --- a/examples/grpc-samples/services.md +++ b/examples/grpc-samples/services.md @@ -55,7 +55,7 @@ $ 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 \ @@ -63,3 +63,25 @@ $ grpcurl \ -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 +``` diff --git a/internal/command/env_resolver.go b/internal/command/env_resolver.go index 92d65ebd6..5f0a30921 100644 --- a/internal/command/env_resolver.go +++ b/internal/command/env_resolver.go @@ -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: diff --git a/internal/command/env_resolver_test.go b/internal/command/env_resolver_test.go index d448597c6..4b725c6da 100644 --- a/internal/command/env_resolver_test.go +++ b/internal/command/env_resolver_test.go @@ -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}`,