dataaccess

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDuplicate is the error for a duplicate record.
	ErrDuplicate = errors.New("duplicate record")

	// ErrNotFound is the error for a record not found.
	ErrNotFound = errors.New("record not found")
)
View Source
var DatabaseLatency = promauto.NewHistogramVec(
	prometheus.HistogramOpts{
		Name: "database_latency",
		Help: "Duration of database queries",
	},
	[]string{"query"},
)

DatabaseLatency is the duration of database queries.

View Source
var Files fileHandler
View Source
var StorageLatency = promauto.NewHistogramVec(
	prometheus.HistogramOpts{
		Name: "storage_latency",
		Help: "Duration of fileHandler queries",
	},
	[]string{"query"},
)

StorageLatency is the duration of Files queries.

Functions

func ConnectStorage

func ConnectStorage(ctx context.Context, storeType StoreType, bucketName string) error

Types

type Database added in v0.2.0

type Database interface {
	// Ping pings the database.
	Ping(ctx context.Context) error

	// Close closes the database connection.
	Close(ctx context.Context) error

	// SaveRun saves a PuppetRun to the database.
	SaveRun(ctx context.Context, run *entities.PuppetReport) error

	// GetRuns returns all PuppetRuns from the database.
	GetRuns(ctx context.Context) ([]*entities.PuppetRun, error)

	// GetRunsByState returns all PuppetRuns from the database that are in the given state.
	GetRunsByState(ctx context.Context, states ...summary.State) ([]*entities.PuppetRun, error)

	// GetReports returns all PuppetReports from the database for the given fqdn.
	GetReports(ctx context.Context, fqdn string) ([]*entities.PuppetReportSummary, error)

	// GetReport returns the PuppetReport from the database for the given id.
	GetReport(ctx context.Context, id string) (*entities.PuppetReport, error)

	// GetHistory returns the PuppetHistory from the database for the given environment.
	GetHistory(ctx context.Context, environment ...summary.Environment) ([]*entities.PuppetHistory, error)

	// GetEnvironments returns all environments from the database.
	GetEnvironments(ctx context.Context) ([]summary.Environment, error)

	// Purge purges the data from the database out of the given range.
	Purge(ctx context.Context, from time.Time) (int, error)
}

func ConnectDatabase

func ConnectDatabase(ctx context.Context, dbType string) (Database, error)

func NewMongo added in v0.2.0

func NewMongo(ctx context.Context) (Database, error)

func NewMySQL added in v0.2.0

func NewMySQL() (Database, error)

func NewSQLite added in v0.2.0

func NewSQLite() (Database, error)

type DbOpt

type DbOpt string
const (
	// DbSqlite is the sqlite database.
	DbSqlite DbOpt = "SQLITE"

	// DbMySQL is the MySQL database.
	DbMySQL DbOpt = "MYSQL"

	// DbMongo is the MongoDB database.
	DbMongo DbOpt = "MONGO"
)

func (DbOpt) IsIn

func (d DbOpt) IsIn(opts ...DbOpt) bool

func (DbOpt) String

func (d DbOpt) String() string

func (DbOpt) Valid

func (d DbOpt) Valid() bool

type MockDb

type MockDb struct {
	mock.Mock
}

func (*MockDb) Close

func (m *MockDb) Close(ctx context.Context) error

func (*MockDb) GetEnvironments

func (m *MockDb) GetEnvironments(ctx context.Context) ([]summary.Environment, error)

func (*MockDb) GetHistory

func (m *MockDb) GetHistory(ctx context.Context, environment ...summary.Environment) ([]*entities.PuppetHistory, error)

func (*MockDb) GetReport

func (m *MockDb) GetReport(ctx context.Context, id string) (*entities.PuppetReport, error)

func (*MockDb) GetReports

func (m *MockDb) GetReports(ctx context.Context, fqdn string) ([]*entities.PuppetReportSummary, error)

func (*MockDb) GetRuns

func (m *MockDb) GetRuns(ctx context.Context) ([]*entities.PuppetRun, error)

func (*MockDb) GetRunsByState

func (m *MockDb) GetRunsByState(ctx context.Context, states ...summary.State) ([]*entities.PuppetRun, error)

func (*MockDb) Ping

func (m *MockDb) Ping(ctx context.Context) error

func (*MockDb) Purge

func (m *MockDb) Purge(ctx context.Context, from time.Time) (int, error)

func (*MockDb) SaveRun

func (m *MockDb) SaveRun(ctx context.Context, run *entities.PuppetReport) error

type MockStorage

type MockStorage struct {
	mock.Mock
}

func (*MockStorage) DeleteFile

func (m *MockStorage) DeleteFile(ctx context.Context, filePath string) error

func (*MockStorage) DownloadFile

func (m *MockStorage) DownloadFile(ctx context.Context, filePath string) ([]byte, error)

func (*MockStorage) Purge

func (m *MockStorage) Purge(ctx context.Context, from time.Time) (int, error)

func (*MockStorage) SaveFile

func (m *MockStorage) SaveFile(ctx context.Context, filePath string, file []byte) error

type StoreType

type StoreType string
const (
	// StoreTypeLocal is a local file system store
	StoreTypeLocal StoreType = "LOCAL"

	// StoreTypeS3 is an S3 store
	StoreTypeS3 StoreType = "S3"

	// StoreTypeGCS is a Google Cloud fileHandler store
	StoreTypeGCS StoreType = "GCS"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