state

package
v0.32.3 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package state interacts with core database schema and stores cloudquery metadata such as fetch summaries

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckResult added in v0.24.1

type CheckResult struct {
	ExecutionId        uuid.UUID `db:"execution_id"`
	ExecutionTimestamp time.Time `db:"execution_timestamp"`
	Name               string    `db:"name"`
	Selector           string    `db:"selector"`
	Description        string    `db:"description"`
	Status             string    `db:"status"`
	RawResults         string    `db:"raw_results"`
	Error              string    `db:"error"`
}

CheckResult represents the output of a single check run

type Client

type Client struct {
	Logger hclog.Logger
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, clientDns string) (*Client, error)

NewClient creates a client from the given DSN and migrates the metadata schema. client.Close should be called to disconnect afterwards.

func (*Client) Close added in v0.24.0

func (c *Client) Close()

Close closes the underlying database connection.

func (*Client) CreateCheckResult added in v0.24.1

func (c *Client) CreateCheckResult(ctx context.Context, cr *CheckResult) error

CreateCheckResult inserts a check result in the database

func (*Client) CreatePolicyExecution added in v0.24.1

func (c *Client) CreatePolicyExecution(ctx context.Context, pe *PolicyExecution) (*PolicyExecution, error)

CreatePolicyExecution inserts a policy execution in the database

func (*Client) GetFetchSummaryForProvider

func (c *Client) GetFetchSummaryForProvider(ctx context.Context, provider string) (*FetchSummary, error)

GetFetchSummaryForProvider gets latest fetch summary for specific provider

func (*Client) GetProvider added in v0.24.0

func (c *Client) GetProvider(ctx context.Context, p registry.Provider) (*Provider, error)

GetProvider gets state about given provider, or returns nil, nil.

func (*Client) ProviderSync added in v0.24.0

func (c *Client) ProviderSync(ctx context.Context) (*Tx, error)

func (*Client) PrunePolicyExecutions added in v0.24.1

func (c *Client) PrunePolicyExecutions(ctx context.Context, pruneBefore time.Time) error

PrunePolicyExecutions deletes old policy executions in the database

func (*Client) SaveFetchSummary

func (c *Client) SaveFetchSummary(ctx context.Context, fs *FetchSummary) error

SaveFetchSummary saves fetch summary into fetches database

type FetchSummary

type FetchSummary struct {
	CqId uuid.UUID `db:"id"`
	//  Unique Id of fetch session
	FetchId            uuid.UUID              `db:"fetch_id"`
	CreatedAt          time.Time              `db:"created_at"`
	Start              time.Time              `db:"start"`
	Finish             time.Time              `db:"finish"`
	IsSuccess          bool                   `db:"is_success"`
	TotalResourceCount uint64                 `db:"total_resource_count"`
	TotalErrorsCount   uint64                 `db:"total_errors_count"`
	ProviderName       string                 `db:"provider_name"`
	ProviderAlias      string                 `db:"provider_alias"`
	ProviderVersion    string                 `db:"provider_version"`
	CoreVersion        string                 `db:"core_version"`
	Resources          ResourceFetchSummaries `db:"results"`
}

FetchSummary includes a summarized report of fetch, such as fetch id, fetch start and finish, resources fetch results

type PolicyExecution added in v0.24.1

type PolicyExecution struct {
	Id           uuid.UUID `db:"id"`
	Timestamp    time.Time `db:"timestamp"`
	Scheme       string    `db:"scheme"`
	Location     string    `db:"location"`
	PolicyName   string    `db:"policy_name"`
	Selector     string    `db:"selector"`
	Sha256Hash   string    `db:"sha256_hash"`
	Version      string    `db:"version"`
	ChecksTotal  int       `db:"checks_total"`
	ChecksFailed int       `db:"checks_failed"`
	ChecksPassed int       `db:"checks_passed"`
}

PolicyExecution represents a single policy execution and their summary

type Provider added in v0.24.0

type Provider struct {
	Source  string `db:"source"`
	Name    string `db:"name"`
	Version string `db:"version"`

	VMajor int    `db:"v_major"`
	VMinor int    `db:"v_minor"`
	VPatch int    `db:"v_patch"`
	VPre   string `db:"v_pre"`
	VMeta  string `db:"v_meta"`

	Tables     tableList `db:"tables"`
	Signatures stringMap `db:"signatures"`

	ParsedVersion *version.Version `db:"-"`
}

Provider keeps track of installed providers

func ProviderFromRegistry added in v0.24.0

func ProviderFromRegistry(r registry.Provider) *Provider

ProviderFromRegistry returns a Provider struct with info filled from a registry.Provider

func (*Provider) Registry added in v0.24.0

func (p *Provider) Registry() registry.Provider

type ResourceFetchSummaries

type ResourceFetchSummaries []ResourceFetchSummary

func (ResourceFetchSummaries) Value

Value implements Valuer interface required by goqu

type ResourceFetchSummary

type ResourceFetchSummary struct {
	ResourceName string `json:"resource_name"`
	// map of resources that have finished fetching
	FinishedResources map[string]bool `json:"finished_resources"`
	// Error value if any, if returned the stream will be canceled
	Error string `json:"error"`
	// Execution status of resource
	Status string `json:"status"`
	// Total Amount of resources collected by this resource
	ResourceCount uint64 `json:"resource_count"`
}

ResourceFetchSummary includes a data about fetching specific resource

type Tx added in v0.24.0

type Tx struct {
	execution.TXQueryExecer
	// contains filtered or unexported fields
}

func (*Tx) InstallProvider added in v0.24.0

func (t *Tx) InstallProvider(ctx context.Context, p *Provider) error

InstallProvider saves state about given provider

func (*Tx) UninstallProvider added in v0.24.0

func (t *Tx) UninstallProvider(ctx context.Context, p registry.Provider) error

UninstallProvider removes state about given provider

Jump to

Keyboard shortcuts

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