datastore

package
v0.0.0-...-bfb5a2a Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoMigrate

func AutoMigrate(db *gorm.DB) (err error)

func KnownFiles

func KnownFiles() *knownFileRepository

func Machines

func Machines() *machineRepository

func MustAutoMigrate

func MustAutoMigrate(db *gorm.DB)

func MustOpen

func MustOpen(dbUrl string) *gorm.DB

func Open

func Open(dbUrl string) (*gorm.DB, error)

func Packages

func Packages() *packageRepository

func ReportRuns

func ReportRuns() *reportRunRepository

func ScannedFiles

func ScannedFiles() *scannedFileRepository

Types

type Datastore

type Datastore interface {
	Machines() *machineRepository
	Packages() *packageRepository
	KnownFiles() *knownFileRepository
	ScannedFiles() *scannedFileRepository
	ReportRuns() *reportRunRepository
}

type DbOp

type DbOp func(*gorm.DB) error

type FileStatus

type FileStatus byte
const (
	FileStatusUnknown   FileStatus = 0
	FileStatusSafe      FileStatus = 1
	FileStatusCommon    FileStatus = 100
	FileStatusMalicious FileStatus = 255
)

func (FileStatus) String

func (f FileStatus) String() string

type JSONField

type JSONField[T any] struct {
	Val T
}

func (JSONField[T]) GormDBDataType

func (JSONField[T]) GormDBDataType(db *gorm.DB, field *schema.Field) string

func (JSONField[T]) MarshalJSON

func (j JSONField[T]) MarshalJSON() ([]byte, error)

func (*JSONField[T]) Scan

func (j *JSONField[T]) Scan(src interface{}) error

func (*JSONField[T]) UnmarshalJSON

func (j *JSONField[T]) UnmarshalJSON(data []byte) error

func (JSONField[T]) Value

func (j JSONField[T]) Value() (driver.Value, error)

type KnownFile

type KnownFile struct {
	ID uint `gorm:"primarykey"`

	// Path, Hashes, Indexed
	Path *string `gorm:"varchar(1024)"`

	SHA1   *string `gorm:"type:char(40);index"`
	SHA256 *string `gorm:"type:char(64);index"`
	MD5    *string `gorm:"type:char(32);index"`

	// File info
	Size     *int64  `gorm:"default:null"`
	MimeType *string `gorm:"default:null"`

	// Wether was scraped or voted for
	PackageID *uint
	Package   Package `gorm:"foreignKey:PackageID"`

	// File Status
	Status FileStatus `gorm:"notnull;default:0"`
}

func (*KnownFile) BeforeCreate

func (f *KnownFile) BeforeCreate(tx *gorm.DB) (err error)

type Machine

type Machine struct {
	ID        uint   `gorm:"primarykey"`
	Hostname  string `gorm:"type:varchar(255);uniqueIndex:;notnull"`
	MachineId string `gorm:"type:varchar(255);uniqueIndex:;notnull"`
}

Machine represents information about a machine on the network. It also contains info whether the machine is allowed to submit files.

type OsType

type OsType string
const (
	OsTypeDebian    OsType = "debian"
	OsTypeRedhat    OsType = "redhat"
	OsTypeUbuntu    OsType = "ubuntu"
	OsTypeAlmaLinux OsType = "almalinux"
)

type Package

type Package struct {
	ID uint `gorm:"primarykey"`

	Name     string `gorm:"uniqueIndex:uniqpkg"`
	Filename string
	MD5Sum   *string `gorm:"default:null"`
	SHA256   *string `gorm:"default:null"`
	Version  string  `gorm:"uniqueIndex:uniqpkg"`
	Size     uint64

	Architecture string `gorm:"uniqueIndex:uniqpkg"`
	Distro       string `gorm:"uniqueIndex:uniqpkg"`
	Component    string `gorm:"uniqueIndex:uniqpkg"`
	OsType       OsType `gorm:"uniqueIndex:uniqpkg"`

	CreatedAt time.Time
	UpdatedAt time.Time
	ScrapedAt time.Time `gorm:"default:null"`
}

type ReportRun

type ReportRun struct {
	ID        uuid.UUID `gorm:"type:char(36);primarykey;default:uuid()"`
	CreatedAt time.Time
	IP        string
	MachineID uint
	Machine   Machine       `gorm:"foreignKey:MachineID"`
	Files     []ScannedFile `gorm:"foreignKey:ReportRunID"`
}

ReportRun represents information about a machine on the network. It also contains info whether the machine is allowed to submit files.

type ScannedFile

type ScannedFile struct {
	ID        uint `gorm:"primarykey"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`

	// Path
	Path string `gorm:"type:varchar(1024);notnull"`

	// Hashes
	SHA1   *string `gorm:"type:char(40);check:at_least_one,(sha1 IS NOT NULL) OR (sha256 IS NOT NULL) OR (md5 IS NOT NULL)"`
	SHA256 *string `gorm:"type:char(64)"`
	MD5    *string `gorm:"type:char(32)"`

	// File info
	Size     int64  `gorm:"notnull;default:-1"`
	Mode     uint32 `gorm:"notnull;default:4294967295"`
	MimeType string `gorm:"type:varchar(255);notnull"`

	// File times
	Mtime *int64 `gorm:"type:long"`
	Atime *int64 `gorm:"type:long"`
	Ctime *int64 `gorm:"type:long"`

	// Users
	Owner *uint32
	Group *uint32

	// Run info
	ReportRunID uuid.UUID
	ReportRun   ReportRun `gorm:"foreignKey:ReportRunID"`

	// Submitting Machine info
	MachineID uint
	Machine   Machine `gorm:"foreignKey:MachineID"`
}

Jump to

Keyboard shortcuts

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