You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.8 KiB
80 lines
1.8 KiB
3 years ago
|
package sharedmodel
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
|
||
|
"gorm.io/gorm"
|
||
|
"whiteboxsystems.nl/openkvpoc/openkv"
|
||
|
)
|
||
|
|
||
|
type Service struct {
|
||
|
gorm.Model
|
||
|
ServiceID string
|
||
|
Name string
|
||
|
Description string
|
||
|
SubscriptionPolicy openkv.SubscriptionPolicy
|
||
|
ConsentPolicy openkv.ConsentPolicy
|
||
|
FetchProtocols ProtocolArray `gorm:"type:text"`
|
||
|
PushProtocols ProtocolArray `gorm:"type:text"`
|
||
|
}
|
||
|
|
||
|
func (s Service) GetFetchProtocols() []*openkv.ProtocolDefinition {
|
||
|
protoDefs := []*openkv.ProtocolDefinition{}
|
||
|
for _, sd := range s.FetchProtocols {
|
||
|
protoDefs = append(protoDefs, &openkv.ProtocolDefinition{
|
||
|
Protocol: sd.Protocol,
|
||
|
AuthMethods: sd.AuthMethods,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
return protoDefs
|
||
|
}
|
||
|
|
||
|
func (s Service) GetPushProtocols() []*openkv.ProtocolDefinition {
|
||
|
protoDefs := []*openkv.ProtocolDefinition{}
|
||
|
for _, sd := range s.PushProtocols {
|
||
|
protoDefs = append(protoDefs, &openkv.ProtocolDefinition{
|
||
|
Protocol: sd.Protocol,
|
||
|
AuthMethods: sd.AuthMethods,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
return protoDefs
|
||
|
}
|
||
|
|
||
|
type ProtocolConfig struct {
|
||
|
gorm.Model
|
||
|
Protocol string
|
||
|
AuthConfigID uint
|
||
|
AuthConfig *AuthConfig
|
||
|
Config string
|
||
|
}
|
||
|
|
||
|
func (pc ProtocolConfig) UnmarshalConfig(in interface{}) error {
|
||
|
return json.Unmarshal([]byte(pc.Config), in)
|
||
|
}
|
||
|
|
||
|
func (pc *ProtocolConfig) SetConfig(in interface{}) error {
|
||
|
b, err := json.Marshal(in)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
pc.Config = string(b)
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
type ServiceConfig struct {
|
||
|
gorm.Model
|
||
|
ServiceID uint
|
||
|
Service Service
|
||
|
Enabled bool
|
||
|
ConnectionID uint
|
||
|
Connection Connection `json:"-"`
|
||
|
PushProtocolID uint
|
||
|
PushProtocol *ProtocolConfig `gorm:"foreignKey:PushProtocolID"`
|
||
|
FetchProtocolID uint
|
||
|
FetchProtocol *ProtocolConfig `gorm:"foreignKey:FetchProtocolID"`
|
||
|
Subscriptions []*Subscription
|
||
|
}
|