webhook

package
v0.24.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const Timeout = 30 * time.Second

Variables

View Source
var (
	ErrIdentityRequired    = errors.New("identity payload is required in webhook response")
	ErrTransactionRequired = errors.New("pending or transaction payload is required in webhook response")
)
View Source
var MockURL *url.URL

Functions

This section is empty.

Types

type Handler

type Handler interface {
	Callback(context.Context, *Request) (*Reply, error)
}

func New

func New(webhook *url.URL) Handler

New returns a webhook handler that will POST callbacks to the webhook specified by the given URL. If the "mock" scheme is specified for the URL, then a MockCallback handler will be returned for external testing purposes.

type Mock

type Mock struct {
	OnCallback func(context.Context, *Request) (*Reply, error)
	Callbacks  int
}

Mock implements the webhook Handler and is used for testing webhook interactions.

func (*Mock) Callback

func (m *Mock) Callback(ctx context.Context, req *Request) (*Reply, error)

func (*Mock) Reset

func (m *Mock) Reset()

func (*Mock) UseError

func (m *Mock) UseError(err error)

func (*Mock) UseFixture

func (m *Mock) UseFixture(path string) (err error)

func (*Mock) UseReply

func (m *Mock) UseReply(rep *Reply)

type Payload

type Payload struct {
	Identity    *ivms101.IdentityPayload `json:"identity"`
	Pending     *generic.Pending         `json:"pending,omitempty"`
	Transaction *generic.Transaction     `json:"transaction,omitempty"`
	SentAt      string                   `json:"sent_at"`
	ReceivedAt  string                   `json:"received_at,omitempty"`
}

Payload is a denormalized representation of a TRISA payload that includes type-specific data structures. The payload should always have an identity IVMS101 payload and a sent at timestamp. It will have either a pending message or a transaction but not both. If payload is in an envelope with an accepted or completed transfer state it will have a received at timestamp as well.

func (*Payload) IsZero

func (p *Payload) IsZero() bool

func (*Payload) Proto

func (p *Payload) Proto() (payload *trisa.Payload, err error)

Convert payload (usually from a reply) into a TRISA protocol buffer struct.

type Reply

type Reply struct {
	TransactionID  uuid.UUID    `json:"transaction_id"`
	Error          *trisa.Error `json:"error,omitempty"`
	Payload        *Payload     `json:"payload,omitempty"`
	TransferAction string       `json:"transfer_action,omitempty"`
}

Reply represents the expected response from the callback webhook to the Envoy node. Either an error or a pending message is returned in the common case, though Envoy will also handle synchronous compliance responses.

func MockErrorReply

func MockErrorReply(_ context.Context, req *Request) (*Reply, error)

func MockPendingReply

func MockPendingReply(_ context.Context, req *Request) (*Reply, error)

func (*Reply) TransferState

func (r *Reply) TransferState() trisa.TransferState

Determine the API transfer state based on the reply

type Request

type Request struct {
	TransactionID uuid.UUID         `json:"transaction_id"`
	Timestamp     string            `json:"timestamp"`
	Counterparty  *api.Counterparty `json:"counterparty"`
	HMAC          string            `json:"hmac_signature,omitempty"`
	PKS           string            `json:"public_key_signature,omitempty"`
	TransferState string            `json:"transfer_state,omitempty"`
	Error         *trisa.Error      `json:"error,omitempty"`
	Payload       *Payload          `json:"payload,omitempty"`
}

The Request object is sent to the webhook via a POST http call. The request represents an incoming message to the server as an unsealed, decrypted secure envelope (whether the request came from a TRISA or TRP remote client). The request is guaranteed to have a transaction ID, timestamp, and counterparty. If it has a payload, then it will also have an HMAC signature and public key signature. Requests will have either errors or payloads, but not both.

func (*Request) AddPayload

func (r *Request) AddPayload(payload *trisa.Payload) (err error)

Add a TRISA protocol buffer payload to the webhook request, unmarshaling it into its denormalized JSON representation to conduct the request.

type Webhook

type Webhook struct {
	// contains filtered or unexported fields
}

Webhook implements the Handler to make POST requests to the webhook URL.

func (*Webhook) Callback

func (h *Webhook) Callback(ctx context.Context, out *Request) (in *Reply, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL