Home

Awesome

Mainflux Licensing Service

coverage build

Licensing service

Concepts

License is used to validate a service on startup. License entity looks like this:

type License struct {
	ID        string                 `json:"id"`
	Key       string                 `json:"key"`
	Issuer    string                 `json:"issuer"`
	DeviceID  string                 `json:"device_id"`
	Active    bool                   `json:"active"`
	CreatedAt time.Time              `json:"created_at"`
	ExpiresAt time.Time              `json:"expires_at"`
	UpdatedBy string                 `json:"updated_by"`
	UpdatedAt time.Time              `json:"updated_at"`
	Services  []string               `json:"services"`
	Plan      map[string]interface{} `json:"plan"`
	Signature []byte                 `json:"signature"`
}

Please note that some of these fields are not used at the moment and are hare for the future use.

The licensing flow has two parts: service and agent.

Licensing service

Licensing service provides basic CRUD operations over License.

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.

VariableDescriptionDefault
MF_LICENSE_LOG_LEVELLicense service log levelerror
MF_LICENSE_DB_HOSTDB hostlocalhost
MF_LICENSE_DB_PORTDB port5432
MF_LICENSE_DB_USERDB usermainflux
MF_LICENSE_DB_PASSDB passmainflux
MF_LICENSE_DBDB namelicense
MF_LICENSE_DB_SSL_MODEDB SSL modedisable
MF_LICENSE_DB_SSL_CERTDB SSL cert in PEM
MF_LICENSE_DB_SSL_KEYDB SSL key
MF_LICENSE_DB_SSL_ROOT_CERTDB SSL root cert
MF_LICENSE_CLIENT_TLSClient TLSfalse
MF_LICENSE_CA_CERTSgRPC CA cert
MF_LICENSE_PORTservice HTTP port8111
MF_LICENSE_SERVER_CERTserver TLS cert
MF_LICENSE_SERVER_KEYserver TLS cert key
MF_JAEGER_URLtracing URL
MF_AUTH_URLAuth service URLlocalhost:8181
MF_AUTH_TIMEOUTAuth service call timeout1

Licensing Agent

The agent is an executable that's running on local machine and is used for license validation and synchronization with the service.

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

VariableDescriptionDefault
MF_LICENSE_LOG_LEVELAgent log level"error"
MF_LICENSE_SERVICE_URLLicense service URL"http://localhost:8111/licenses/devices"
LICENSE_FILEFile to store license in"./license"
MF_LICENSE_CLIENT_TLSHTTP client for License service"false"
MF_LICENSE_AGENT_CERTAgent TLS cert
MF_AGENT_SERVER_KEYAgen TLS cert key
MF_AGENT_PORTAgent port"3000"
MF_AGENT_LOAD_RETRY_SECONDSRetry period in seconds to wait between two sync calls to service"60"

The Agent fetches the License using its ID, and exposes HTTP API for validation. You can se the License validation flow on the diagram below:

diagram