database

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const MaxAgentRules = 100
View Source
const MaxAlertAfter = 21600 // 6 hours
View Source
const MaxAlertPeriod = 10800 // 3 hours
View Source
const MinAgentNameLength = 3
View Source
const MinAlertAfter = 30 // 30 seconds
View Source
const MinAlertPeriod = 1800 // 30 minutes
View Source
const MinPasswordLength = 8

Variables

This section is empty.

Functions

func Delete

func Delete(v interface{}) error

func Save added in v1.1.0

func Save(v interface{}) error

func Setup

func Setup(config Config) (err error)

func ToJSONB

func ToJSONB(v interface{}) datatypes.JSON

func UpdateAgent

func UpdateAgent(agent *Agent, fields *AgentWritableFields) error

func VerifyUser

func VerifyUser(verification string) error

Types

type Agent

type Agent struct {
	ID          uint           `gorm:"primarykey" json:"id"`
	CreatedAt   time.Time      `gorm:"index" json:"created_at"`
	UpdatedAt   time.Time      `gorm:"index" json:"updated_at"`
	SeenAt      time.Time      `gorm:"index" json:"seen_at"`
	DeletedAt   gorm.DeletedAt `gorm:"index" json:"-"`
	UserID      uint           `gorm:"index" json:"-"`
	AlertAfter  uint           `gorm:"index" json:"alert_after"`
	AlertPeriod uint           `gorm:"index" json:"alert_period"`
	AlertAt     time.Time      `gorm:"index" json:"alert_at"`
	Name        string         `json:"name"`
	Rules       datatypes.JSON `sql:"type:jsonb" json:"rules"`
	Token       string         `gorm:"index" json:"token"`
	Address     string         `json:"address"`
	UserAgent   string         `json:"user_agent"`
}

func FindAgentByToken

func FindAgentByToken(token string) (*Agent, error)

func FindAgentsForAlert added in v1.1.0

func FindAgentsForAlert() ([]*Agent, error)

func RegisterAgent

func RegisterAgent(fields *AgentWritableFields) (*Agent, error)

func (*Agent) Save

func (a *Agent) Save() error

type AgentWritableFields added in v1.1.0

type AgentWritableFields struct {
	ID          uint
	Name        string
	Rules       []*firewall.Rule
	User        *User
	AlertAfter  uint
	AlertPeriod uint
}

func (*AgentWritableFields) Validate added in v1.1.0

func (f *AgentWritableFields) Validate() error

type Config

type Config struct {
	Hostname string `yaml:"host"`
	Port     int    `yaml:"port"`
	User     string `yaml:"user"`
	Password string `yaml:"password"`
	Name     string `yaml:"name"`
}

type JSONB

type JSONB map[string]interface{}

func (*JSONB) Scan

func (j *JSONB) Scan(value interface{}) error

func (JSONB) Value

func (j JSONB) Value() (driver.Value, error)

type User

type User struct {
	ID           uint           `gorm:"primarykey" json:"-""`
	CreatedAt    time.Time      `gorm:"index" json:"created_at"`
	UpdatedAt    time.Time      `gorm:"index" json:"updated_at"`
	DeletedAt    gorm.DeletedAt `gorm:"index" json:"-"`
	Email        string         `gorm:"uniqueIndex" json:"email"`
	Verification string         `gorm:"index" json:"-"`
	Verified     bool           `gorm:"index" json:"-"`
	Use2FA       bool           `gorm:"default:true" json:"use_2fa"` // i know it's not 2fa yet
	Hash         string         `json:"-"`
	Address      string         `json:"address"`
	Agents       []Agent        `json:"-"`
}

func FindUserByID

func FindUserByID(id int) (*User, error)

func LoginUser

func LoginUser(address, email, password string) (*User, error)

func RegisterUser

func RegisterUser(address, email, password string) (*User, error)

func UpdateUser

func UpdateUser(user *User, ip string, newPassword string, use2FA bool) (*User, error)

Jump to

Keyboard shortcuts

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