models

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package models contains the database models.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(next http.Handler) http.Handler

AuthMiddleware Verify if user is logged

func AuthSecretAgentMiddleware

func AuthSecretAgentMiddleware(next http.Handler) http.Handler

AuthSecretAgentMiddleware auth secret agent middleware

func CheckIfAllowTo

func CheckIfAllowTo(user *User, allowTo string) error

CheckIfAllowTo check if user has permission to execute

func CleanupMetrics added in v1.0.3

func CleanupMetrics(interval time.Duration) error

CleanupMetrics Cleanup metrics

func CreateAgent

func CreateAgent(secret, name, description string, tags map[string]string) error

CreateAgent create a new agent

func CreateAgentTagByAgentID

func CreateAgentTagByAgentID(agentID uuid.UUID, key string, value string) error

CreateAgentTagByAgentID create a new agent tag

func CreateUserToken

func CreateUserToken(user *User) (string, error)

CreateUserToken Generate a new login token

func DeleteAgentTags

func DeleteAgentTags(agentID uuid.UUID) error

DeleteAgentTags delete agent tags

func DeleteAllSampleResults added in v1.2.0

func DeleteAllSampleResults(sampleID string) error

DeleteAllSampleResults by sample id

func DeleteExpiredMetrics

func DeleteExpiredMetrics() error

DeleteExpiredMetrics Delete all expired metrics

func DeleteMetricBySampleID added in v1.2.0

func DeleteMetricBySampleID(sampleID string) error

DeleteMetricBySampleID Delete metric by sample id

func DeleteOldMetrics

func DeleteOldMetrics(interval time.Duration) error

DeleteOldMetrics Delete old metrics

func DeleteOldMetricsLabels added in v1.0.3

func DeleteOldMetricsLabels(interval time.Duration) error

DeleteOldMetricsLabels Delete old metrics labels

func DeleteOldSampleResults added in v1.0.3

func DeleteOldSampleResults(interval time.Duration) error

DeleteOldSampleResults Delete old scenario results

func DeleteSample added in v1.2.0

func DeleteSample(sampleID string) error

DeleteSample delete sample by id

func GetAgentQuery

func GetAgentQuery() *gorm.DB

GetAgentQuery get agent query

func GetDistinctChecksumByName

func GetDistinctChecksumByName(name string) ([]string, error)

GetDistinctChecksumByName Get distinct checksum by name

func GetDistinctChecksumByNameAndSampleID

func GetDistinctChecksumByNameAndSampleID(name, sampleID string) ([]string, error)

GetDistinctChecksumByNameAndSampleID Get distinct metrics by name and sample id

func GetDistinctMetricName

func GetDistinctMetricName() ([]string, error)

GetDistinctMetricName Get distinct metric name

func GetDistinctMetricNameBySampleID

func GetDistinctMetricNameBySampleID(sampleID string) ([]string, error)

GetDistinctMetricNameBySampleID return distinct metric name by sample id

func GetTotalSamples

func GetTotalSamples() int64

GetTotalSamples return total samples

func GetUserCount

func GetUserCount() int64

GetUserCount Get count of users

func ProcessMetricsQueue

func ProcessMetricsQueue()

ProcessMetricsQueue process metrics queue

func SetupDB

func SetupDB(dbType, dbPath, dbURI string)

SetupDB creates the database tables.

func UpdateAgent

func UpdateAgent(agentID uuid.UUID, name, description string) error

UpdateAgent update agent

func VerifyUserToken

func VerifyUserToken(tokenString string) (jwt.Claims, error)

VerifyUserToken Verify if token is correct

Types

type Agent

type Agent struct {
	gorm.Model
	Name        string
	Description string
	ID          uuid.UUID `gorm:"primaryKey;type:char(36);"`
	Secret      string    `json:"-" gorm:"primaryKey;type:char(36);"`
}

Agent model

func GetAgent

func GetAgent(agentID uuid.UUID) (*Agent, error)

GetAgent get agent by agent id

func GetAgents

func GetAgents() ([]Agent, error)

GetAgents get all agents

func SearchAgentByName

func SearchAgentByName(name string) ([]Agent, error)

SearchAgentByName search agent by name

type AgentTag

type AgentTag struct {
	gorm.Model
	ID      uuid.UUID `gorm:"primaryKey;type:char(36);"`
	AgentID uuid.UUID
	Agent   Agent `gorm:"foreignKey:AgentID" json:"-"`
	Key     string
	Value   string
}

