webhooks

package
v0.0.0-...-81dd437 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

Webhooks

Webhooks service provides forwarding received messages to other platforms.

Configuration

The service is configured using the environment variables from the following table. Note that any unset variables will be replaced with their default values.

Variable Description Default
MF_WEBHOOKS_LOG_LEVEL Log level for Webhooks (debug, info, warn, error) error
MF_WEBHOOKS_DB_HOST Database host address localhost
MF_WEBHOOKS_DB_PORT Database host port 5432
MF_WEBHOOKS_DB_USER Database user mainflux
MF_WEBHOOKS_DB_PASS Database password mainflux
MF_WEBHOOKS_DB Name of the database used by the service webhooks
MF_WEBHOOKS_DB_SSL_MODE Database connection SSL mode (disable, require, verify-ca, verify-full) disable
MF_WEBHOOKS_DB_SSL_CERT Path to the PEM encoded certificate file
MF_WEBHOOKS_DB_SSL_KEY Path to the PEM encoded key file
MF_WEBHOOKS_DB_SSL_ROOT_CERT Path to the PEM encoded root certificate file
MF_WEBHOOKS_CLIENT_TLS Flag that indicates if TLS should be turned on false
MF_WEBHOOKS_CA_CERTS Path to trusted CAs in PEM format
MF_WEBHOOKS_HTTP_PORT Webhooks service HTTP port 9021
MF_WEBHOOKS_SERVER_CERT Path to server certificate in pem format
MF_WEBHOOKS_SERVER_KEY Path to server key in pem format
MF_JAEGER_URL Jaeger server URL localhost:6831
MF_BROKER_URL Message broker URL nats://127.0.0.1:4222
MF_THINGS_AUTH_GRPC_URL Things auth service gRPC URL localhost:8183
MF_THINGS_AUTH_GRPC_TIMEOUT Things auth service gRPC request timeout in seconds 1s

Deployment

The service is distributed as a Docker container. The following snippet provides a compose file template that can be used to deploy the service container locally:

version: "3"
services:
  webhooks:
    image: mainfluxlabs/webhooks:[version]
    container_name: [instance name]
    ports:
      - [host machine port]:[configured HTTP port]
    environment:
      MF_WEBHOOKS_LOG_LEVEL: [Webhooks log level]
      MF_BROKER_URL: [Message broker URL]
      MF_WEBHOOKS_DB_HOST: [Database host address]
      MF_WEBHOOKS_DB_PORT: [Database host port]
      MF_WEBHOOKS_DB_USER: [Database user]
      MF_WEBHOOKS_DB_PASS: [Database password]
      MF_WEBHOOKS_DB: [Name of the database used by the service]
      MF_WEBHOOKS_HTTP_PORT: [Service HTTP port]
      MF_WEBHOOKS_SERVER_CERT: [String path to server cert in pem format]
      MF_WEBHOOKS_SERVER_KEY: [String path to server key in pem format]
      MF_JAEGER_URL: [Jaeger server URL]
      MF_THINGS_AUTH_GRPC_URL: [Things auth service gRPC URL]
      MF_THINGS_AUTH_GRPC_TIMEOUT: [Things auth service gRPC request timeout in seconds]

To start the service outside of the container, execute the following shell script:

# download the latest version of the service
go get github.com/MainfluxLabs/mainflux

cd $GOPATH/src/github.com/MainfluxLabs/mainflux

# compile the webhooks
make webhooks

# copy binary to bin
make install

# set the environment variables and run the service
MF_WEBHOOKS_LOG_LEVEL=[Webhooks log level]
MF_WEBHOOKS_DB_HOST=[Database host address]
MF_WEBHOOKS_DB_PORT=[Database host port]
MF_WEBHOOKS_DB_USER=[Database user]
MF_WEBHOOKS_DB_PASS=[Database password]
MF_WEBHOOKS_DB=[Name of the database used by the service]
MF_THINGS_DB_SSL_MODE=[SSL mode to connect to the database with]
MF_THINGS_DB_SSL_CERT=[Path to the PEM encoded certificate file]
MF_THINGS_DB_SSL_KEY=[Path to the PEM encoded key file]
MF_THINGS_DB_SSL_ROOT_CERT=[Path to the PEM encoded root certificate file]
MF_WEBHOOKS_HTTP_PORT=[Service HTTP port]
MF_WEBHOOKS_AUTH_GRPC_PORT=[Webhooks service Auth gRPC port]
MF_WEBHOOKS_SERVER_CERT=[String path to server cert in pem format]
MF_WEBHOOKS_SERVER_KEY=[String path to server key in pem format]
MF_JAEGER_URL=[Jaeger server URL]
MF_AUTH_GRPC_URL=[Auth service gRPC URL]
MF_AUTH_GRPC_TIMEOUT=[Auth service gRPC request timeout in seconds]
$GOBIN/mainflux-kit

Usage

For more information about service capabilities and its usage, please check out the API documentation.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrForward     = errors.New("failed to forward message")
	ErrSendRequest = errors.New("failed to send request")
)

Functions

This section is empty.

Types

type Forwarder

type Forwarder interface {
	// Forward method is used to forward the received message to a certain url
	Forward(ctx context.Context, message messaging.Message, whs []Webhook) error
}

func NewForwarder

func NewForwarder(webhooks WebhookRepository) Forwarder

type Service

type Service interface {
	// CreateWebhooks creates webhooks for certain thing
	// which belongs to the user identified by a given token
	CreateWebhooks(ctx context.Context, token string, webhooks ...Webhook) ([]Webhook, error)

	// ListWebhooksByThing retrieves data about a subset of webhooks
	// related to a certain thing identified by the provided ID.
	ListWebhooksByThing(ctx context.Context, token string, thingID string) ([]Webhook, error)

	consumers.Consumer
}

Service specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics).

func New

func New(things mainflux.ThingsServiceClient, webhooks WebhookRepository, forwarder Forwarder) Service

New instantiates the webhooks service implementation.

type Webhook

type Webhook struct {
	ThingID string
	Name    string
	Format  string
	Url     string
}

type WebhookRepository

type WebhookRepository interface {
	// Save persists multiple webhooks. Webhooks are saved using a transaction.
	// If one webhook fails then none will be saved.
	// Successful operation is indicated by non-nil error response.
	Save(ctx context.Context, whs ...Webhook) ([]Webhook, error)

	// RetrieveByThingID retrieves webhooks related to
	// a certain thing identified by a given ID.
	RetrieveByThingID(ctx context.Context, thingID string) ([]Webhook, error)
}

Directories

Path Synopsis
api
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
http
Package http contains implementation of kit service HTTP API.
Package http contains implementation of kit service HTTP API.

Jump to

Keyboard shortcuts

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