mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* Manage configuration of polling period in connectors manager and enable override via env variables * Treat connector validation errors as http 4xx * Perform strict config validation only if connector being loaded for install or update * Add flags to configure notification outbox schedules * Only configure outbox schedule creation in worker * Improve manager config validation test coverage
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
// since the json unmarshaller is case-insensitive this generic interface will be used to receive back the unmarshaled struct from a plugin
|
|
// then we can remarshal the payload and enforce the case we expect (eg. clientID vs clientId) rather than blindly trusting the raw user input
|
|
type PluginInternalConfig interface{}
|
|
|
|
// Config is the generic configuration that all connectors share
|
|
// Note that the PollingPeriod defined here is often overwritten by the connector-specific configuration
|
|
type Config struct {
|
|
Name string `json:"name" validate:"required,gte=3,lte=500"`
|
|
PollingPeriod time.Duration `json:"pollingPeriod" validate:"required"`
|
|
}
|
|
|
|
func (c Config) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(struct {
|
|
Name string `json:"name"`
|
|
PollingPeriod string `json:"pollingPeriod"`
|
|
}{
|
|
Name: c.Name,
|
|
PollingPeriod: c.PollingPeriod.String(),
|
|
})
|
|
}
|
|
|
|
func (c *Config) UnmarshalJSON(data []byte) error {
|
|
var raw struct {
|
|
Name string `json:"name"`
|
|
PollingPeriod string `json:"pollingPeriod"`
|
|
}
|
|
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return err
|
|
}
|
|
|
|
var pollingPeriod time.Duration
|
|
if raw.PollingPeriod != "" {
|
|
p, err := time.ParseDuration(raw.PollingPeriod)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
pollingPeriod = p
|
|
}
|
|
|
|
c.Name = raw.Name
|
|
|
|
if pollingPeriod > 0 {
|
|
c.PollingPeriod = pollingPeriod
|
|
}
|
|
|
|
return nil
|
|
}
|