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
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package connectors
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/formancehq/payments/internal/models"
|
|
"github.com/go-playground/validator/v10"
|
|
)
|
|
|
|
type Configurer struct {
|
|
connectorPollingPeriodDefault time.Duration
|
|
connectorPollingPeriodMinimum time.Duration
|
|
}
|
|
|
|
func NewConfigurer(pollingPeriodDefault, pollingPeriodMinimum time.Duration) (*Configurer, error) {
|
|
if pollingPeriodDefault < pollingPeriodMinimum {
|
|
return nil, fmt.Errorf("default connector polling period may not be lower than minimum")
|
|
}
|
|
|
|
return &Configurer{
|
|
connectorPollingPeriodDefault: pollingPeriodDefault,
|
|
connectorPollingPeriodMinimum: pollingPeriodMinimum,
|
|
}, nil
|
|
}
|
|
|
|
func (c *Configurer) DefaultConfig() models.Config {
|
|
return models.Config{
|
|
PollingPeriod: c.connectorPollingPeriodDefault,
|
|
}
|
|
}
|
|
|
|
func (c *Configurer) Validate(conf models.Config) error {
|
|
validate := validator.New(validator.WithRequiredStructEnabled())
|
|
if err := validate.Struct(conf); err != nil {
|
|
return fmt.Errorf("%w: %w", models.ErrInvalidConfig, err)
|
|
}
|
|
|
|
if conf.PollingPeriod < c.connectorPollingPeriodMinimum {
|
|
return fmt.Errorf("%w: polling period cannot be lower than minimum of %s", ErrPollingPeriod, c.connectorPollingPeriodMinimum)
|
|
}
|
|
return nil
|
|
}
|