github.com/jerryclinesmith/packer@v0.3.7/builder/amazon/common/template_funcs.go (about) 1 package common 2 3 import ( 4 "bytes" 5 "text/template" 6 ) 7 8 func isalphanumeric(b byte) bool { 9 if '0' <= b && b <= '9' { 10 return true 11 } 12 if 'a' <= b && b <= 'z' { 13 return true 14 } 15 if 'A' <= b && b <= 'Z' { 16 return true 17 } 18 return false 19 } 20 21 // Clean up AMI name by replacing invalid characters with "-" 22 func templateCleanAMIName(s string) string { 23 allowed := []byte{'(', ')', ',', '/', '-', '_'} 24 b := []byte(s) 25 newb := make([]byte, len(b)) 26 for i, c := range b { 27 if isalphanumeric(c) || bytes.IndexByte(allowed, c) != -1 { 28 newb[i] = c 29 } else { 30 newb[i] = '-' 31 } 32 } 33 return string(newb[:]) 34 } 35 36 var TemplateFuncs = template.FuncMap{ 37 "clean_ami_name": templateCleanAMIName, 38 }