Download this file
| 1 | // Package controlname validates identifiers used as control-plane key segments. |
| 2 | package controlname |
| 3 | |
| 4 | import ( |
| 5 | "regexp" |
| 6 | "strings" |
| 7 | ) |
| 8 | |
| 9 | var ( |
| 10 | account = regexp.MustCompile(`^[a-z]{3,16}$`) |
| 11 | app = regexp.MustCompile(`^[a-z][a-z0-9-]{0,31}$`) |
| 12 | label = regexp.MustCompile(`^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$`) |
| 13 | ) |
| 14 | |
| 15 | func ValidAccount(s string) bool { return account.MatchString(s) } |
| 16 | func ValidApp(s string) bool { return app.MatchString(s) } |
| 17 | func ValidLabel(s string) bool { return label.MatchString(s) } |
| 18 | func ValidHostShape(host string) bool { |
| 19 | if host == "" || len(host) > 253 { |
| 20 | return false |
| 21 | } |
| 22 | for _, part := range strings.Split(host, ".") { |
| 23 | if !ValidLabel(part) { |
| 24 | return false |
| 25 | } |
| 26 | } |
| 27 | return true |
| 28 | } |
| 29 | |