Initial commit
This commit is contained in:
commit
3e81a54556
74 changed files with 41737 additions and 0 deletions
79
sharedmodel/service.go
Normal file
79
sharedmodel/service.go
Normal file
|
@ -0,0 +1,79 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue