Skip to content

Commit

Permalink
fix: environmental variables not expanded in command (#1241)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeidiDeng committed Jan 19, 2021
1 parent e6a5bf1 commit f3afd5c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ func (r *Runner) exec(raw, evt, path, dst string, user *users.User) error {
return err
}

envMapping := func(key string) string {
switch key {
case "FILE":
return path
case "SCOPE":
return user.Scope
case "TRIGGER":
return evt
case "USERNAME":
return user.Username
case "DESTINATION":
return dst
default:
return os.Getenv(key)
}
}
for i, arg := range command {
if i == 0 {
continue
}

command[i] = os.Expand(arg, envMapping)
}

cmd := exec.Command(command[0], command[1:]...) //nolint:gosec
cmd.Env = append(os.Environ(), fmt.Sprintf("FILE=%s", path))
cmd.Env = append(cmd.Env, fmt.Sprintf("SCOPE=%s", user.Scope)) //nolint:gocritic
Expand Down

0 comments on commit f3afd5c

Please sign in to comment.