model

package
v0.0.0-...-720f425 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2016 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserNotExist user not found error message
	ErrUserNotExist = errors.New("User does not exist")
)

Functions

func CreateUser

func CreateUser(u *User) error

CreateUser creates record of a new user.

func GetUserSalt

func GetUserSalt() string

GetUserSalt returns a user salt token

func IsEmailUsed

func IsEmailUsed(email string) (bool, error)

IsEmailUsed returns true if the e-mail has been used.

func LoadDefaultSavedQueries

func LoadDefaultSavedQueries() error

LoadDefaultSavedQueries Load all of the default saved queries. This will only run once on initial database creation.

func NewDatabase

func NewDatabase(c *config.Config) (*xorm.Engine, error)

NewDatabase will create, connect return a postgres connection pool

func NewSavedQuery

func NewSavedQuery(s SavedQuery) error

NewSavedQuery will iadd a new saved query to the database.

func UniqueKey

func UniqueKey() string

UniqueKey returns a new v4 uuid

Types

type AllNodeOptions

type AllNodeOptions struct {
	OnlyEnabled bool
}

AllNodeOptions for AllNodes query

type Category

type Category struct {
	Id int64

	ConfigId int64

	Name        string
	Description string

	Color string
}

Category table

type Config

type Config struct {
	Id int64
}

Config table

type Node

type Node struct {
	Id int64 `json:"id"`

	Key     string `xorm:"UNIQUE NOT NULL" json:"key"`
	Address string `json:"address"`
	Name    string `xorm:"INDEX NOT NULL" json:"name"`
	Enabled bool   `xorm:"INDEX NOT NULL" json:"enabled"`

	Created time.Time `xorm:"CREATED" json:"created"`
	Updated time.Time `xorm:"UPDATED" json:"updated"`
}

Node database table schema

func AllNodes

func AllNodes(options *AllNodeOptions) ([]*Node, error)

AllNodes Return all nodes in the database

func CreateOrUpdateNode

func CreateOrUpdateNode(req *osquery.EnrollReq) (*Node, error)

CreateOrUpdateNode will create or update a node from a enroll request

func FindAndUpdateNode

func FindAndUpdateNode(req *osquery.KeyReq) (*Node, error)

FindAndUpdateNode node by node key which is also the osquery host id

func FindNodeByNodeKey

func FindNodeByNodeKey(key string) (*Node, error)

FindNodeByNodeKey node by node key which is also the osquery host id

func FindNodeByRequest

func FindNodeByRequest(c *gin.Context, req *osquery.KeyReq) (*Node, error)

FindNodeByRequest takes the osquery request and returns a node from the database

func (*Node) Delete

func (n *Node) Delete() error

Delete node from the database.

func (*Node) JSON

func (n *Node) JSON() []byte

JSON node format

func (*Node) Update

func (n *Node) Update() error

Update node information

type SavedQuery

type SavedQuery struct {
	Id    int64  `json:"id"`
	Name  string `xorm:"NOT NULL" from:"name" binding:"required"`
	Query string `xorm:"NOT NULL" from:"query" binding:"required"`
	Type  string `xorm:"NOT NULL" form:"type" binding:"required"`
}

SavedQuery database table.

func AllSavedQueries

func AllSavedQueries() ([]*SavedQuery, error)

AllSavedQueries returns all saved queries in the database.

func FindSavedQueryById

func FindSavedQueryById(id int64) (*SavedQuery, error)

FindSavedQueryById a saved query by its id.

func (*SavedQuery) Delete

func (s *SavedQuery) Delete() error

Delete a saved query

type User

type User struct {
	Id   int64
	Name string `xorm:"NOT NULL" json:"name"`

	Key         string `xorm:"UNIQUE INDEX NOT NULL" json:"key"`
	Email       string `xorm:"UNIQUE NOT NULL" json:"email"`
	Avatar      string `xorm:"VARCHAR(2048) NOT NULL" json:"avatar"`
	AvatarEmail string `xorm:"NOT NULL" json:"-"`

	Password string `xorm:"NOT NULL" json:"-"`
	Hash     string `xorm:"VARCHAR(10)" json:"-"`
	Salt     string `xorm:"VARCHAR(10)" json:"-"`

	Admin   bool `json:"admin"`
	Enabled bool `json:"enabled"`
}

User database table schema

func GetUserByEmail

func GetUserByEmail(email string) (*User, error)

GetUserByEmail returns the user object by given e-mail if exists.

func GetUserById

func GetUserById(id int64) (*User, error)

GetUserById returns the user object by given ID if exists.

func UserLogin

func UserLogin(email, password string) (*User, error)

UserLogin validates user name and password.

func (u *User) AvatarLink() string

AvatarLink Users avatar link. Using gravatar

func (*User) EncodePassword

func (u *User) EncodePassword()

EncodePassword encodes password to safe format.

func (*User) Exists

func (u *User) Exists() bool

Exists returns true or false based on the user context

func (*User) ValidatePassword

func (u *User) ValidatePassword(passwd string) bool

ValidatePassword checks if given password matches the one belongs to the user.

Jump to

Keyboard shortcuts

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