mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 05:52:51 +00:00
# Which Problems Are Solved In the context of moving our datastore to relational tables, Identity Provider Intents have no definition of a relational table nor any DB API that can be used to store the IDP intents as relational objects. # How the Problems Are Solved The PR follows the guidelines left in #11190 - A table `zitadel.identity_provider_intents` is created: it defines its relational constraints (foreign keys) with the other tables, as well as an ENUM to represent the state of the intent. - An IDP Intent repository has been created, which offers CRUD operations implemented as `Create`, `Get`, `Update` and `Delete` methods for the IDP intent. - The repository also defines all columns and conditions useful for performing DB operations on the IDP intents. - DB mocks have been added as well to ease testing on the `domain` package. - Reduction functions have been implemented for the existing IDP events so to keep the relational table in sync with the event store. # Additional Changes To allow testing LDAP intent flow, the `Session.FetchUser()` method has been extracted to a separate file. A corresponding mock has been created as well in `fetch_user_mock.go`. The files are mutually excluded and added at build time through go build tags: the mock is added when the `integration` tag is specified, while the real implementation is added when the same tag IS NOT added to the build tags. # Additional Context - Closes #11190 --------- Co-authored-by: Livio Spring <[email protected]> Co-authored-by: Silvan <[email protected]>
114 lines
3.0 KiB
Go
114 lines
3.0 KiB
Go
// Code generated by "enumer -type IDPIntentState -transform lower -trimprefix IDPIntentState -sql"; DO NOT EDIT.
|
|
|
|
package domain
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
const _IDPIntentStateName = "startedsucceededfailed"
|
|
|
|
var _IDPIntentStateIndex = [...]uint8{0, 7, 16, 22}
|
|
|
|
const _IDPIntentStateLowerName = "startedsucceededfailed"
|
|
|
|
func (i IDPIntentState) String() string {
|
|
if i >= IDPIntentState(len(_IDPIntentStateIndex)-1) {
|
|
return fmt.Sprintf("IDPIntentState(%d)", i)
|
|
}
|
|
return _IDPIntentStateName[_IDPIntentStateIndex[i]:_IDPIntentStateIndex[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 _IDPIntentStateNoOp() {
|
|
var x [1]struct{}
|
|
_ = x[IDPIntentStateStarted-(0)]
|
|
_ = x[IDPIntentStateSucceeded-(1)]
|
|
_ = x[IDPIntentStateFailed-(2)]
|
|
}
|
|
|
|
var _IDPIntentStateValues = []IDPIntentState{IDPIntentStateStarted, IDPIntentStateSucceeded, IDPIntentStateFailed}
|
|
|
|
var _IDPIntentStateNameToValueMap = map[string]IDPIntentState{
|
|
_IDPIntentStateName[0:7]: IDPIntentStateStarted,
|
|
_IDPIntentStateLowerName[0:7]: IDPIntentStateStarted,
|
|
_IDPIntentStateName[7:16]: IDPIntentStateSucceeded,
|
|
_IDPIntentStateLowerName[7:16]: IDPIntentStateSucceeded,
|
|
_IDPIntentStateName[16:22]: IDPIntentStateFailed,
|
|
_IDPIntentStateLowerName[16:22]: IDPIntentStateFailed,
|
|
}
|
|
|
|
var _IDPIntentStateNames = []string{
|
|
_IDPIntentStateName[0:7],
|
|
_IDPIntentStateName[7:16],
|
|
_IDPIntentStateName[16:22],
|
|
}
|
|
|
|
// IDPIntentStateString retrieves an enum value from the enum constants string name.
|
|
// Throws an error if the param is not part of the enum.
|
|
func IDPIntentStateString(s string) (IDPIntentState, error) {
|
|
if val, ok := _IDPIntentStateNameToValueMap[s]; ok {
|
|
return val, nil
|
|
}
|
|
|
|
if val, ok := _IDPIntentStateNameToValueMap[strings.ToLower(s)]; ok {
|
|
return val, nil
|
|
}
|
|
return 0, fmt.Errorf("%s does not belong to IDPIntentState values", s)
|
|
}
|
|
|
|
// IDPIntentStateValues returns all values of the enum
|
|
func IDPIntentStateValues() []IDPIntentState {
|
|
return _IDPIntentStateValues
|
|
}
|
|
|
|
// IDPIntentStateStrings returns a slice of all String values of the enum
|
|
func IDPIntentStateStrings() []string {
|
|
strs := make([]string, len(_IDPIntentStateNames))
|
|
copy(strs, _IDPIntentStateNames)
|
|
return strs
|
|
}
|
|
|
|
// IsAIDPIntentState returns "true" if the value is listed in the enum definition. "false" otherwise
|
|
func (i IDPIntentState) IsAIDPIntentState() bool {
|
|
for _, v := range _IDPIntentStateValues {
|
|
if i == v {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (i IDPIntentState) Value() (driver.Value, error) {
|
|
return i.String(), nil
|
|
}
|
|
|
|
func (i *IDPIntentState) 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 IDPIntentState: %[1]T(%[1]v)", value)
|
|
}
|
|
|
|
val, err := IDPIntentStateString(str)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
*i = val
|
|
return nil
|
|
}
|