mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* feat: Create EE architecture * feat: Move Fireblocks to EE * feat: Add dual CE/EE licensing model Update root LICENSE to dual-license format distinguishing Community Edition (MIT) from Enterprise Edition (ee/LICENSE), aligned with the formancehq/stack licensing model. * refactor: Rename main_ee.go to ee.go for cleaner build tag convention * feat: Move Coinbase Prime to EE * feat: just * fix: tidy & package name
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package coinbaseprime
|
|
|
|
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 {
|
|
APIKey string `json:"apiKey" validate:"required"`
|
|
APISecret string `json:"apiSecret" validate:"required"`
|
|
Passphrase string `json:"passphrase" validate:"required"`
|
|
PortfolioID string `json:"portfolioId" validate:"required"`
|
|
PollingPeriod sharedconfig.PollingPeriod `json:"pollingPeriod"`
|
|
}
|
|
|
|
const PAGE_SIZE = 100
|
|
|
|
func unmarshalAndValidateConfig(payload json.RawMessage) (Config, error) {
|
|
var raw struct {
|
|
APIKey string `json:"apiKey"`
|
|
APISecret string `json:"apiSecret"`
|
|
Passphrase string `json:"passphrase"`
|
|
PortfolioID string `json:"portfolioId"`
|
|
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{
|
|
APIKey: raw.APIKey,
|
|
APISecret: raw.APISecret,
|
|
Passphrase: raw.Passphrase,
|
|
PortfolioID: raw.PortfolioID,
|
|
PollingPeriod: pp,
|
|
}
|
|
|
|
validate := validator.New(validator.WithRequiredStructEnabled())
|
|
if err := validate.Struct(config); err != nil {
|
|
return Config{}, errors.Wrap(models.ErrInvalidConfig, err.Error())
|
|
}
|
|
|
|
return config, nil
|
|
}
|