backends

package
v0.0.0-...-5968118 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFilesJWTChecker

func NewFilesJWTChecker(authOpts map[string]string, logLevel log.Level, hasher hashing.HashComparer, options tokenOptions) (jwtChecker, error)

func NewJsJWTChecker

func NewJsJWTChecker(authOpts map[string]string, options tokenOptions) (jwtChecker, error)

func NewLocalJWTChecker

func NewLocalJWTChecker(authOpts map[string]string, logLevel log.Level, hasher hashing.HashComparer, options tokenOptions) (jwtChecker, error)

NewLocalJWTChecker initializes a checker with a local DB.

func NewRemoteJWTChecker

func NewRemoteJWTChecker(authOpts map[string]string, options tokenOptions, version string) (jwtChecker, error)

func OpenDatabase

func OpenDatabase(dsn, engine string, tries int, maxLifeTime int64) (*sqlx.DB, error)

OpenDatabase opens the database and performs a ping to make sure the database is up. Taken from brocaar's lora-app-server: https://github.com/brocaar/lora-app-server

Types

type Backend

type Backend interface {
	GetUser(username, password, clientid string) (bool, error)
	GetSuperuser(username string) (bool, error)
	CheckAcl(username, topic, clientId string, acc int32) (bool, error)
	GetName() string
	Halt()
}

type Backends

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

func Initialize

func Initialize(authOpts map[string]string, logLevel log.Level, version string) (*Backends, error)

Initialize sets general options, tries to build the backends and register their checkers.

func (*Backends) AuthAclCheck

func (b *Backends) AuthAclCheck(clientid, username, topic string, acc int) (bool, error)

AuthAclCheck checks user/topic/acc authorization.

func (*Backends) AuthUnpwdCheck

func (b *Backends) AuthUnpwdCheck(username, password, clientid string) (bool, error)

AuthUnpwdCheck checks user authentication.

func (*Backends) Halt

func (b *Backends) Halt()

type CustomPlugin

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

func NewCustomPlugin

func NewCustomPlugin(authOpts map[string]string, logLevel log.Level) (*CustomPlugin, error)

func (*CustomPlugin) CheckAcl

func (o *CustomPlugin) CheckAcl(username, topic, clientid string, acc int32) (bool, error)

func (*CustomPlugin) GetName

func (o *CustomPlugin) GetName() string

func (*CustomPlugin) GetSuperuser

func (o *CustomPlugin) GetSuperuser(username string) (bool, error)

func (*CustomPlugin) GetUser

func (o *CustomPlugin) GetUser(username, password, clientid string) (bool, error)

func (*CustomPlugin) Halt

func (o *CustomPlugin) Halt()

type Files

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

Files hols a static failes checker.

func NewFiles

func NewFiles(authOpts map[string]string, logLevel log.Level, hasher hashing.HashComparer) (*Files, error)

NewFiles initializes a files backend.

func (*Files) CheckAcl

func (o *Files) CheckAcl(username, topic, clientid string, acc int32) (bool, error)

CheckAcl checks that the topic may be read/written by the given user/clientid.

func (*Files) GetName

func (o *Files) GetName() string

GetName returns the backend's name

func (*Files) GetSuperuser

func (o *Files) GetSuperuser(username string) (bool, error)

GetSuperuser returns false for files backend.

func (*Files) GetUser

func (o *Files) GetUser(username, password, clientid string) (bool, error)

GetUser checks that user exists and password is correct.

func (*Files) Halt

func (o *Files) Halt()

Halt cleans up Files backend.

type GRPC

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

GRPC holds a client for the service and implements the Backend interface.

func NewGRPC

func NewGRPC(authOpts map[string]string, logLevel log.Level) (*GRPC, error)

NewGRPC tries to connect to the gRPC service at the given host.

func (*GRPC) CheckAcl

func (o *GRPC) CheckAcl(username, topic, clientid string, acc int32) (bool, error)

CheckAcl checks if the user has access to the given topic.

func (*GRPC) GetName

func (o *GRPC) GetName() string

GetName gets the gRPC backend's name.

func (*GRPC) GetSuperuser

func (o *GRPC) GetSuperuser(username string) (bool, error)

GetSuperuser checks that the user is a superuser.

func (*GRPC) GetUser

func (o *GRPC) GetUser(username, password, clientid string) (bool, error)

GetUser checks that the username exists and the given password hashes to the same password.

func (*GRPC) Halt

func (o *GRPC) Halt()

Halt signals the gRPC backend that mosquitto is halting.

type HTTP

type HTTP struct {
	UserUri      string
	SuperuserUri string
	AclUri       string
	UserAgent    string
	Host         string
	Port         string
	WithTLS      bool
	VerifyPeer   bool
	ParamsMode   string

	ResponseMode string
	Timeout      int
	Client       *h.Client
	// contains filtered or unexported fields
}

