This commit is contained in:
adlerhurst
2025-08-07 10:52:57 +02:00
parent cc952c47a1
commit 866c2971f1
8 changed files with 342 additions and 12 deletions

View File

@@ -6,18 +6,20 @@ import (
"github.com/zitadel/zitadel/backend/v3/storage/database" "github.com/zitadel/zitadel/backend/v3/storage/database"
) )
type DomainValidationType string //go:generate enumer -type DomainValidationType -transform lower -trimprefix DomainValidationType -sql
type DomainValidationType uint8
const ( const (
DomainValidationTypeDNS DomainValidationType = "dns" DomainValidationTypeDNS DomainValidationType = iota
DomainValidationTypeHTTP DomainValidationType = "http" DomainValidationTypeHTTP
) )
type DomainType string //go:generate enumer -type DomainType -transform lower -trimprefix DomainType -sql
type DomainType uint8
const ( const (
DomainTypeCustom DomainType = "custom" DomainTypeCustom DomainType = iota
DomainTypeTrusted DomainType = "trusted" DomainTypeTrusted
) )
type domainColumns interface { type domainColumns interface {

View File

@@ -0,0 +1,109 @@
// Code generated by "enumer -type DomainType -transform lower -trimprefix DomainType -sql"; DO NOT EDIT.
package domain
import (
"database/sql/driver"
"fmt"
"strings"
)
const _DomainTypeName = "customtrusted"
var _DomainTypeIndex = [...]uint8{0, 6, 13}
const _DomainTypeLowerName = "customtrusted"
func (i DomainType) String() string {
if i >= DomainType(len(_DomainTypeIndex)-1) {
return fmt.Sprintf("DomainType(%d)", i)
}
return _DomainTypeName[_DomainTypeIndex[i]:_DomainTypeIndex[i+1]]
}
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _DomainTypeNoOp() {
var x [1]struct{}
_ = x[DomainTypeCustom-(0)]
_ = x[DomainTypeTrusted-(1)]
}
var _DomainTypeValues = []DomainType{DomainTypeCustom, DomainTypeTrusted}
var _DomainTypeNameToValueMap = map[string]DomainType{
_DomainTypeName[0:6]: DomainTypeCustom,
_DomainTypeLowerName[0:6]: DomainTypeCustom,
_DomainTypeName[6:13]: DomainTypeTrusted,
_DomainTypeLowerName[6:13]: DomainTypeTrusted,
}
var _DomainTypeNames = []string{
_DomainTypeName[0:6],
_DomainTypeName[6:13],
}
// DomainTypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func DomainTypeString(s string) (DomainType, error) {
if val, ok := _DomainTypeNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _DomainTypeNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to DomainType values", s)
}
// DomainTypeValues returns all values of the enum
func DomainTypeValues() []DomainType {
return _DomainTypeValues
}
// DomainTypeStrings returns a slice of all String values of the enum
func DomainTypeStrings() []string {
strs := make([]string, len(_DomainTypeNames))
copy(strs, _DomainTypeNames)
return strs
}
// IsADomainType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i DomainType) IsADomainType() bool {
for _, v := range _DomainTypeValues {
if i == v {
return true
}
}
return false
}
func (i DomainType) Value() (driver.Value, error) {
return i.String(), nil
}
func (i *DomainType) Scan(value interface{}) error {
if value == nil {
return nil
}
var str string
switch v := value.(type) {
case []byte:
str = string(v)
case string:
str = v
case fmt.Stringer:
str = v.String()
default:
return fmt.Errorf("invalid value of DomainType: %[1]T(%[1]v)", value)
}
val, err := DomainTypeString(str)
if err != nil {
return err
}
*i = val
return nil
}

View File

@@ -0,0 +1,109 @@
// Code generated by "enumer -type DomainValidationType -transform lower -trimprefix DomainValidationType -sql"; DO NOT EDIT.
package domain
import (
"database/sql/driver"
"fmt"
"strings"
)
const _DomainValidationTypeName = "dnshttp"
var _DomainValidationTypeIndex = [...]uint8{0, 3, 7}
const _DomainValidationTypeLowerName = "dnshttp"
func (i DomainValidationType) String() string {
if i >= DomainValidationType(len(_DomainValidationTypeIndex)-1) {
return fmt.Sprintf("DomainValidationType(%d)", i)
}
return _DomainValidationTypeName[_DomainValidationTypeIndex[i]:_DomainValidationTypeIndex[i+1]]
}
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _DomainValidationTypeNoOp() {
var x [1]struct{}
_ = x[DomainValidationTypeDNS-(0)]
_ = x[DomainValidationTypeHTTP-(1)]
}
var _DomainValidationTypeValues = []DomainValidationType{DomainValidationTypeDNS, DomainValidationTypeHTTP}
var _DomainValidationTypeNameToValueMap = map[string]DomainValidationType{
_DomainValidationTypeName[0:3]: DomainValidationTypeDNS,
_DomainValidationTypeLowerName[0:3]: DomainValidationTypeDNS,
_DomainValidationTypeName[3:7]: DomainValidationTypeHTTP,
_DomainValidationTypeLowerName[3:7]: DomainValidationTypeHTTP,
}
var _DomainValidationTypeNames = []string{
_DomainValidationTypeName[0:3],
_DomainValidationTypeName[3:7],
}
// DomainValidationTypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func DomainValidationTypeString(s string) (DomainValidationType, error) {
if val, ok := _DomainValidationTypeNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _DomainValidationTypeNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to DomainValidationType values", s)
}
// DomainValidationTypeValues returns all values of the enum
func DomainValidationTypeValues() []DomainValidationType {
return _DomainValidationTypeValues
}
// DomainValidationTypeStrings returns a slice of all String values of the enum
func DomainValidationTypeStrings() []string {
strs := make([]string, len(_DomainValidationTypeNames))
copy(strs, _DomainValidationTypeNames)
return strs
}
// IsADomainValidationType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i DomainValidationType) IsADomainValidationType() bool {
for _, v := range _DomainValidationTypeValues {
if i == v {
return true
}
}
return false
}
func (i DomainValidationType) Value() (driver.Value, error) {
return i.String(), nil
}
func (i *DomainValidationType) Scan(value interface{}) error {
if value == nil {
return nil
}
var str string
switch v := value.(type) {
case []byte:
str = string(v)
case string:
str = v
case fmt.Stringer:
str = v.String()
default:
return fmt.Errorf("invalid value of DomainValidationType: %[1]T(%[1]v)", value)
}
val, err := DomainValidationTypeString(str)
if err != nil {
return err
}
*i = val
return nil
}

