models

package
v0.0.0-...-efd50ba Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimezone = "Asia/Shanghai"
View Source
const SALT = "MONGOUSERSALT"
View Source
const TLSMinVersionDefault = tls.VersionTLS12

Variables

This section is empty.

Functions

func ParseTLSVersion

func ParseTLSVersion(version string) (uint16, error)

ParseTLSVersion returns a `uint16` by received version string key that represents tls version from crypto/tls. If version isn't supported ParseTLSVersion returns 0 with error

Types

type Application

type Application struct {
	ID          primitive.ObjectID       `json:"ID" bson:"_id"`
	Name        string                   `json:"Name" bson:"Name"`
	Description string                   `json:"Description" bson:"Description"`
	UserID      primitive.ObjectID       `json:"UserID" bson:"UserID"`
	CreatedAt   time.Time                `json:"CreatedAt" bson:"CreatedAt"`
	Scheme      string                   `json:"Scheme" bson:"Scheme"`
	Active      bool                     `json:"Active" bson:"Active"`
	Public      ApplicationPublicOptions `json:"Public" bson:"Public"`
	Options     bson.M                   `json:"Options" bson:"Options"`
}

func (*Application) User

func (this *Application) User() (*User, error)

type ApplicationPublicOptions

type ApplicationPublicOptions struct {
	Multiplier  uint     `json:"Multiplier" bson:"Multiplier"`
	Threshold   int      `json:"Threshold" bson:"Threshold"`
	TriggerList []string `json:"TriggerList" bson:"TriggerList"`
}

type EnvoyEmail

type EnvoyEmail struct {
	EnvoyHeader `json:"EnvoyHeader" bson:"EnvoyHeader"`
	ID          primitive.ObjectID `json:"ID" bson:"_id"`
	Address     string             `json:"Address" bson:"Address"`
}

type EnvoyGotify

type EnvoyGotify struct {
	EnvoyHeader `json:"EnvoyHeader" bson:"EnvoyHeader"`
	ID          primitive.ObjectID `json:"ID" bson:"_id"`
	URL         string             `json:"URL" bson:"URL"`
	Token       string             `json:"Token" bson:"Token"`
}

type EnvoyHeader

type EnvoyHeader struct {
	UserID       primitive.ObjectID `json:"UserID" bson:"UserID"`
	CreatedAt    time.Time          `json:"CreatedAt" bson:"CreatedAt"`
	OfflineAlert bool               `json:"OfflineAlert" bson:"OfflineAlert"`
	Sensitive    int                `json:"Sensitive" bson:"Sensitive"`
}

type EnvoyLog

type EnvoyLog struct {
	ID             primitive.ObjectID `json:"ID" bson:"_id"`
	SendTime       time.Time          `json:"SendTime" bson:"SendTime"`
	Success        bool               `json:"Success" bson:"Success"`
	FailedMessage  string             `json:"FailedMessage" bson:"FailedMessage"`
	OfflineLogID   primitive.ObjectID `json:"OfflineLogID" bson:"OfflineLogID"`
	PolicyType     string             `json:"PolicyType" bson:"PolicyType"`
	PolicySnapShot bson.M             `json:"PolicySnapShot" bson:"PolicySnapShot"`
}

type EnvoyNtfy

type EnvoyNtfy struct {
	EnvoyHeader `json:"EnvoyHeader" bson:"EnvoyHeader"`
	ID          primitive.ObjectID `json:"ID" bson:"_id"`
}

type EnvoyPolicy

type EnvoyPolicy struct {
	PolicyID   primitive.ObjectID `json:"PolicyID" bson:"PolicyID"`
	PolicyType EnvoyPolicyType    `json:"PolicyType" bson:"PolicyType"`
}

type EnvoyPolicyType

type EnvoyPolicyType int
const (
	IsEnvoyEmail EnvoyPolicyType = iota + 1000
	IsEnvoyGotify
	IsEnvoySMS
	IsEnvoyTelegram
	IsEnvoyWebhook
)

func (EnvoyPolicyType) GetCollection

func (this EnvoyPolicyType) GetCollection() *mongo.Collection

type EnvoyTelegram

type EnvoyTelegram struct {
	EnvoyHeader `json:"EnvoyHeader" bson:"EnvoyHeader"`
	ID          primitive.ObjectID `json:"ID" bson:"_id"`
	ChatID      int64              `json:"ChatID" bson:"ChatID"`
}

type EnvoyWebhook

type EnvoyWebhook struct {
	EnvoyHeader   `json:"EnvoyHeader" bson:"EnvoyHeader"`
	ID            primitive.ObjectID `json:"ID" bson:"_id"`
	URL           string             `json:"URL" bson:"URL"`
	Insecure      bool               `json:"Insecure" bson:"Insecure"`     // true: HTTP, false: HTTPS
	AuthMethod    string             `json:"AuthMethod" bson:"AuthMethod"` // "None" "Basic" "Bearer"
	BasicUsername string             `json:"BasicUsername" bson:"BasicUsername"`
	BasicPassword string             `json:"BasicPassword" bson:"BasicPassword"`
	BearerToken   string             `json:"BearerToken" bson:"BearerToken"`
}

type OfflineLog

