2021-01-08 11:33:45 +01:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
2021-04-19 16:43:36 +02:00
|
|
|
"strings"
|
|
|
|
|
2021-01-18 11:24:15 +01:00
|
|
|
http_util "github.com/caos/zitadel/internal/api/http"
|
2021-01-08 11:33:45 +01:00
|
|
|
"github.com/caos/zitadel/internal/crypto"
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
2021-01-08 11:33:45 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type OrgDomain struct {
|
|
|
|
models.ObjectRoot
|
|
|
|
|
|
|
|
Domain string
|
|
|
|
Primary bool
|
|
|
|
Verified bool
|
|
|
|
ValidationType OrgDomainValidationType
|
|
|
|
ValidationCode *crypto.CryptoValue
|
|
|
|
}
|
|
|
|
|
2021-01-18 11:24:15 +01:00
|
|
|
func (domain *OrgDomain) IsValid() bool {
|
2021-03-19 11:12:56 +01:00
|
|
|
return domain.Domain != ""
|
2021-01-18 11:24:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (domain *OrgDomain) GenerateVerificationCode(codeGenerator crypto.Generator) (string, error) {
|
|
|
|
validationCodeCrypto, validationCode, err := crypto.NewCode(codeGenerator)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
domain.ValidationCode = validationCodeCrypto
|
|
|
|
return validationCode, nil
|
|
|
|
}
|
|
|
|
|
2021-04-19 16:43:36 +02:00
|
|
|
func NewIAMDomainName(orgName, iamDomain string) string {
|
|
|
|
return strings.ToLower(strings.ReplaceAll(orgName, " ", "-") + "." + iamDomain)
|
|
|
|
}
|
|
|
|
|
2021-01-08 11:33:45 +01:00
|
|
|
type OrgDomainValidationType int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
OrgDomainValidationTypeUnspecified OrgDomainValidationType = iota
|
|
|
|
OrgDomainValidationTypeHTTP
|
|
|
|
OrgDomainValidationTypeDNS
|
|
|
|
)
|
|
|
|
|
2021-01-18 11:24:15 +01:00
|
|
|
func (t OrgDomainValidationType) CheckType() (http_util.CheckType, bool) {
|
|
|
|
switch t {
|
|
|
|
case OrgDomainValidationTypeHTTP:
|
|
|
|
return http_util.CheckTypeHTTP, true
|
|
|
|
case OrgDomainValidationTypeDNS:
|
|
|
|
return http_util.CheckTypeDNS, true
|
|
|
|
default:
|
|
|
|
return -1, false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-08 11:33:45 +01:00
|
|
|
type OrgDomainState int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
OrgDomainStateUnspecified OrgDomainState = iota
|
|
|
|
OrgDomainStateActive
|
|
|
|
OrgDomainStateRemoved
|
|
|
|
|
|
|
|
orgDomainStateCount
|
|
|
|
)
|
|
|
|
|
|
|
|
func (f OrgDomainState) Valid() bool {
|
|
|
|
return f >= 0 && f < orgDomainStateCount
|
|
|
|
}
|