View File

@@ -7,11 +7,12 @@ import (
"github.com/zitadel/zitadel/backend/v3/storage/database" "github.com/zitadel/zitadel/backend/v3/storage/database"
) )
type OrgState string //go:generate enumer -type OrgState -transform lower -trimprefix OrgState -sql
type OrgState uint8
const ( const (
OrgStateActive OrgState = "active" OrgStateActive OrgState = iota
OrgStateInactive OrgState = "inactive" OrgStateInactive
) )
type Organization struct { type Organization struct {

View File

@@ -0,0 +1,109 @@
// Code generated by "enumer -type OrgState -transform lower -trimprefix OrgState -sql"; DO NOT EDIT.
package domain
import (
"database/sql/driver"
"fmt"
"strings"
)
const _OrgStateName = "activeinactive"
var _OrgStateIndex = [...]uint8{0, 6, 14}
const _OrgStateLowerName = "activeinactive"
func (i OrgState) String() string {
if i >= OrgState(len(_OrgStateIndex)-1) {
return fmt.Sprintf("OrgState(%d)", i)
}
return _OrgStateName[_OrgStateIndex[i]:_OrgStateIndex[i+1]]
}
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _OrgStateNoOp() {
var x [1]struct{}
_ = x[OrgStateActive-(0)]
_ = x[OrgStateInactive-(1)]
}
var _OrgStateValues = []OrgState{OrgStateActive, OrgStateInactive}
var _OrgStateNameToValueMap = map[string]OrgState{
_OrgStateName[0:6]: OrgStateActive,
_OrgStateLowerName[0:6]: OrgStateActive,
_OrgStateName[6:14]: OrgStateInactive,
_OrgStateLowerName[6:14]: OrgStateInactive,
}
var _OrgStateNames = []string{
_OrgStateName[0:6],
_OrgStateName[6:14],
}
// OrgStateString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func OrgStateString(s string) (OrgState, error) {
if val, ok := _OrgStateNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _OrgStateNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to OrgState values", s)
}
// OrgStateValues returns all values of the enum
func OrgStateValues() []OrgState {
return _OrgStateValues
}
// OrgStateStrings returns a slice of all String values of the enum
func OrgStateStrings() []string {
strs := make([]string, len(_OrgStateNames))
copy(strs, _OrgStateNames)
return strs
}
// IsAOrgState returns "true" if the value is listed in the enum definition. "false" otherwise
func (i OrgState) IsAOrgState() bool {
for _, v := range _OrgStateValues {
if i == v {
return true
}
}
return false
}
func (i OrgState) Value() (driver.Value, error) {
return i.String(), nil
}
func (i *OrgState) Scan(value interface{}) error {
if value == nil {
return nil
}
var str string
switch v := value.(type) {
case []byte:
str = string(v)
case string:
str = v
case fmt.Stringer:
str = v.String()
default:
return fmt.Errorf("invalid value of OrgState: %[1]T(%[1]v)", value)
}
val, err := OrgStateString(str)
if err != nil {
return err
}
*i = val
return nil
}

View File

@@ -138,7 +138,7 @@ func (i instanceDomain) IsPrimaryCondition(isPrimary bool) database.Condition {
// TypeCondition implements [domain.InstanceDomainRepository]. // TypeCondition implements [domain.InstanceDomainRepository].
func (i instanceDomain) TypeCondition(typ domain.DomainType) database.Condition { func (i instanceDomain) TypeCondition(typ domain.DomainType) database.Condition {
return database.NewTextCondition(i.TypeColumn(true), database.TextOperationEqual, typ) return database.NewTextCondition(i.TypeColumn(true), database.TextOperationEqual, typ.String())
} }
// ------------------------------------------------------------- // -------------------------------------------------------------

View File

@@ -171,7 +171,7 @@ func (o org) InstanceIDCondition(instanceID string) database.Condition {
// StateCondition implements [domain.organizationConditions]. // StateCondition implements [domain.organizationConditions].
func (o org) StateCondition(state domain.OrgState) database.Condition { func (o org) StateCondition(state domain.OrgState) database.Condition {
return database.NewTextCondition(o.StateColumn(true), database.TextOperationEqual, state) return database.NewTextCondition(o.StateColumn(true), database.TextOperationEqual, state.String())
} }
// ------------------------------------------------------------- // -------------------------------------------------------------

View File

@@ -459,7 +459,7 @@ func TestGetOrganization(t *testing.T) {
ID: organizationId, ID: organizationId,
Name: organizationName, Name: organizationName,
InstanceID: instanceId, InstanceID: instanceId,
State: domain.OrgStateActive, State: domain.OrgStateInactive,
} }
// create organization // create organization