pgdb

package
v0.0.0-...-4da4744 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: Apache-2.0 Imports: 29 Imported by: 10

Documentation

Index

Constants

View Source
const (
	DayLatestFlag                = "day_latest"
	ControlIndexFlag             = "control_index"
	CompRunInfoFlag              = "comp_run_info"
	EnhancedReportingEnabledFlag = "enhanced_reporting"
)

constants represents the flags

View Source
const (
	PolicyNameUnreachable = "unreachable_assets"
)

Variables

This section is empty.

Functions

func FindKeyValue

func FindKeyValue(tags []*common.Kv, key string) *common.Kv

FindKeyValue finds a Tag object in the array based on key match

func RemoveKeyValue

func RemoveKeyValue(tags []*common.Kv, key string) []*common.Kv

RemoveKeyValue removes an item from the array base on key match

func Transact

func Transact(db *DB, txFunc func(*DBTrans) error) error

Transact wraps your calls in a transaction. If the call should fail with an error it will perform a rollback. Otherwise the transaction will be committed.

Types

type DB

type DB struct {
	*gorp.DbMap
}

func InitDB

func InitDB(connectionString string) (*DB, error)

func New

func New(conf *config.Postgres) (*DB, error)

func (*DB) AddJob

func (db *DB) AddJob(inJob *jobs.Job) (string, error)

func (*DB) DeleteJob

func (db *DB) DeleteJob(id string) error

func (*DB) GetConfigs

func (db *DB) GetConfigs(ctx context.Context) (*reporting.ComplianceConfigResponse, error)

func (*DB) GetJob

func (db *DB) GetJob(id string) (*jobs.Job, error)

func (*DB) GetJobName

func (db *DB) GetJobName(id string) (string, error)

func (*DB) GetJobResultByNodeId

func (db *DB) GetJobResultByNodeId(ctx context.Context, in *jobs.GetJobResultByNodeIdRequest) (*jobs.ResultsRow, error)

given a job id and node id, get the result from the results table

func (*DB) GetJobs

func (db *DB) GetJobs(sortField string, insortOrder jobs.Query_OrderType, pageNr int32, perPage int32, filters []*common.Filter) ([]*jobs.Job, int64, error)

func (*DB) GetTelemetry

func (db *DB) GetTelemetry(ctx context.Context) (Telemetry, error)

Get last compliance telemetry reported timestamp

func (*DB) ListInitiatedScans

func (db *DB) ListInitiatedScans(ctx context.Context, startTime *tspb.Timestamp) ([]jobWithTime, error)

func (*DB) SetConfigs

func (db *DB) SetConfigs(ctx context.Context, in *reporting.ComplianceConfigRequest) error

func (*DB) UpdateJob

func (db *DB) UpdateJob(inJob *jobs.Job) error

func (*DB) UpdateLastTelemetryReported

func (db *DB) UpdateLastTelemetryReported(ctx context.Context, req *stats.UpdateTelemetryReportedRequest) error

UpdateLastTelemetryReported: Upsert the last compliance telemetry reported date in postgres

type DBTrans

type DBTrans struct {
	*gorp.Transaction
}

func (*DBTrans) DeleteTelemetry

func (trans *DBTrans) DeleteTelemetry(ctx context.Context, id string) error

Delete last compliance telemetry reported timestamp

func (*DBTrans) GetTelemetry

func (trans *DBTrans) GetTelemetry(ctx context.Context) (Telemetry, error)

Get last compliance telemetry reported timestamp

func (*DBTrans) StoreTelemetry

func (trans *DBTrans) StoreTelemetry(ctx context.Context, lastTelemetryReportedAt time.Time) error

store last compliance telemetry reported timestamp

func (*DBTrans) UpdateTelemetry

func (trans *DBTrans) UpdateTelemetry(ctx context.Context, lastTelemetryReportedAt time.Time) error

Update last compliance telemetry reported timestamp

type Flag

type Flag struct {
	FlagName     string    `db:"upgrade_flag"`
	Status       bool      `db:"upgrade_value"`
	UpgradedTime time.Time `db:"upgrade_time"`
}

type JobNode

type JobNode struct {
	JobID  string `db:"job_id"`
	NodeID string `db:"node_id"`
}

JobNode used only to (de)serialize database access

type JobProfile

type JobProfile struct {
	JobID     string `db:"job_id"`
	ProfileID string `db:"profile_id"`
}

type JobTag

type JobTag struct {
	JobID string `db:"job_id"`
	TagID string `db:"tag_id"`
}

JobTag used only to (de)serialize database access

type ResultsRow

type ResultsRow struct {
	JobID     string    `db:"job_id" json:"job_id,omitempty"`
	NodeID    string    `db:"node_id" json:"node_id"`
	ReportID  string    `db:"report_id" json:"report_id"`
	Status    string    `db:"status" json:"status"`
	Result    string    `db:"result" json:"result"`
	StartTime time.Time `db:"start_time" json:"start_time"`
	EndTime   time.Time `db:"end_time" json:"end_time"`
}

type Storage

type Storage interface {
	GetUpgradeFlags() (map[string]Flag, error)
	UpdateControlFlagValue(bool) error
	UpdateControlFlagTimeStamp() error
	AddEnhancedReportingFlag() error
	RemoveEnhancedReportingFlag() error
}

type Telemetry

type Telemetry struct {
	ID                      string    `db:"id" json:"id"`
	LastTelemetryReportedAt time.Time `db:"last_telemetry_reported_at" json:"last_telemetry_reported_at"`
	CreatedAt               time.Time `db:"created_at" json:"created_at"`
}

type UpgradesDB

type UpgradesDB struct {
	DB *DB
}

func NewDB

func NewDB(db *DB) *UpgradesDB

func (*UpgradesDB) AddEnhancedReportingFlag

func (u *UpgradesDB) AddEnhancedReportingFlag() error

AddEnhancedReportingFlag adds the enhanced_reporting flag to flags table

func (*UpgradesDB) GetUpgradeFlags

func (u *UpgradesDB) GetUpgradeFlags() (map[string]Flag, error)

GetUpgradeFlags Gets the all the upgrade flags and status from the pg database

func (*UpgradesDB) RemoveEnhancedReportingFlag

func (u *UpgradesDB) RemoveEnhancedReportingFlag() error

RemoveEnhancedReportingFlag delete the enhanced_reporting from flags table

func (*UpgradesDB) UpdateControlFlagTimeStamp

func (u *UpgradesDB) UpdateControlFlagTimeStamp() error

UpdateControlFlagTimeStamp updates the upgrade_time for the control index flag

func (*UpgradesDB) UpdateControlFlagValue

func (u *UpgradesDB) UpdateControlFlagValue(value bool) error

UpdateControlFlagValue updates the upgrade_value for control index flag

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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