dbmodels

package
v1.19.3 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ACLsByIdentifiers

func ACLsByIdentifiers(db *gorm.DB, identifiers []string) *gorm.DB

func ACLsPreload

func ACLsPreload(db *gorm.DB) *gorm.DB

func EventsByIdentifiers

func EventsByIdentifiers(db *gorm.DB, identifiers []string) *gorm.DB

func EventsPreload

func EventsPreload(db *gorm.DB) *gorm.DB

func GenericNameOrID added in v1.17.0

func GenericNameOrID(db *gorm.DB, identifiers []string) *gorm.DB

Generic Helper

func HostGroupsByIdentifiers

func HostGroupsByIdentifiers(db *gorm.DB, identifiers []string) *gorm.DB

func HostGroupsPreload

func HostGroupsPreload(db *gorm.DB) *gorm.DB

func HostsByIdentifiers

func HostsByIdentifiers(db *gorm.DB, identifiers []string) *gorm.DB

func HostsPreload

func HostsPreload(db *gorm.DB) *gorm.DB

func InitValidator added in v1.12.4

func InitValidator()

func IsValidHostLoggingMode added in v1.13.0

func IsValidHostLoggingMode(name string) bool

func SSHKeysByIdentifiers

func SSHKeysByIdentifiers(db *gorm.DB, identifiers []string) *gorm.DB

func SSHKeysPreload

func SSHKeysPreload(db *gorm.DB) *gorm.DB

func SessionsByIdentifiers

func SessionsByIdentifiers(db *gorm.DB, identifiers []string) *gorm.DB

func SessionsPreload

func SessionsPreload(db *gorm.DB) *gorm.DB

func UserGroupsByIdentifiers

func UserGroupsByIdentifiers(db *gorm.DB, identifiers []string) *gorm.DB

func UserGroupsPreload

func UserGroupsPreload(db *gorm.DB) *gorm.DB

func UserKeysByIdentifiers

func UserKeysByIdentifiers(db *gorm.DB, identifiers []string) *gorm.DB

func UserKeysByUserID added in v1.16.0

func UserKeysByUserID(db *gorm.DB, identifiers []string) *gorm.DB

func UserKeysPreload

func UserKeysPreload(db *gorm.DB) *gorm.DB

func UserRolesByIdentifiers

func UserRolesByIdentifiers(db *gorm.DB, identifiers []string) *gorm.DB

func UsersByIdentifiers

func UsersByIdentifiers(db *gorm.DB, identifiers []string) *gorm.DB

func UsersPreload

func UsersPreload(db *gorm.DB) *gorm.DB

Types

type ACL

type ACL struct {
	gorm.Model
	HostGroups  []*HostGroup `gorm:"many2many:host_group_acls;"`
	UserGroups  []*UserGroup `gorm:"many2many:user_group_acls;"`
	HostPattern string       `valid:"optional"`
	Action      string       `valid:"required"`
	Weight      uint         ``
	Comment     string       `valid:"optional"`
	Inception   *time.Time
	Expiration  *time.Time
}

type ACLAction

type ACLAction string
const (
	ACLActionAllow ACLAction = "allow"
	ACLActionDeny  ACLAction = "deny"
)

type BastionScheme

type BastionScheme string
const (
	BastionSchemeSSH    BastionScheme = "ssh"
	BastionSchemeTelnet BastionScheme = "telnet"
)

type Config

type Config struct {
	SSHKeys    []*SSHKey    `json:"keys"`
	Hosts      []*Host      `json:"hosts"`
	UserKeys   []*UserKey   `json:"user_keys"`
	Users      []*User      `json:"users"`
	UserGroups []*UserGroup `json:"user_groups"`
	HostGroups []*HostGroup `json:"host_groups"`
	ACLs       []*ACL       `json:"acls"`
	Settings   []*Setting   `json:"settings"`
	Events     []*Event     `json:"events"`
	Sessions   []*Session   `json:"sessions"`
	// FIXME: add latest migration
	Date time.Time `json:"date"`
}

type Event

type Event struct {
	gorm.Model
	Author   *User                  `gorm:"ForeignKey:AuthorID"`
	AuthorID uint                   `valid:"optional"`
	Domain   string                 `valid:"required"`
	Action   string                 `valid:"required"`
	Entity   string                 `valid:"optional"`
	Args     []byte                 `sql:"size:10000" valid:"optional,length(1|10000)" json:"-"`
	ArgsMap  map[string]interface{} `gorm:"-" json:"Args"`
}

func NewEvent

func NewEvent(domain, action string) *Event

func (*Event) Log

func (e *Event) Log(db *gorm.DB)

func (*Event) SetArg

func (e *Event) SetArg(name string, value interface{}) *Event

func (*Event) SetAuthor

func (e *Event) SetAuthor(user *User) *Event

func (*Event) String

func (e *Event) String() string

type Host

