Files
fgueryandGitHub 92373b73cd fix(EN-696): ensure server/worker start even when plugin is invalid (#636)
* fix(EN-696): ensure server/worker start even when plugin is invalid

* fix: make quonto endpoint an url, and move comments around a bit

* fix: quonto test update
2026-01-22 14:21:19 +00:00

54 lines
1.6 KiB
Go

package qonto
import (
"encoding/json"
"github.com/formancehq/payments/internal/connectors/plugins/sharedconfig"
"github.com/formancehq/payments/internal/models"
"github.com/go-playground/validator/v10"
"github.com/pkg/errors"
)
type Config struct {
ClientID string `json:"clientID" validate:"required"`
APIKey string `json:"apiKey" validate:"required"`
Endpoint string `json:"endpoint" validate:"required,url"`
StagingToken string `json:"stagingToken" validate:"omitempty"`
PollingPeriod sharedconfig.PollingPeriod `json:"pollingPeriod"`
}
const PAGE_SIZE = 100 // max page size is 100
func unmarshalAndValidateConfig(payload json.RawMessage) (Config, error) {
var raw struct {
ClientID string `json:"clientID"`
APIKey string `json:"apiKey"`
Endpoint string `json:"endpoint"`
StagingToken string `json:"stagingToken"`
PollingPeriod string `json:"pollingPeriod"`
}
if err := json.Unmarshal(payload, &raw); err != nil {
return Config{}, errors.Wrap(models.ErrInvalidConfig, err.Error())
}
pp, err := sharedconfig.NewPollingPeriod(
raw.PollingPeriod,
sharedconfig.DefaultPollingPeriod,
sharedconfig.MinimumPollingPeriod,
)
if err != nil {
return Config{}, errors.Wrap(models.ErrInvalidConfig, err.Error())
}
config := Config{
ClientID: raw.ClientID,
APIKey: raw.APIKey,
Endpoint: raw.Endpoint,
StagingToken: raw.StagingToken,
PollingPeriod: pp,
}
validate := validator.New(validator.WithRequiredStructEnabled())
return config, validate.Struct(config)
}