provision

package module
v0.0.0-...-0a7255e Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

README

PROVISION service

PROVISION service provides an HTTP API to interact with Mainflux.

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
MF_USER User (email) for accessing Mainflux user@example.com
MF_PASS Mainflux password user123
MF_API_KEY Mainflux authentication token ""
MF_PROVISION_CONFIG_FILE Provision config file "config.toml"
MF_PROVISION_HTTP_PORT Provision service listening port 8091
MF_ENV_CLIENTS_TLS Mainflux SDK TLS verification false
MF_PROVISION_CA_CERTS Mainflux gRPC secure certs ""
MF_PROVISION_SERVER_CERT Mainflux gRPC secure server cert ""
MF_PROVISION_SERVER_KEY Mainflux gRPC secure server key ""
MF_PROVISION_SERVER_KEY Mainflux gRPC secure server key ""
MF_MQTT_URL Mainflux MQTT adapter URL "http://localhost:1883"
MF_USERS_LOCATION Users service URL "http://locahost"
MF_THINGS_LOCATION Things service URL "http://localhost"
MF_PROVISION_LOG_LEVEL Service log level "http://localhost"
MF_PROVISION_HTTP_PORT Service listening port "8091"
MF_USER Mainflux user username "test@example.com"
MF_PASS Mainflux user password "password"
MF_BS_SVC_URL Mainflux Bootstrap service URL http://localhost/things/configs"
MF_BS_SVC_WHITELIST_URL Mainflux Bootstrap service whitelist URL "http://localhost/things/state"
MF_CERTS_SVC_URL Certificats service URL "http://localhost/certs"
MF_X509_PROVISIONING Should X509 client cert be provisioned "false"
MF_BS_CONFIG_PROVISIONING Should thing config be saved in Bootstrap service "true"
MF_BS_AUTO_WHITEIST Should thing be auto whitelisted "true"
MF_BS_CONTENT Bootstrap service content "{}"

By default, call to mapping endpoint will create one thing and two channels ( 'control' and 'data' ) and connect it. If there is a requirement for different conf we can use config file. In config.toml we can enlist array of things and channels that we want to create and make connections between them. Metadata can be whatever suits your needs except that at least one thing needs to have 'externalID' (which is populated with value from request). For channels metadata 'type' is reserved for 'control' and 'data'.

Example below

[[things]]
  name = "thing"

  [things.metadata]
    externalID = "xxxxxx"


[[channels]]
  name = "control-channel"

  [channels.metadata]
    type = "control"

[[channels]]
  name = "data-channel"

  [channels.metadata]
    type = "data"

[[channels]]
  name = "export-channel"

  [channels.metadata]
    type = "data"

Example

curl -X POST \
  http://localhost:8091/mapping\
  -H 'Content-Type: application/json' \
  -d '{ "externalid" : "02:42:fE:65:CB:3d", "externalkey: "key12345678" }'

Documentation

Overview

Package provision contains domain concept definitions needed to support Provision service feature, i.e. automate provision process.

Index

Constants

View Source
const (
	ExternalID = "externalID"
	Active     = 1
)

Variables

This section is empty.

Functions

func Save

func Save(c Config, file string) error

Save - store config in a file

Types

type Bootstrap

type Bootstrap struct {
	X509Provision bool   `toml:"x509_provision"`
	Provision     bool   `toml:"provision"`
	AutoWhiteList bool   `toml:"autowhite_list"`
	Content       string `toml:"content"`
}

type Channel

type Channel struct {
	Name     string                 `toml:"name"`
	Metadata map[string]interface{} `toml:"metadata" mapstructure:"metadata"`
}

type Config

type Config struct {
	File      string      `toml:"file"`
	Server    ServiceConf `toml:"server"`
	Bootstrap Bootstrap   `toml:"bootstrap"`
	Things    []Thing     `toml:"things" mapstructure:"things"`
	Channels  []Channel   `toml:"channels" mapstructure:"channel"`
}

Config struct of Provision

func Read

func Read(file string) (Config, error)

Read - retrieve config from a file

type Result

type Result struct {
	Things      []provSDK.Thing   `json:"things,omitempty"`
	ThingsID    []string          `json:"thing_ids,omitempty"`
	Channels    []provSDK.Channel `json:"channels,omitempty"`
	ClientCert  map[string]string `json:"client_cert,omitempty"`
	ClientKey   map[string]string `json:"client_key,omitempty"`
	CACert      string            `json:"ca_cert,omitempty"`
	Whitelisted map[string]bool   `json:"whitelisted,omitempty"`
}

Result represent what is created with additional info.

type Service

type Service interface {
	// Provision is the only method this API specifies. Depending on the configuration,
	// the following actions will can be executed:
	// - create a Thing based od mac address
	// - create multiple Channels
	// - create Bootstrap configuration
	// - whitelist Thing in Bootstrap configuration == connect Thing to Channels
	Provision(externalID, externalKey string) (Result, error)
}

Service specifies Provision service API.

func New

func New(cfg Config, sdk provSDK.SDK, logger logger.Logger) Service

New returns new provision service.

type ServiceConf

type ServiceConf struct {
	Port           string `toml:"port"`
	LogLevel       string `toml:"log_level"`
	TLS            bool   `toml:"tls"`
	CACerts        string `toml:"ca_certs"`
	ServerCert     string `toml:"server_cert"`
	ServerKey      string `toml:"server_key"`
	ThingsLocation string `toml:"things_location"`
	UsersLocation  string `toml:"users_location"`
	MQTTURL        string `toml:"mqtt_url"`
	HTTPPort       string `toml:"http_port"`
	MfUser         string `toml:"mf_user"`
	MfPass         string `toml:"mf_pass"`
	MfApiKey       string `toml:"mf_api_key"`
	MfBSURL        string `toml:"mf_bs_url"`
	MfWhiteListURL string `toml:"mf_whit_list"`
	MfCertsURL     string `toml:"mf_certs_url"`
}

Service represents service config.

type Thing

type Thing struct {
	Name     string                 `toml:"name"`
	Metadata map[string]interface{} `toml:"metadata" mapstructure:"metadata"`
}

Directories

Path Synopsis
Package sdk contains Mainflux SDK wrapper with extended new bootstrapping and certs management features.
Package sdk contains Mainflux SDK wrapper with extended new bootstrapping and certs management features.

Jump to

Keyboard shortcuts

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