2014-08-15 12:29:35 -04:00
|
|
|
package builder
|
2014-08-05 16:17:40 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
TOKEN_ENV_INTERPOLATION = regexp.MustCompile("(\\\\\\\\+|[^\\\\]|\\b|\\A)\\$({?)([[:alnum:]_]+)(}?)")
|
|
|
|
)
|
|
|
|
|
2014-08-07 01:56:44 -04:00
|
|
|
// handle environment replacement. Used in dispatcher.
|
2014-08-26 15:25:44 -04:00
|
|
|
func (b *Builder) replaceEnv(str string) string {
|
2014-08-05 16:17:40 -04:00
|
|
|
for _, match := range TOKEN_ENV_INTERPOLATION.FindAllString(str, -1) {
|
|
|
|
match = match[strings.Index(match, "$"):]
|
|
|
|
matchKey := strings.Trim(match, "${}")
|
|
|
|
|
2014-08-13 06:07:41 -04:00
|
|
|
for _, keyval := range b.Config.Env {
|
|
|
|
tmp := strings.SplitN(keyval, "=", 2)
|
|
|
|
if tmp[0] == matchKey {
|
|
|
|
str = strings.Replace(str, match, tmp[1], -1)
|
2014-08-19 07:14:21 -04:00
|
|
|
break
|
2014-08-05 16:17:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return str
|
|
|
|
}
|
2014-08-13 06:07:41 -04:00
|
|
|
|
|
|
|
func handleJsonArgs(args []string, attributes map[string]bool) []string {
|
|
|
|
if attributes != nil && attributes["json"] {
|
|
|
|
return args
|
|
|
|
}
|
|
|
|
|
|
|
|
// literal string command, not an exec array
|
|
|
|
return append([]string{"/bin/sh", "-c", strings.Join(args, " ")})
|
|
|
|
}
|