webhook

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const BoltDBFile = "webhooks.db"

BoltDBFile is the filename to store the boltdb database

Variables

View Source
var EventLabels = map[string]EventEnum{
	"all":            EventAll,
	"localdelivery":  EventLocalDelivery,
	"faileddelivery": EventFailedDelivery,
	"remotedelivery": EventRemoteDelivery,
	"apikeycreated":  EventAPIKeyCreated,
	"apikeydeleted":  EventAPIKeyDeleted,
	"apikeyupdated":  EventAPIKeyUpdated,
	"authkeycreated": EventAuthKeyCreated,
	"authkeydeleted": EventAuthKeyDeleted,
	"authkeyupdated": EventAuthKeyUpdated,
	"webhookcreated": EventWebhookCreated,
	"webhookdeleted": EventWebhookDeleted,
	"webhookupdated": EventWebhookUpdated,
	"invitecreated":  EventInviteCreated,
	"accountcreated": EventAccountCreated,
	"test":           EventTest,
}

EventLabels is the mapping of an event to a string or string to event

Functions

This section is empty.

Types

type ConfigHTTP

type ConfigHTTP struct {
	URL string
}

ConfigHTTP Configuration for TypeHTTP

type ConfigSQS

type ConfigSQS struct {
	Arn             string
	Region          string
	AccessKeyID     string
	SecretAccessKey string
}

ConfigSQS Configuration for TypeSQS (not yet implemented)

type ConfigSlack

type ConfigSlack struct {
	WebhookURL string
	Channel    string
	Username   string
	IconEmoji  string
	IconURL    string
	Template   string
}

ConfigSlack Configuration for TypeSlack (not yet implemented)

type EventEnum

type EventEnum int

EventEnum is the event on which the webhook responds

const (
	EventLocalDelivery  EventEnum = iota + 1 // A local delivery has been made (incoming)
	EventFailedDelivery                      // A message is received but not considered correct
	EventRemoteDelivery                      // A message has been send to a remote server (outgoing)
	EventAPIKeyCreated                       // Api Key created
	EventAPIKeyDeleted                       // Api key deleted
	EventAPIKeyUpdated                       // Api key updated
	EventAuthKeyCreated                      // Auth key created
	EventAuthKeyDeleted                      // Auth key deleted
	EventAuthKeyUpdated                      // Auth key updated
	EventWebhookCreated                      // webhook created
	EventWebhookDeleted                      // webhook deleted
	EventWebhookUpdated                      // webhook updated
	EventInviteCreated                       // invite created
	EventAccountCreated                      // account created
	EventTest           EventEnum = 998      // Test event
	EventAll            EventEnum = 999      // All events
)

Webhook event types. Everything that a webhook can trigger on

func NewEventFromString

func NewEventFromString(s string) (EventEnum, error)

NewEventFromString will create a new event based on the string

func (EventEnum) String

func (e EventEnum) String() string

String convert event to string

type Repository

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

Repository is a repository to fetch and store webhooks

func NewBoltRepository

func NewBoltRepository(dbPath string) *Repository

NewBoltRepository initializes a new BoltDb repository

func NewMockRepository

func NewMockRepository() *Repository

NewMockRepository initializes a new mock repository

func NewRedisRepository

func NewRedisRepository(opts *redis.Options) *Repository

NewRedisRepository initializes a new Redis repository

func (Repository) Fetch

func (r Repository) Fetch(ID string) (*Type, error)

Fetch will get a single API key

func (Repository) FetchByHash

func (r Repository) FetchByHash(h hash.Hash) ([]Type, error)

FetchByHash will fetch all api keys for the given address hash

func (Repository) Remove

func (r Repository) Remove(w Type) error

Remove will remove a single webhook

func (Repository) Store

func (r Repository) Store(w Type) error

Store will store a single webhook

type Storage

type Storage interface {
	FetchByHash(h hash.Hash) ([]Type, error)
	Fetch(ID string) (*Type, error)
	Store(w Type) error
	Remove(w Type) error
}

Storage is the main interface for fetching and storing webhook data

type Type

type Type struct {
	ID      string    // Id of the webhook (uuidv4)
	Account hash.Hash // account to which this webhook belongs to
	Type    TypeEnum  // type of webhook
	Event   EventEnum // event when this webhook is triggered
	Enabled bool      // true when the webhook is enabled
	Config  string    // config for the given target, json encoded
}

Type is the webhook structure

func NewWebhook

func NewWebhook(account hash.Hash, e EventEnum, t TypeEnum, cfg interface{}) (*Type, error)

NewWebhook creates a new webhook

type TypeEnum

type TypeEnum int

TypeEnum is the type of the webhook destination

const (
	TypeHTTP  TypeEnum = iota // Simple HTTP endpoint
	TypeSlack                 // Slack support

)

Webhook destination types.

func (TypeEnum) String

func (e TypeEnum) String() string

String convert type to string

Jump to

Keyboard shortcuts

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