backends

package
v0.0.0-...-efde164 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2018 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HashIterations = 100000

HashIterations defines the number of hash iterations.

Functions

This section is empty.

Types

type AclRecord

type AclRecord struct {
	Topic string
	Acc   byte //None 0x00, Read 0x01, Write 0x02, ReadWrite: Read | Write : 0x03
}

AclRecord holds a topic and access privileges.

type Claims

type Claims struct {
	jwt.StandardClaims

	// Username defines the identity of the user.
	Username string `json:"username"`
}

Claims defines the struct containing the token claims.

type FileUser

type FileUser struct {
	Password   string
	AclRecords []AclRecord
}

FileUer keeps a user password and acl records.

type Files

type Files struct {
	PasswordPath string
	AclPath      string
	CheckAcls    bool
	Users        map[string]*FileUser //Users keeps a registry of username/FileUser pairs, holding a user's password and Acl records.
	AclRecords   []AclRecord
}

FileBE holds paths to files, list of file users and general (no user or pattern) acl records.

func NewFiles

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

NewFiles initializes a files backend.

func (Files) CheckAcl

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

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

GetSuperuser returns false for files backend.

func (Files) GetUser

func (o Files) GetUser(username, password string) bool

GetUser checks that user exists and password is correct.

func (Files) Halt

func (o Files) Halt()

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

type HTTP

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

func NewHTTP

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

func (HTTP) CheckAcl

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

func (HTTP) GetName

func (o HTTP) GetName() string

GetName returns the backend's name

func (HTTP) GetSuperuser

func (o HTTP) GetSuperuser(username string) bool

func (HTTP) GetUser

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

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 {
	Remote  bool
	LocalDB string

	Postgres       Postgres
	Mysql          Mysql
	Secret         string
	UserQuery      string
	SuperuserQuery string
	AclQuery       string

	UserUri      string
	SuperuserUri string
	AclUri       string
	Host         string
	Port         string
	WithTLS      bool
	VerifyPeer   bool

	ParamsMode   string
	ResponseMode string
}

func NewJWT

func NewJWT(authOpts map[string]string, logLevel log.Level) (JWT, error)

func (JWT) CheckAcl

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

func (JWT) GetName

func (o JWT) GetName() string

GetName returns the backend's name

func (JWT) GetSuperuser

func (o JWT) GetSuperuser(token string) bool

func (JWT) GetUser

func (o JWT) GetUser(token, password string) bool

func (JWT) Halt

func (o JWT) Halt()

Halt closes any DB connection.

type Mongo

type Mongo struct {
	Host            string
	Port            string
	Username        string
	Password        string
	DBName          string
	UsersCollection string
	AclsCollection  string
	Conn            *mgo.Session
}

func NewMongo

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

func (Mongo) CheckAcl

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

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

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

func (Mongo) GetUser

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

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
}

Mysql holds all fields of the Mysql db connection.

func NewMysql

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

func (Mysql) CheckAcl

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

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

GetSuperuser checks that the username meets the superuser query.

func (Mysql) GetUser

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

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
}

Postgres holds all fields of the postgres db connection.

func NewPostgres

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

func (Postgres) CheckAcl

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

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

GetSuperuser checks that the username meets the superuser query.

func (Postgres) GetUser

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

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
	DB       int32
	Conn     *goredis.Client
}

func NewRedis

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

func (Redis) CheckAcl

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

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

func (Redis) GetName

func (o Redis) GetName() string

GetName returns the backend's name

func (Redis) GetSuperuser

func (o Redis) GetSuperuser(username string) bool

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

func (Redis) GetUser

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

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 Response

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

type Sqlite

type Sqlite struct {
	DB             *sqlx.DB
	Source         string
	UserQuery      string
	SuperuserQuery string
	AclQuery       string
}

Sqlite holds all fields of the sqlite db connection.

func NewSqlite

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

func (Sqlite) CheckAcl

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

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

GetSuperuser checks that the username meets the superuser query.

func (Sqlite) GetUser

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

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.

Jump to

Keyboard shortcuts

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