2020-04-21 17:00:32 +02:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2020-06-15 16:50:09 +02:00
|
|
|
"github.com/golang/protobuf/ptypes/timestamp"
|
2021-02-17 15:31:47 +01:00
|
|
|
|
|
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
2020-04-21 17:00:32 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Application struct {
|
|
|
|
es_models.ObjectRoot
|
|
|
|
|
|
|
|
AppID string
|
|
|
|
State AppState
|
|
|
|
Name string
|
|
|
|
Type AppType
|
|
|
|
OIDCConfig *OIDCConfig
|
2021-02-17 15:31:47 +01:00
|
|
|
APIConfig *APIConfig
|
2020-04-21 17:00:32 +02:00
|
|
|
}
|
2020-06-15 16:50:09 +02:00
|
|
|
type ApplicationChanges struct {
|
|
|
|
Changes []*ApplicationChange
|
|
|
|
LastSequence uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
type ApplicationChange struct {
|
2020-06-29 09:37:10 +02:00
|
|
|
ChangeDate *timestamp.Timestamp `json:"changeDate,omitempty"`
|
|
|
|
EventType string `json:"eventType,omitempty"`
|
|
|
|
Sequence uint64 `json:"sequence,omitempty"`
|
|
|
|
ModifierId string `json:"modifierUser,omitempty"`
|
|
|
|
ModifierName string `json:"-"`
|
|
|
|
Data interface{} `json:"data,omitempty"`
|
2020-06-15 16:50:09 +02:00
|
|
|
}
|
2020-04-21 17:00:32 +02:00
|
|
|
|
|
|
|
type AppState int32
|
|
|
|
|
|
|
|
const (
|
2020-06-23 14:47:47 +02:00
|
|
|
AppStateActive AppState = iota
|
|
|
|
AppStateInactive
|
2020-08-13 08:28:18 +02:00
|
|
|
AppStateRemoved
|
2020-04-21 17:00:32 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type AppType int32
|
|
|
|
|
|
|
|
const (
|
2020-06-23 14:47:47 +02:00
|
|
|
AppTypeUnspecified AppType = iota
|
|
|
|
AppTypeOIDC
|
|
|
|
AppTypeSAML
|
2021-02-17 15:31:47 +01:00
|
|
|
AppTypeAPI
|
2020-04-21 17:00:32 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewApplication(projectID, appID string) *Application {
|
2020-06-23 14:47:47 +02:00
|
|
|
return &Application{ObjectRoot: es_models.ObjectRoot{AggregateID: projectID}, AppID: appID, State: AppStateActive}
|
2020-04-21 17:00:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Application) IsValid(includeConfig bool) bool {
|
|
|
|
if a.Name == "" || a.AggregateID == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !includeConfig {
|
|
|
|
return true
|
|
|
|
}
|
2020-06-23 14:47:47 +02:00
|
|
|
if a.Type == AppTypeOIDC && !a.OIDCConfig.IsValid() {
|
2020-04-21 17:00:32 +02:00
|
|
|
return false
|
|
|
|
}
|
2021-02-17 15:31:47 +01:00
|
|
|
if a.Type == AppTypeAPI && !a.APIConfig.IsValid() {
|
|
|
|
return false
|
|
|
|
}
|
2020-04-21 17:00:32 +02:00
|
|
|
return true
|
|
|
|
}
|
2021-02-17 15:31:47 +01:00
|
|
|
|
|
|
|
func (a *Application) GetKey(keyID string) (int, *ClientKey) {
|
|
|
|
if a.OIDCConfig == nil {
|
|
|
|
return -1, nil
|
|
|
|
}
|
|
|
|
for i, k := range a.OIDCConfig.ClientKeys {
|
|
|
|
if k.KeyID == keyID {
|
|
|
|
return i, k
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1, nil
|
|
|
|
}
|