policy

package
v0.20.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	CloudQueryOrg = "cloudquery-policies"
)

Variables

View Source
var ErrPolicyOrQueryNotFound = errors.New("selected policy/query not found")

Functions

func GenerateExecutionResultFile added in v0.16.0

func GenerateExecutionResultFile(result *ExecutionResult, outputDir string) error

Types

type Check added in v0.19.0

type Check struct {
	Name         string    `hcl:"name,label"`
	Title        string    `hcl:"title,optional"`
	Doc          string    `hcl:"doc,optional"`
	ExpectOutput bool      `hcl:"expect_output,optional"`
	Type         QueryType `hcl:"type,optional"`
	Query        string    `hcl:"query"`
}

type Configuration added in v0.16.0

type Configuration struct {
	Providers []*Provider `hcl:"provider,block"`
}

type ExecuteRequest

type ExecuteRequest struct {
	// Policy is the policy that should be executed.
	Policy *Policy

	// StopOnFailure if true policy execution will stop on first failure
	StopOnFailure bool

	// ProviderVersions describes current versions of providers in use.
	ProviderVersions map[string]*version.Version

	// UpdateCallback is the console ui update callback
	UpdateCallback UpdateCallback
}

ExecuteRequest is a request that triggers policy execution.

type ExecutionResult

type ExecutionResult struct {
	// PolicyName is the running policy name
	PolicyName string

	// ExecutionTime is when the policy has been started
	ExecutionTime time.Time

	// True if all policies have passed
	Passed bool

	// List of all query result sets
	Results []*QueryResult

	// Error is the reason the execution failed
	Error string

	// List of loaded Policies
	LoadedPolicies Policies
}

ExecutionResult contains all policy execution results.

type Executor

type Executor struct {
	PolicyPath []string
	// contains filtered or unexported fields
}

Executor implements the execution framework.

func NewExecutor

func NewExecutor(conn execution.QueryExecer, log hclog.Logger, progressUpdate UpdateCallback) *Executor

NewExecutor creates a new executor.

func (*Executor) Execute added in v0.19.0

func (e *Executor) Execute(ctx context.Context, req *ExecuteRequest, policy *Policy) (*ExecutionResult, error)

Execute executes given policy and the related sub queries/views.

type Manager

type Manager interface {
	// Run the given policy.
	Run(ctx context.Context, request *ExecuteRequest) (*ExecutionResult, error)

	// Load the policy
	Load(ctx context.Context, policy *Policy) (*Policy, error)
}

Manager is the interface that describes the interaction with the policy hub. Implemented by ManagerImpl.

type ManagerImpl

type ManagerImpl struct {
	// contains filtered or unexported fields
}

ManagerImpl is the manager implementation struct.

func NewManager

func NewManager(policyDir string, pool execution.QueryExecer, logger hclog.Logger) *ManagerImpl

NewManager returns a new manager instance.

func (*ManagerImpl) Load added in v0.16.0

func (m *ManagerImpl) Load(ctx context.Context, policy *Policy) (*Policy, error)

func (*ManagerImpl) Run added in v0.16.0

func (m *ManagerImpl) Run(ctx context.Context, request *ExecuteRequest) (*ExecutionResult, error)

type Meta added in v0.19.0

type Meta struct {
	Type    string
	Version string

	Directory string
	// contains filtered or unexported fields
}

func LoadSource added in v0.19.0

func LoadSource(ctx context.Context, installDir, source string) ([]byte, *Meta, error)

type Policies added in v0.16.0

type Policies []*Policy

func (Policies) All added in v0.19.0

func (pp Policies) All() []string

type Policy

type Policy struct {
	// Name of the policy
	Name string `hcl:"name,label"`
	// Short human-readable title about the policy
	Title string `hcl:"title,optional"`
	// Full documentation about the policy, this will be shown in the hub
	Doc    string         `hcl:"doc,optional"`
	Config *Configuration `hcl:"configuration,block"`

	Policies Policies `hcl:"policy,block"`
	Checks   []*Check `hcl:"check,block"`
	Views    []*View  `hcl:"view,block"`

	// Link to policy in filesystem/hub/git etc' to use, if source flag is set, all other attributes aren't allowed.
	Source string `hcl:"source,optional"`
	// contains filtered or unexported fields
}

func DecodePolicy added in v0.19.0

func DecodePolicy(body hcl.Body, diags hcl.Diagnostics, basePath string) (*Policy, hcl.Diagnostics)

func DecodePolicyBlock added in v0.19.0

func DecodePolicyBlock(b *hcl.Block, ctx *hcl.EvalContext) (*Policy, hcl.Diagnostics)

func DetectPolicy added in v0.19.0

func DetectPolicy(name string, subPolicy string) (*Policy, bool, error)

func (Policy) Filter added in v0.20.0

func (p Policy) Filter(path string) Policy

func (Policy) HasChecks added in v0.20.1

func (p Policy) HasChecks() bool

func (Policy) String added in v0.19.0

func (p Policy) String() string

func (Policy) SubPolicy added in v0.19.0

func (p Policy) SubPolicy() string

func (Policy) TotalQueries added in v0.19.0

func (p Policy) TotalQueries() int

func (Policy) Version

func (p Policy) Version() string

type Provider added in v0.16.0

type Provider struct {
	Type    string `hcl:"type,label"`
	Version string `hcl:"version,optional"`
}

type QueryResult

type QueryResult struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Columns     []string        `json:"result_headers"`
	Data        [][]interface{} `json:"result_rows"`
	Type        QueryType       `json:"type"`
	Passed      bool            `json:"check_passed"`
}

QueryResult contains the result information from an executed query.

type QueryType added in v0.16.0

type QueryType string
const (
	ManualQuery    QueryType = "manual"
	AutomaticQuery QueryType = "automatic"
)

type Update added in v0.16.0

type Update struct {
	// PolicyID is the name of the policy that is being updated.
	PolicyName string
	// Version is the policy version.
	Version string
	// Source policy was fetched from
	Source string
	// FinishedQueries is the number queries that have finished evaluating
	FinishedQueries int
	// QueriesCount is the amount of queries collected so far
	QueriesCount int
	// Error if any returned by the provider
	Error string
}

func (Update) AllDone added in v0.16.0

func (f Update) AllDone() bool

func (Update) DoneCount added in v0.16.0

func (f Update) DoneCount() int

type UpdateCallback added in v0.16.0

type UpdateCallback func(update Update)

type View added in v0.16.0

type View struct {
	Name  string `hcl:"name,label"`
	Title string `hcl:"title,optional"`
	Query string `hcl:"query"`
}

Jump to

Keyboard shortcuts

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