AgentTag model

func GetAgentTags

func GetAgentTags(agentID uuid.UUID) ([]AgentTag, error)

GetAgentTags get agent tags

type IScenario

type IScenario interface {
	StartPrimitives()
	Init()
	RunStep(string, map[string]string) ([]Metric, error)
	RegisterStep(string, StepDefinition)
	Description() string
	GetScenarioDefinitions() map[string]StepDefinition
}

IScenario Define scenario interface

type Metric

type Metric struct {
	gorm.Model
	ID             uuid.UUID `gorm:"primaryKey;type:char(36);"`
	Name           string
	Value          float64
	Labels         map[string]string `gorm:"-"`
	Description    string
	SampleID       string
	Expires        time.Duration
	SampleResultID uuid.UUID     `json:"-"`
	SampleResult   *SampleResult `gorm:"foreignKey:SampleResultID" json:"-"`
}

Metric definition

func GetMetricByChecksum

func GetMetricByChecksum(checksum, name string) (*Metric, error)

GetMetricByChecksum Get one metric by checksum

func GetMetricByName

func GetMetricByName(name string) (*Metric, error)

GetMetricByName Get one metric by name

func GetMetricsByNameAndSampleID

func GetMetricsByNameAndSampleID(name, sampleID, checksum string, limit int) ([]Metric, error)

GetMetricsByNameAndSampleID Get metrics by name and sample id

func GetMetricsBySampleID

func GetMetricsBySampleID(sampleID string) ([]Metric, error)

GetMetricsBySampleID return metrics by sample id

func GetMetricsBySampleResultID

func GetMetricsBySampleResultID(sampleResultID string) ([]Metric, error)

GetMetricsBySampleResultID return metrics by sample result id

func (*Metric) PushToDB

func (m *Metric) PushToDB(labels map[string]string) error

PushToDB Push new metric to db

type MetricLabel

type MetricLabel struct {
	gorm.Model
	Key      string
	Value    string
	Metric   Metric `gorm:"foreignKey:MetricID" json:"-"`
	MetricID string
}

MetricLabel definition

func GetMetricLabelByMetricID

func GetMetricLabelByMetricID(id uuid.UUID) ([]MetricLabel, error)

GetMetricLabelByMetricID Get metric label by metric id

type MetricQueue

type MetricQueue struct {
	AgentID        string
	Sample         Sample
	ScenarioResult ScenarioResult
}

MetricQueue represent a metric queue

type Permission

type Permission struct {
	gorm.Model
	ID      uuid.UUID `gorm:"primaryKey;type:char(36);"`
	UserID  uuid.UUID `json:"user"`
	User    User      `gorm:"foreignKey:UserID" json:"-"`
	AllowTo string
}

Permission represents a permission

func AddPermission2User

func AddPermission2User(user *User, allowTo string) (*Permission, error)

AddPermission2User add permission to user

func GetPermissionByUserAllowTo

func GetPermissionByUserAllowTo(user *User, allowTo string) (*Permission, error)

GetPermissionByUserAllowTo get permission by user and allowTo

type Sample

type Sample struct {
	gorm.Model  `json:"-"`
	ID          uuid.UUID `gorm:"primaryKey;type:char(36);"`
	Name        string    `json:"-"`
	OwnerID     uuid.UUID `json:"-"`
	Owner       User      `gorm:"foreignKey:OwnerID" json:"-"`
	SampleData  []byte    `json:"-"`
	Checksum    string
	Description string `json:"-"`
	Kind        string `json:"-"`
}

Sample represent a sample

func GetSampleByID

func GetSampleByID(id string) (*Sample, error)

GetSampleByID return sample by id

func GetSamples

func GetSamples() ([]Sample, error)

GetSamples return samples

func GetSamplesWithPagination

func GetSamplesWithPagination(page, limit int) ([]Sample, error)

GetSamplesWithPagination return samples with pagination

func RegisterSample

func RegisterSample(name, descrption, kind string, sampleData []byte, user *User) (*Sample, error)

RegisterSample register sample

func SearchSamples

func SearchSamples(name string) ([]Sample, error)

SearchSamples search samples

func SearchSamplesWithPagination

func SearchSamplesWithPagination(name string, page, limit int) ([]Sample, error)

SearchSamplesWithPagination search samples with pagination

func UpdateSample

func UpdateSample(id, name, descrption, kind string, sampleData []byte, user *User) (*Sample, error)

UpdateSample update sample

