|
|
|
@ -3,25 +3,26 @@ package sharedmodel |
|
|
|
|
import ( |
|
|
|
|
"encoding/json" |
|
|
|
|
|
|
|
|
|
"google.golang.org/protobuf/types/known/structpb" |
|
|
|
|
"gorm.io/gorm" |
|
|
|
|
"whiteboxsystems.nl/openkvpoc/openkv" |
|
|
|
|
"src.whiteboxsystems.nl/DECOZO/okapi" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type Service struct { |
|
|
|
|
type ServiceDefinition struct { |
|
|
|
|
gorm.Model |
|
|
|
|
ServiceID string |
|
|
|
|
Name string |
|
|
|
|
Description string |
|
|
|
|
SubscriptionPolicy openkv.SubscriptionPolicy |
|
|
|
|
ConsentPolicy openkv.ConsentPolicy |
|
|
|
|
SubscriptionPolicy okapi.SubscriptionPolicy |
|
|
|
|
ConsentPolicy okapi.ConsentPolicy |
|
|
|
|
FetchProtocols ProtocolArray `gorm:"type:text"` |
|
|
|
|
PushProtocols ProtocolArray `gorm:"type:text"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s Service) GetFetchProtocols() []*openkv.ProtocolDefinition { |
|
|
|
|
protoDefs := []*openkv.ProtocolDefinition{} |
|
|
|
|
func (s ServiceDefinition) GetFetchProtocols() []*okapi.ProtocolDefinition { |
|
|
|
|
protoDefs := []*okapi.ProtocolDefinition{} |
|
|
|
|
for _, sd := range s.FetchProtocols { |
|
|
|
|
protoDefs = append(protoDefs, &openkv.ProtocolDefinition{ |
|
|
|
|
protoDefs = append(protoDefs, &okapi.ProtocolDefinition{ |
|
|
|
|
Protocol: sd.Protocol, |
|
|
|
|
AuthMethods: sd.AuthMethods, |
|
|
|
|
}) |
|
|
|
@ -30,10 +31,10 @@ func (s Service) GetFetchProtocols() []*openkv.ProtocolDefinition { |
|
|
|
|
return protoDefs |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s Service) GetPushProtocols() []*openkv.ProtocolDefinition { |
|
|
|
|
protoDefs := []*openkv.ProtocolDefinition{} |
|
|
|
|
func (s ServiceDefinition) GetPushProtocols() []*okapi.ProtocolDefinition { |
|
|
|
|
protoDefs := []*okapi.ProtocolDefinition{} |
|
|
|
|
for _, sd := range s.PushProtocols { |
|
|
|
|
protoDefs = append(protoDefs, &openkv.ProtocolDefinition{ |
|
|
|
|
protoDefs = append(protoDefs, &okapi.ProtocolDefinition{ |
|
|
|
|
Protocol: sd.Protocol, |
|
|
|
|
AuthMethods: sd.AuthMethods, |
|
|
|
|
}) |
|
|
|
@ -46,7 +47,7 @@ type ProtocolConfig struct { |
|
|
|
|
gorm.Model |
|
|
|
|
Protocol string |
|
|
|
|
AuthConfigID uint |
|
|
|
|
AuthConfig *AuthConfig |
|
|
|
|
AuthConfig *AuthConfig `gorm:"constraint:OnDelete:CASCADE;"` |
|
|
|
|
Config string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -54,6 +55,15 @@ func (pc ProtocolConfig) UnmarshalConfig(in interface{}) error { |
|
|
|
|
return json.Unmarshal([]byte(pc.Config), in) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (pc ProtocolConfig) ConfigToOkapi() *structpb.Struct { |
|
|
|
|
config := map[string]interface{}{} |
|
|
|
|
pc.UnmarshalConfig(&config) |
|
|
|
|
|
|
|
|
|
cnf, _ := structpb.NewStruct(config) |
|
|
|
|
|
|
|
|
|
return cnf |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (pc *ProtocolConfig) SetConfig(in interface{}) error { |
|
|
|
|
b, err := json.Marshal(in) |
|
|
|
|
if err != nil { |
|
|
|
@ -67,13 +77,12 @@ func (pc *ProtocolConfig) SetConfig(in interface{}) error { |
|
|
|
|
type ServiceConfig struct { |
|
|
|
|
gorm.Model |
|
|
|
|
ServiceID uint |
|
|
|
|
Service Service |
|
|
|
|
Enabled bool |
|
|
|
|
Service ServiceDefinition |
|
|
|
|
ConnectionID uint |
|
|
|
|
Connection Connection `json:"-"` |
|
|
|
|
PushProtocolID uint |
|
|
|
|
PushProtocol *ProtocolConfig `gorm:"foreignKey:PushProtocolID"` |
|
|
|
|
PushProtocol *ProtocolConfig `gorm:"foreignKey:PushProtocolID;constraint:OnDelete:CASCADE;"` |
|
|
|
|
FetchProtocolID uint |
|
|
|
|
FetchProtocol *ProtocolConfig `gorm:"foreignKey:FetchProtocolID"` |
|
|
|
|
Subscriptions []*Subscription |
|
|
|
|
FetchProtocol *ProtocolConfig `gorm:"foreignKey:FetchProtocolID;constraint:OnDelete:CASCADE;"` |
|
|
|
|
Subscriptions []*Subscription `gorm:"constraint:OnDelete:CASCADE;"` |
|
|
|
|
} |
|
|
|
|