func NewHTTP

func NewHTTP(authOpts map[string]string, logLevel log.Level, version string) (HTTP, error)

func (HTTP) CheckAcl

func (o HTTP) CheckAcl(username, topic, clientid string, acc int32) (bool, error)

func (HTTP) GetName

func (o HTTP) GetName() string

GetName returns the backend's name

func (HTTP) GetSuperuser

func (o HTTP) GetSuperuser(username string) (bool, error)

func (HTTP) GetUser

func (o HTTP) GetUser(username, password, clientid string) (bool, error)

func (HTTP) Halt

func (o HTTP) Halt()

Halt does nothing for http as there's no cleanup needed.

type HTTPResponse

type HTTPResponse struct {
	Ok    bool   `json:"ok"`
	Error string `json:"error"`
}

type JWT

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

func NewJWT

func NewJWT(authOpts map[string]string, logLevel log.Level, hasher hashing.HashComparer, version string) (*JWT, error)

func (*JWT) CheckAcl

func (o *JWT) CheckAcl(token, topic, clientid string, acc int32) (bool, error)

CheckAcl checks user authorization.

func (*JWT) GetName

func (o *JWT) GetName() string

GetName returns the backend's name

func (*JWT) GetSuperuser

func (o *JWT) GetSuperuser(token string) (bool, error)

GetSuperuser checks if the given user is a superuser.

func (*JWT) GetUser

func (o *JWT) GetUser(token, password, clientid string) (bool, error)

GetUser authenticates a given user.

func (*JWT) Halt

func (o *JWT) Halt()

Halt closes any db connection.

type Javascript

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

func NewJavascript

func NewJavascript(authOpts map[string]string, logLevel log.Level) (*Javascript, error)

func (*Javascript) CheckAcl

func (o *Javascript) CheckAcl(username, topic, clientid string, acc int32) (bool, error)

func (*Javascript) GetName

func (o *Javascript) GetName() string

GetName returns the backend's name

func (*Javascript) GetSuperuser

func (o *Javascript) GetSuperuser(username string) (bool, error)

func (*Javascript) GetUser

func (o *Javascript) GetUser(username, password, clientid string) (bool, error)

func (*Javascript) Halt

func (o *Javascript) Halt()

type Mongo

type Mongo struct {
	Host            string
	Port            string
	Username        string
	Password        string
	SaltEncoding    string
	DBName          string
	AuthSource      string
	UsersCollection string
	AclsCollection  string
	Conn            *mongo.Client
	// contains filtered or unexported fields
}

func NewMongo

func NewMongo(authOpts map[string]string, logLevel log.Level, hasher hashing.HashComparer) (Mongo, error)

func (Mongo) CheckAcl

func (o Mongo) CheckAcl(username, topic, clientid string, acc int32) (bool, error)

CheckAcl gets all acls for the username and tries to match against topic, acc, and username/clientid if needed.

func (Mongo) GetName

func (o Mongo) GetName() string

GetName returns the backend's name

func (Mongo) GetSuperuser

func (o Mongo) GetSuperuser(username string) (bool, error)

GetSuperuser checks that the key username:su exists and has value "true".

func (Mongo) GetUser

func (o Mongo) GetUser(username, password, clientid string) (bool, error)

GetUser checks that the username exists and the given password hashes to the same password.

func (Mongo) Halt

func (o Mongo) Halt()

Halt closes the mongo session.

type MongoAcl

type MongoAcl struct {
	Topic string `bson:"topic"`
	Acc   int32  `bson:"acc"`
}

type MongoUser

type MongoUser struct {
	Username     string     `bson:"username"`
	PasswordHash string     `bson:"password"`
	Superuser    bool       `bson:"superuser"`
	Acls         []MongoAcl `bson:"acls"`
}

type Mysql

type Mysql struct {
	DB                   *sqlx.DB
	Host                 string
	Port                 string
	DBName               string
	User                 string
	Password             string
	UserQuery            string
	SuperuserQuery       string
	AclQuery             string
	SSLMode              string
	SSLCert              string
	SSLKey               string
	SSLRootCert          string
	Protocol             string
	SocketPath           string
	AllowNativePasswords bool
	// contains filtered or unexported fields
}

Mysql holds all fields of the Mysql db connection.

func NewMysql

func NewMysql(authOpts map[string]string, logLevel log.Level, hasher hashing.HashComparer) (Mysql, error)

func (Mysql) CheckAcl

func (o Mysql) CheckAcl(username, topic, clientid string, acc int32) (bool, error)

CheckAcl gets all acls for the username and tries to match against topic, acc, and username/clientid if needed.