func (*Sample) PushMetrics

func (s *Sample) PushMetrics(ScenarioResult *ScenarioResult, agentID string) error

PushMetrics push metrics to database

func (*Sample) PushMetricsToQueue

func (s *Sample) PushMetricsToQueue(ScenarioResult *ScenarioResult, agentID string)

PushMetricsToQueue push metrics to queue

type SampleResult

type SampleResult struct {
	gorm.Model `json:"-"`
	ID         uuid.UUID `gorm:"primaryKey;type:char(36);"`
	SampleID   uuid.UUID `json:"-"`
	Sample     Sample    `gorm:"foreignKey:SampleID" json:"-"`
	StartDate  time.Time
	EndDate    time.Time
	Error      string
	Agent      Agent `gorm:"foreignKey:AgentID"`
	AgentID    uuid.UUID
}

SampleResult represent a sample result

func GetLastSampleResultBySampleID

func GetLastSampleResultBySampleID(sampleID string) (*SampleResult, error)

GetLastSampleResultBySampleID return last sample result by sample id

func GetSampleResultBySampleIDWithLimit

func GetSampleResultBySampleIDWithLimit(sampleID string, limit int) ([]*SampleResult, error)

GetSampleResultBySampleIDWithLimit return latest sample result by sample id

func GetSampleResults

func GetSampleResults(sampleID string, limit int) ([]SampleResult, error)

GetSampleResults return sample results by sample id

type Scenario

type Scenario struct {
	Kind             string
	Steps            []Step
	StepsDefinitions map[string]StepDefinition
}

Scenario definition

func (*Scenario) Description

func (s *Scenario) Description() string

Description Get scenario description

func (*Scenario) GetScenarioDefinitions

func (s *Scenario) GetScenarioDefinitions() map[string]StepDefinition

GetScenarioDefinitions Get scenario definitions

func (*Scenario) RegisterStep

func (s *Scenario) RegisterStep(name string, step StepDefinition)

RegisterStep Register step default method

func (*Scenario) RunStep

func (s *Scenario) RunStep(name string, p map[string]string) ([]Metric, error)

RunStep Run an step

func (*Scenario) StartPrimitives

func (s *Scenario) StartPrimitives()

StartPrimitives Initialize primitive variables

type ScenarioResult

type ScenarioResult struct {
	Scenario    Scenario
	StartDate   time.Time
	EndDate     time.Time
	StepResults []*StepResult
	Error       error `json:"-"`
	ErrorString string
}

ScenarioResult is the result of a scenario

type Scenarios

type Scenarios struct {
	Name        string
	Description string

	Scenario       Scenario
	ScrapeInterval time.Duration `yaml:"scrapeInterval"`
}

Scenarios represent sample scenarios

func ReadScenariosYAML

func ReadScenariosYAML(data []byte) (*Scenarios, error)

ReadScenariosYAML Read scenarios pointer from yaml

type Step

type Step struct {
	Type   string
	Params map[string]string
	Negate bool
}

Step definition

type StepDefinition

type StepDefinition struct {
	Name        string
	Description string
	Params      []StepParam
	Fn          stepFn `json:"-"`
}

StepDefinition definition

type StepParam

type StepParam struct {
	Name        string
	Description string
	Optional    bool
}

StepParam returns the value of a step parameter

type StepResult

type StepResult struct {
	Step      Step
	StartDate time.Time
	EndDate   time.Time
	Metrics   []Metric
}

StepResult is the result of a step

type User

type User struct {
	gorm.Model
	ID             uuid.UUID `gorm:"primaryKey;type:char(36);"`
	Email          string    `gorm:"unique;primaryKey"`
	Password       []byte    `json:"-"`
	TwoFactorToken string    `json:"-" gorm:"type:char(32)"`
}

User Represent user

func CreateUser

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

CreateUser Create a new username

func GetLoggedUser

func GetLoggedUser(r *http.Request) *User

GetLoggedUser Return user by http header

func GetUserByEmail

func GetUserByEmail(email string) *User

GetUserByEmail Get one user given an email

func GetUserByID

func GetUserByID(id string) *User

GetUserByID Get user by id

func (*User) Update2FAToken added in v1.0.5

func (user *User) Update2FAToken(token string) error

Update2FAToken Update 2FA token

func (*User) UpdatePassword added in v1.0.5

func (user *User) UpdatePassword(password string) error

UpdatePassword Update user password

Jump to

Keyboard shortcuts

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