Skip to content

Commit cba52ae

Browse files
authored
Merge pull request #1115 from jmpsec/fix-provision-quick-add
Fix `provision.sh` running a CLI error as a command
2 parents e65598f + 7a48717 commit cba52ae

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎cmd/cli/environment.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func quickAddEnvironment(ctx context.Context, cmd *cli.Command) error {
366366
// Get environment name
367367
envName := cmd.String("name")
368368
if envName == "" {
369-
fmt.Println("❌ environment name is required")
369+
fmt.Fprintln(os.Stderr, "❌ environment name is required")
370370
os.Exit(1)
371371
}
372372
var env environments.TLSEnvironment
@@ -389,7 +389,7 @@ func quickAddEnvironment(ctx context.Context, cmd *cli.Command) error {
389389
case targetPowershell:
390390
oneLiner, _ = environments.QuickAddOneLinerPowershell(insecure, env)
391391
default:
392-
fmt.Printf("❌ invalid target! It can be %s or %s\n", targetShell, targetPowershell)
392+
fmt.Fprintf(os.Stderr, "❌ invalid target! It can be %s or %s\n", targetShell, targetPowershell)
393393
os.Exit(1)
394394
}
395395
fmt.Printf("%s\n", oneLiner)

‎cmd/cli/main.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2316,6 +2316,9 @@ func main() {
23162316
}
23172317
// Run the app
23182318
if err := app.Run(context.Background(), os.Args); err != nil {
2319-
log.Fatal().Msgf("❌ %v", err)
2319+
// Errors go to stderr: stdout can carry output meant to be run or piped
2320+
// (for example the quick-add one-liner).
2321+
fmt.Fprintf(os.Stderr, "❌ %v\n", err)
2322+
os.Exit(1)
23202323
}
23212324
}

‎deploy/provision.sh‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,14 @@ else
680680
# Enroll host in environment
681681
if [[ "$ENROLL" == true ]]; then
682682
log "Adding host in environment $ENVIRONMENT"
683-
eval $( "$DEST_PATH"/bin/osctrl-cli --db -D "$__db_conf" env node-actions -n "$ENVIRONMENT" quick-add)
683+
# Run the one-liner only if osctrl-cli produced it. A failure prints its
684+
# error instead of the one-liner, and that must never reach eval.
685+
if ! __quick_add=$("$DEST_PATH"/bin/osctrl-cli --db -D "$__db_conf" env node-actions -n "$ENVIRONMENT" quick-add 2>&1); then
686+
log "Could not generate the quick-add one-liner for environment $ENVIRONMENT:"
687+
echo "$__quick_add"
688+
exit 1
689+
fi
690+
eval "$__quick_add"
684691
fi
685692
fi
686693

0 commit comments

Comments
 (0)