func (Mysql) GetName

func (o Mysql) GetName() string

GetName returns the backend's name

func (Mysql) GetSuperuser

func (o Mysql) GetSuperuser(username string) (bool, error)

GetSuperuser checks that the username meets the superuser query.

func (Mysql) GetUser

func (o Mysql) GetUser(username, password, clientid string) (bool, error)

GetUser checks that the username exists and the given password hashes to the same password.

func (Mysql) Halt

func (o Mysql) Halt()

Halt closes the mysql connection.

type Postgres

type Postgres struct {
	DB             *sqlx.DB
	Host           string
	Port           string
	DBName         string
	User           string
	Password       string
	UserQuery      string
	SuperuserQuery string
	AclQuery       string
	SSLMode        string
	SSLCert        string
	SSLKey         string
	SSLRootCert    string
	// contains filtered or unexported fields
}

Postgres holds all fields of the postgres db connection.

func NewPostgres

func NewPostgres(authOpts map[string]string, logLevel log.Level, hasher hashing.HashComparer) (Postgres, error)

func (Postgres) CheckAcl

func (o Postgres) CheckAcl(username, topic, clientid string, acc int32) (bool, error)

CheckAcl gets all acls for the username and tries to match against topic, acc, and username/clientid if needed.

func (Postgres) GetName

func (o Postgres) GetName() string

GetName returns the backend's name

func (Postgres) GetSuperuser

func (o Postgres) GetSuperuser(username string) (bool, error)

GetSuperuser checks that the username meets the superuser query.

func (Postgres) GetUser

func (o Postgres) GetUser(username, password, clientid string) (bool, error)

GetUser checks that the username exists and the given password hashes to the same password.

func (Postgres) Halt

func (o Postgres) Halt()

Halt closes the mysql connection.

type Redis

type Redis struct {
	Host         string
	Port         string
	Password     string
	SaltEncoding string
	DB           int32
	// contains filtered or unexported fields
}

func NewRedis

func NewRedis(authOpts map[string]string, logLevel log.Level, hasher hashing.HashComparer) (Redis, error)

func (Redis) CheckAcl

func (o Redis) CheckAcl(username, topic, clientid string, acc int32) (bool, error)

func (Redis) GetName

func (o Redis) GetName() string

GetName returns the backend's name

func (Redis) GetSuperuser

func (o Redis) GetSuperuser(username string) (bool, error)

GetSuperuser checks that the key username:su exists and has value "true".

func (Redis) GetUser

func (o Redis) GetUser(username, password, _ string) (bool, error)

GetUser checks that the username exists and the given password hashes to the same password.

func (Redis) Halt

func (o Redis) Halt()

Halt terminates the connection.

type RedisClient

type RedisClient interface {
	Get(ctx context.Context, key string) *goredis.StringCmd
	SMembers(ctx context.Context, key string) *goredis.StringSliceCmd
	Ping(ctx context.Context) *goredis.StatusCmd
	Close() error
	FlushDB(ctx context.Context) *goredis.StatusCmd
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *goredis.StatusCmd
	SAdd(ctx context.Context, key string, members ...interface{}) *goredis.IntCmd
	Expire(ctx context.Context, key string, expiration time.Duration) *goredis.BoolCmd
	ReloadState(ctx context.Context)
}

type Response

type Response struct {
	Ok    bool   `json:"ok"`
	Error string `json:"error"`
}

type SingleRedisClient

type SingleRedisClient struct {
	*goredis.Client
}

func (SingleRedisClient) ReloadState

func (c SingleRedisClient) ReloadState(ctx context.Context)

type Sqlite

type Sqlite struct {
	DB             *sqlx.DB
	Source         string
	UserQuery      string
	SuperuserQuery string
	AclQuery       string
	// contains filtered or unexported fields
}

Sqlite holds all fields of the sqlite db connection.

func NewSqlite

func NewSqlite(authOpts map[string]string, logLevel log.Level, hasher hashing.HashComparer) (Sqlite, error)

func (Sqlite) CheckAcl

func (o Sqlite) CheckAcl(username, topic, clientid string, acc int32) (bool, error)

CheckAcl gets all acls for the username and tries to match against topic, acc, and username/clientid if needed.

func (Sqlite) GetName

func (o Sqlite) GetName() string

GetName returns the backend's name

func (Sqlite) GetSuperuser

func (o Sqlite) GetSuperuser(username string) (bool, error)

GetSuperuser checks that the username meets the superuser query.

func (Sqlite) GetUser

func (o Sqlite) GetUser(username, password, clientid string) (bool, error)

GetUser checks that the username exists and the given password hashes to the same password.

func (Sqlite) Halt

func (o Sqlite) Halt()

Halt closes the mysql connection.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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