http

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

README

HTTP adapter

HTTP adapter provides an HTTP API for sending messages through the platform.

Configuration

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

Variable Description Default
MG_HTTP_ADAPTER_LOG_LEVEL Log level for the HTTP Adapter (debug, info, warn, error) info
MG_HTTP_ADAPTER_HOST Service HTTP host ""
MG_HTTP_ADAPTER_PORT Service HTTP port 80
MG_HTTP_ADAPTER_SERVER_CERT Path to the PEM encoded server certificate file ""
MG_HTTP_ADAPTER_SERVER_KEY Path to the PEM encoded server key file ""
MG_THINGS_AUTH_GRPC_URL Things service Auth gRPC URL localhost:7016
MG_THINGS_AUTH_GRPC_TIMEOUT Things service Auth gRPC request timeout in seconds 1s
MG_THINGS_AUTH_GRPC_CLIENT_CERT Path to the PEM encoded things service Auth gRPC client certificate file ""
MG_THINGS_AUTH_GRPC_CLIENT_KEY Path to the PEM encoded things service Auth gRPC client key file ""
MG_THINGS_AUTH_GRPC_SERVER_CERTS Path to the PEM encoded things server Auth gRPC server trusted CA certificate file ""
MG_MESSAGE_BROKER_URL Message broker instance URL nats://localhost:4222
MG_JAEGER_URL Jaeger server URL http://localhost:14268/api/traces
MG_JAEGER_TRACE_RATIO Jaeger sampling ratio 1.0
MG_SEND_TELEMETRY Send telemetry to magistrala call home server true
MG_HTTP_ADAPTER_INSTANCE_ID Service instance ID ""

Deployment

The service itself is distributed as Docker container. Check the http-adapter service section in docker-compose file to see how service is deployed.

Running this service outside of container requires working instance of the message broker service, things service and Jaeger server. To start the service outside of the container, execute the following shell script:

# download the latest version of the service
git clone https://github.com/andychao217/magistrala

cd magistrala

# compile the http
make http

# copy binary to bin
make install

# set the environment variables and run the service
MG_HTTP_ADAPTER_LOG_LEVEL=info \
MG_HTTP_ADAPTER_HOST=localhost \
MG_HTTP_ADAPTER_PORT=80 \
MG_HTTP_ADAPTER_SERVER_CERT="" \
MG_HTTP_ADAPTER_SERVER_KEY="" \
MG_THINGS_AUTH_GRPC_URL=localhost:7016 \
MG_THINGS_AUTH_GRPC_TIMEOUT=1s \
MG_THINGS_AUTH_GRPC_CLIENT_CERT="" \
MG_THINGS_AUTH_GRPC_CLIENT_KEY="" \
MG_THINGS_AUTH_GRPC_SERVER_CERTS="" \
MG_MESSAGE_BROKER_URL=nats://localhost:4222 \
MG_JAEGER_URL=http://localhost:14268/api/traces \
MG_JAEGER_TRACE_RATIO=1.0 \
MG_SEND_TELEMETRY=true \
MG_HTTP_ADAPTER_INSTANCE_ID="" \
$GOBIN/magistrala-http

Setting MG_HTTP_ADAPTER_SERVER_CERT and MG_HTTP_ADAPTER_SERVER_KEY will enable TLS against the service. The service expects a file in PEM format for both the certificate and the key.

Setting MG_THINGS_AUTH_GRPC_CLIENT_CERT and MG_THINGS_AUTH_GRPC_CLIENT_KEY will enable TLS against the things service. The service expects a file in PEM format for both the certificate and the key. Setting MG_THINGS_AUTH_GRPC_SERVER_CERTS will enable TLS against the things service trusting only those CAs that are provided. The service expects a file in PEM format of trusted CAs.

Usage

HTTP Authorization request header contains the credentials to authenticate a Thing. The authorization header can be a plain Thing key or a Thing key encoded as a password for Basic Authentication. In case the Basic Authentication schema is used, the username is ignored. For more information about service capabilities and its usage, please check out the API documentation.

Documentation

Overview

Package http contains the domain concept definitions needed to support Magistrala HTTP Adapter functionality.

Index

Constants

View Source
const (
	LogInfoConnected = "connected with thing_key %s"
	// ThingPrefix represents the key prefix for Thing authentication scheme.
	ThingPrefix      = "Thing "
	LogInfoPublished = "published with client_id %s to the topic %s"
)

Log message formats.

Variables

View Source
var (
	ErrMalformedSubtopic         = errors.New("malformed subtopic")
	ErrClientNotInitialized      = errors.New("client is not initialized")
	ErrMalformedTopic            = errors.New("malformed topic")
	ErrMissingTopicPub           = errors.New("failed to publish due to missing topic")
	ErrMissingTopicSub           = errors.New("failed to subscribe due to missing topic")
	ErrFailedConnect             = errors.New("failed to connect")
	ErrFailedPublish             = errors.New("failed to publish")
	ErrFailedParseSubtopic       = errors.New("failed to parse subtopic")
	ErrFailedPublishConnectEvent = errors.New("failed to publish connect event")
	ErrFailedPublishToMsgBroker  = errors.New("failed to publish to magistrala message broker")
)

Error wrappers for MQTT errors.

Functions

func NewHandler

func NewHandler(publisher messaging.Publisher, logger *slog.Logger, authClient magistrala.AuthzServiceClient) session.Handler

NewHandler creates new Handler entity.

Types

This section is empty.

Directories

Path Synopsis
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.

Jump to

Keyboard shortcuts

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