2022-04-05 05:58:09 +00:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2022-05-16 09:26:24 +00:00
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
domainRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
2022-04-05 05:58:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type InstanceDomainState int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
InstanceDomainStateUnspecified InstanceDomainState = iota
|
|
|
|
InstanceDomainStateActive
|
|
|
|
InstanceDomainStateRemoved
|
|
|
|
|
|
|
|
instanceDomainStateCount
|
|
|
|
)
|
|
|
|
|
|
|
|
func (f InstanceDomainState) Valid() bool {
|
|
|
|
return f >= 0 && f < instanceDomainStateCount
|
|
|
|
}
|
|
|
|
|
2022-04-14 12:19:18 +00:00
|
|
|
func (f InstanceDomainState) Exists() bool {
|
|
|
|
return f == InstanceDomainStateActive
|
|
|
|
}
|
|
|
|
|
2022-05-16 09:26:24 +00:00
|
|
|
func NewGeneratedInstanceDomain(instanceName, iamDomain string) (string, error) {
|
|
|
|
randomString, err := crypto.GenerateRandomString(6, domainRunes)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2022-04-21 10:37:39 +00:00
|
|
|
instanceName = strings.TrimSpace(instanceName)
|
2022-05-16 09:26:24 +00:00
|
|
|
return strings.ToLower(strings.ReplaceAll(instanceName, " ", "-") + "-" + randomString + "." + iamDomain), nil
|
2022-04-05 05:58:09 +00:00
|
|
|
}
|