type Host struct {
	// FIXME: use uuid for ID
	gorm.Model
	Name     string       `gorm:"index:uix_hosts_name,unique;type:varchar(255)" valid:"required,length(1|255)"`
	Addr     string       `valid:"optional"` // FIXME: to be removed in a future version in favor of URL
	User     string       `valid:"optional"` // FIXME: to be removed in a future version in favor of URL
	Password string       `valid:"optional"` // FIXME: to be removed in a future version in favor of URL
	URL      string       `valid:"optional"`
	SSHKey   *SSHKey      `gorm:"ForeignKey:SSHKeyID"` // SSHKey used to connect by the client
	SSHKeyID uint         `gorm:"index"`
	HostKey  []byte       `sql:"size:1000" valid:"optional"`
	Groups   []*HostGroup `gorm:"many2many:host_host_groups;"`
	Comment  string       `valid:"optional"`
	Logging  string       `valid:"optional,host_logging_mode"`
	Hop      *Host
	HopID    uint
}

func HostByName

func HostByName(db *gorm.DB, name string) (*Host, error)

func (*Host) ClientConfig

func (host *Host) ClientConfig(hk gossh.HostKeyCallback) (*gossh.ClientConfig, error)

func (*Host) DialAddr

func (host *Host) DialAddr() string

func (*Host) Hostname

func (host *Host) Hostname() string

func (*Host) Passwd

func (host *Host) Passwd() string

func (*Host) Port

func (host *Host) Port() uint64

func (*Host) Scheme

func (host *Host) Scheme() BastionScheme

func (*Host) String

func (host *Host) String() string

func (*Host) Username

func (host *Host) Username() string

type HostGroup

type HostGroup struct {
	gorm.Model
	Name    string  `valid:"required,length(1|255),unix_user" gorm:"index:uix_hostgroups_name,unique"`
	Hosts   []*Host `gorm:"many2many:host_host_groups;"`
	ACLs    []*ACL  `gorm:"many2many:host_group_acls;"`
	Comment string  `valid:"optional"`
}

type SSHKey

type SSHKey struct {
	// FIXME: use uuid for ID
	gorm.Model
	Name        string  `valid:"required,length(1|255),unix_user" gorm:"index:uix_keys_name,unique"`
	Type        string  `valid:"required"`
	Length      uint    `valid:"required"`
	Fingerprint string  `valid:"optional"`
	PrivKey     string  `sql:"size:5000" valid:"required"`
	PubKey      string  `sql:"size:1000" valid:"optional"`
	Hosts       []*Host `gorm:"ForeignKey:SSHKeyID"`
	Comment     string  `valid:"optional"`
}

SSHKey defines a ssh client key (used by sshportal to connect to remote hosts)

type Session

type Session struct {
	gorm.Model
	StoppedAt *time.Time `sql:"index" valid:"optional"`
	Status    string     `valid:"required"`
	User      *User      `gorm:"ForeignKey:UserID"`
	Host      *Host      `gorm:"ForeignKey:HostID"`
	UserID    uint       `valid:"optional"`
	HostID    uint       `valid:"optional"`
	ErrMsg    string     `valid:"optional"`
	Comment   string     `valid:"optional"`
}

type SessionStatus

type SessionStatus string
const (
	SessionStatusUnknown SessionStatus = "unknown"
	SessionStatusActive  SessionStatus = "active"
	SessionStatusClosed  SessionStatus = "closed"
)

type Setting

type Setting struct {
	gorm.Model
	Name  string `valid:"required" gorm:"index:uix_settings_name,unique"`
	Value string `valid:"required"`
}

type User

type User struct {
	// FIXME: use uuid for ID
	gorm.Model
	Roles       []*UserRole  `gorm:"many2many:user_user_roles"`
	Email       string       `valid:"required,email"`
	Name        string       `valid:"required,length(1|255),unix_user" gorm:"index:uix_users_name,unique"`
	Keys        []*UserKey   `gorm:"ForeignKey:UserID"`
	Groups      []*UserGroup `gorm:"many2many:user_user_groups;"`
	Comment     string       `valid:"optional"`
	InviteToken string       `valid:"optional,length(10|60)"`
}

func (*User) CheckRoles

func (u *User) CheckRoles(names []string) error

func (*User) HasRole

func (u *User) HasRole(name string) bool

type UserGroup

type UserGroup struct {
	gorm.Model
	Name    string  `valid:"required,length(1|255),unix_user" gorm:"index:uix_usergroups_name,unique"`
	Users   []*User `gorm:"many2many:user_user_groups;"`
	ACLs    []*ACL  `gorm:"many2many:user_group_acls;"`
	Comment string  `valid:"optional"`
}

type UserKey

type UserKey struct {
	gorm.Model
	Key           []byte `sql:"size:1000" valid:"length(1|1000)"`
	AuthorizedKey string `sql:"size:1000" valid:"required,length(1|1000)"`
	UserID        uint   ``
	User          *User  `gorm:"ForeignKey:UserID"`
	Comment       string `valid:"optional"`
}

UserKey defines a user public key used by sshportal to identify the user

type UserRole

type UserRole struct {
	gorm.Model
	Name  string  `valid:"required,length(1|255),unix_user"`
	Users []*User `gorm:"many2many:user_user_roles"`
}

Jump to

Keyboard shortcuts

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