ingester

package module
v0.0.0-...-b80e893 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: MPL-2.0 Imports: 21 Imported by: 0

README

Convoy Ingester

Convoy Ingester is a serverless function that acts as a middleware between API providers and Convoy. This enables consumers benefit from Convoy without providers taking advantage of Convoy yet.

The plan is to make this first class support in Convoy, this repo is a prototype for that future.

Functions
WebhookEndpoint

This function receives webhook events from the provider E.g. Paystack. acks the event and publishes the event to a pub/sub topic. To configure this function set the environment variable - WEBHOOK_ENDPOINT_ENV_VARS in GitHub actions with:

WEBHOOK_TOPIC=<insert-topic>,GOOGLE_CLOUD_PROJECT=<insert-project-id>,PAYSTACK_SECRET=<insert-paystack-secret>
PushToConvoy

This function is triggered from the pub/sub topic earlier and pushes to Convoy. To configure this function set environment variable - PUSH_TO_CONVOY_ENV_VARS in GitHub actions with:

WEBHOOK_TOPIC=<insert-topic>,GOOGLE_CLOUD_PROJECT=<insert-project-id>,CONVOY_GROUP_ID=<insert-group-id>,CONVOY_API_KEY=<insert-api-key>,CONVOY_PAYSTACK_APP_ID=<insert-app-id>
How To

To run this function, you need to fork the repository. Follow this article to deploy these functions to Google Cloud Functions

Topic Configuration
  • Create a topic on the GCP console. Retrieve the topic's full name. E.g. projects/{project-name}/topics/{topic-name}
  • Add the topic to the Github actions secret with key - TRIGGER_RESOURCE
Push Request
curl --request POST \
--url "http://localhost:8080" \
--header "Content-Type: application/json" \
--header "X-Paystack-Signature: <signature>" \
--header "X-Forwarded-For: <insert-ip-address> \
--data '{"event": "charge.created"}'

You can generate dummy hash here

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Configuration Environment Variable
	CONFIG_ENV = "CONVOY_INGESTER_CONFIG"
)
View Source
var ErrAlgoNotFound = errors.New("Algorithm not found")
View Source
var ErrAuthHeader = errors.New("Invalid Authorization header")
View Source
var ErrAuthHeaderCannotBeEmpty = errors.New("Auth header cannot be empty")
View Source
var ErrCannotDecodeMACHeader = errors.New("Cannot decode MAC header")
View Source
var ErrCannotReadRequestBody = errors.New("Failed to read request body")
View Source
var ErrHashDoesNotMatch = errors.New("Invalid Signature - Hash does not match")
View Source
var ErrInvalidAuthLength = errors.New("Invalid Basic Auth Length")
View Source
var ErrInvalidHeaderStructure = errors.New("Invalid header structure")
View Source
var ErrInvalidIP = errors.New("Source IP not supported")
View Source
var ErrSignatureCannotBeEmpty = errors.New("Signature cannot be empty")

Functions

func LoadConfig

func LoadConfig(env string) error

func LoadProviderStore

func LoadProviderStore() error

func PushToConvoy

func PushToConvoy(ctx context.Context, m pubSubMessage) error

PushToConvoy is a Pub/Sub Triggered Function to push events to Convoy.

func WebhookEndpoint

func WebhookEndpoint(w http.ResponseWriter, r *http.Request)

WebhookEndpoint is a HTTP Function to receive events from the world.

func WebhooksHandler

func WebhooksHandler(w http.ResponseWriter, r *http.Request)

HTTP Handlers

Types

type APIKeyConfig

type APIKeyConfig struct {
	Header string `json:"header"`
	APIKey string `json:"api_key"`
}

type APIKeyVerifier

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

func (*APIKeyVerifier) VerifyRequest

func (aV *APIKeyVerifier) VerifyRequest(r *http.Request, payload []byte) error

type BasicAuthConfig

type BasicAuthConfig struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type BasicAuthVerifier

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

func (*BasicAuthVerifier) VerifyRequest

func (baV *BasicAuthVerifier) VerifyRequest(r *http.Request, payload []byte) error

type Configuration

type Configuration []ProviderConfig

type HmacConfig

type HmacConfig struct {
	Header string `json:"header"`
	Hash   string `json:"hash"`
	Secret string `json:"secret"`
}

type HmacVerifier

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

func (*HmacVerifier) VerifyRequest

func (hV *HmacVerifier) VerifyRequest(r *http.Request, payload []byte) error

type IPAddressConfig

type IPAddressConfig struct {
	IPSafelist []string `json:"ip_safelist"`
}

type IPAddressVerifier

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

func (*IPAddressVerifier) VerifyRequest

func (ipV *IPAddressVerifier) VerifyRequest(r *http.Request, payload []byte) error

type Provider

type Provider struct {
	Name  string
	AppID string
	// contains filtered or unexported fields
}

func (*Provider) VerifyRequest

func (p *Provider) VerifyRequest(r *http.Request, payload []byte) error

type ProviderConfig

type ProviderConfig struct {
	Name           string         `json:"name"`
	AppID          string         `json:"app_id"`
	VerifierConfig VerifierConfig `json:"verifier_config"`
}

type ProviderStore

type ProviderStore map[string]*Provider

Store

type Verifier

type Verifier interface {
	VerifyRequest(r *http.Request, payload []byte) error
}

type VerifierConfig

type VerifierConfig struct {
	*HmacConfig
	*BasicAuthConfig
	*APIKeyConfig
	*IPAddressConfig
}

func (*VerifierConfig) UnmarshalJSON

func (vC *VerifierConfig) UnmarshalJSON(data []byte) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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