type OfflineLog struct {
	ID             primitive.ObjectID `bson:"_id"`
	EntityID       primitive.ObjectID `bson:"EntityID"`
	OfflineTime    time.Time          `bson:"OfflineTime"`
	OfflineMessage string             `bson:"OfflineMessage"`
	OnlineTime     time.Time          `bson:"OnlineTime"`
	SentryLogs     []SentryLog        `bson:"SentryLogs"`
}

type SentryLog

type SentryLog struct {
	SentryName   string    `bson:"SentryName"`
	SentryTime   time.Time `bson:"SentryTime"`
	ErrorMessage string    `bson:"ErrorMessage"`
}

type TLS

type TLS struct {
	ID     primitive.ObjectID `json:"ID" bson:"_id"`
	UserID primitive.ObjectID `json:"UserID" bson:"UserID"`
	Name   string             `json:"Name" bson:"Name"`
	// TLS Settings
	TLSCA         string `json:"TLSCA" bson:"TLSCA"`
	TLSCert       string `json:"TLSCert" bson:"TLSCert"`
	TLSKey        string `json:"TLSKey" bson:"TLSKey"`
	TLSKeyPwd     string `json:"TLSKeyPwd" bson:"TLSKeyPwd"`
	TLSMinVersion string `json:"TLSMinVersion" bson:"TLSMinVersion"` // "TLS10" "TLS11" "TLS12" "TLS13"
	Insecure      bool   `json:"Insecure" bson:"Insecure"`
}

func (*TLS) TLSConfig

func (this *TLS) TLSConfig() (*tls.Config, error)

func (*TLS) User

func (this *TLS) User() (*User, error)

type Timezone

type Timezone string

func (Timezone) Location

func (this Timezone) Location() *time.Location

type User

type User struct {
	ID             primitive.ObjectID `json:"ID" bson:"_id"`
	Email          string             `json:"Email" bson:"Email"`
	Password       string             `json:"Password" bson:"Password"`
	CreatedAt      time.Time          `json:"CreatedAt" bson:"CreatedAt"`
	Level          UserLevel          `json:"Level" bson:"Level"` // default(free) level: 0
	LevelExpireAt  time.Time          `json:"LevelExpireAt" bson:"LevelExpireAt"`
	Usage          UserUsage          `json:"Usage" bson:"Usage"`
	EnvoyPolicies  []EnvoyPolicy      `json:"EnvoyPolicies" bson:"EnvoyPolicies"`
	Timezone       Timezone           `json:"Timezone" bson:"Timezone"`
	CustomSentries []string           `json:"CustomSentries" bson:"CustomSentries"`
}

func NewUser

func NewUser() *User

func (*User) CheckPassword

func (this *User) CheckPassword(pwd string) bool

func (*User) SetPassword

func (this *User) SetPassword(ctx context.Context, pwd string) error

func (*User) SetUserLevel

func (this *User) SetUserLevel(ctx context.Context, level UserLevel, ttl ...time.Duration) error

func (*User) UsageEntityAccessible

func (this *User) UsageEntityAccessible() bool

func (*User) UsageEntityIncr

func (this *User) UsageEntityIncr(ctx context.Context, delta int32) error

func (*User) UsageEnvoyAccessible

func (this *User) UsageEnvoyAccessible() bool

func (*User) UsageEnvoyIncr

func (this *User) UsageEnvoyIncr(ctx context.Context, delta int32) error

func (*User) UsageEnvoyPolicyAccessible

func (this *User) UsageEnvoyPolicyAccessible() bool

func (*User) UsageEnvoyPolicyIncr

func (this *User) UsageEnvoyPolicyIncr(ctx context.Context, delta int32) error

func (*User) UsageEnvoySMSAccessible

func (this *User) UsageEnvoySMSAccessible() bool

func (*User) UsageEnvoySMSIncr

func (this *User) UsageEnvoySMSIncr(ctx context.Context, delta int32) error

type UserGetter

type UserGetter interface {
	User() (*User, error)
}

type UserLevel

type UserLevel int32
const (
	UserLevelAdmin UserLevel = iota - 1
	UserLevelFree
	UserLevelBasic
	UserLevelStandard
	UserLevelPremium
)

func (UserLevel) Limit

func (this UserLevel) Limit() UserUsage

type UserLoginLog

type UserLoginLog struct {
	ID         primitive.ObjectID `json:"ID" bson:"_id"`
	UserID     primitive.ObjectID `json:"UserID" bson:"UserID"`
	LoginTime  time.Time          `json:"LoginTime" bson:"LoginTime"`
	Location   string             `json:"Location" bson:"Location"`
	Device     string             `json:"Device" bson:"Device"`
	DeviceType string             `json:"DeviceType" bson:"DeviceType"`
}

type UserUsage

type UserUsage struct {
	EnvoySMSCount    int32 `json:"EnvoySMSCount" bson:"EnvoySMSCount"`
	EnvoyCount       int32 `json:"EnvoyCount" bson:"EnvoyCount"`
	EntityCount      int32 `json:"EntityCount" bson:"EntityCount"`
	EnvoyPolicyCount int32 `json:"EnvoyPolicyCount" bson:"EnvoyPolicyCount"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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