carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1// Package controlname validates identifiers used as control-plane key segments.
2package controlname
3
4import (
5 "regexp"
6 "strings"
7)
8
9var (
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
15func ValidAccount(s string) bool { return account.MatchString(s) }
16func ValidApp(s string) bool { return app.MatchString(s) }
17func ValidLabel(s string) bool { return label.MatchString(s) }
18func 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