mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* Use validation library in pools creation endpoint * Return error before launching workflow if connector not found in forward bank account req * Return error before launching workflow if bank account not found in forward bank account req * Use TaskIDReference naming convention for connector install workflow * Exclude generate workflow run mock from code coverage check * Use TaskIDReference naming convention for connector uninstall workflow * Use TaskIDReference naming convention for connector reset workflow * Deduplicate Install Workflow options and test OnStart function * Add validation for Name field in Pool creation * Separate not found errors from other storage errors in bank account forwarding * Add customizable timeout to e2e test client
84 lines
1.7 KiB
Go
84 lines
1.7 KiB
Go
package models
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"encoding/base64"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/gibson042/canonicaljson-go"
|
|
)
|
|
|
|
type TaskID struct {
|
|
Reference string
|
|
ConnectorID ConnectorID
|
|
}
|
|
|
|
func TaskIDReference(prefix string, connectorID ConnectorID, objectID string) string {
|
|
if objectID == "" {
|
|
return fmt.Sprintf("%s-%s-%s", prefix, connectorID.Provider, connectorID.Reference.String())
|
|
}
|
|
return fmt.Sprintf("%s-%s-%s-%s", prefix, connectorID.Provider, connectorID.Reference.String(), objectID)
|
|
}
|
|
|
|
func (aid *TaskID) String() string {
|
|
if aid == nil || aid.Reference == "" {
|
|
return ""
|
|
}
|
|
|
|
data, err := canonicaljson.Marshal(aid)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString(data)
|
|
}
|
|
|
|
func TaskIDFromString(value string) (*TaskID, error) {
|
|
data, err := base64.URLEncoding.WithPadding(base64.NoPadding).DecodeString(value)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ret := TaskID{}
|
|
err = canonicaljson.Unmarshal(data, &ret)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &ret, nil
|
|
}
|
|
|
|
func MustTaskIDFromString(value string) TaskID {
|
|
id, err := TaskIDFromString(value)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return *id
|
|
}
|
|
|
|
func (aid TaskID) Value() (driver.Value, error) {
|
|
return aid.String(), nil
|
|
}
|
|
|
|
func (aid *TaskID) Scan(value interface{}) error {
|
|
if value == nil {
|
|
return errors.New("task id is nil")
|
|
}
|
|
|
|
if s, err := driver.String.ConvertValue(value); err == nil {
|
|
|
|
if v, ok := s.(string); ok {
|
|
|
|
id, err := TaskIDFromString(v)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to parse task id %s: %v", v, err)
|
|
}
|
|
|
|
*aid = *id
|
|
return nil
|
|
}
|
|
}
|
|
|
|
return fmt.Errorf("failed to scan task id: %v", value)
|
|
}
|