policy

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2022 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

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

Variables

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

Functions

func FilterPolicies added in v0.17.0

func FilterPolicies(args []string, configPolicies []*config.Policy, policyName string) ([]*config.Policy, error)

func GenerateExecutionResultFile added in v0.16.0

func GenerateExecutionResultFile(result *ExecutionResult, outputDir string) error

Types

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 *config.Policy

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

	// SkipVersioning if true policy will be executed without checking out the version of the policy repo using git tags
	SkipVersioning 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

	// 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 *pgxpool.Conn, log hclog.Logger, progressUpdate UpdateCallback) *Executor

NewExecutor creates a new executor.

func (*Executor) ExecutePolicies

func (e *Executor) ExecutePolicies(ctx context.Context, req *ExecuteRequest, policies Policies, selector []string) (*ExecutionResult, error)

type Manager

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

	// Load the policy from local / remote location
	Load(ctx context.Context, p *config.Policy, execReq *ExecuteRequest) (Policies, error)

	// DownloadPolicy downloads the policy into the manager path.
	DownloadPolicy(ctx context.Context, p *RemotePolicy) error
}

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

func NewManager

func NewManager(policyDir string, pool *pgxpool.Pool, logger hclog.Logger) Manager

NewManager returns a new manager instance.

type ManagerImpl

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

ManagerImpl is the manager implementation struct.

func (*ManagerImpl) DownloadPolicy

func (m *ManagerImpl) DownloadPolicy(ctx context.Context, p *RemotePolicy) error

DownloadPolicy downloads the given policy from GitHub and stores it in the local policy directory.

func (*ManagerImpl) Load added in v0.16.0

func (m *ManagerImpl) Load(ctx context.Context, p *config.Policy, execReq *ExecuteRequest) (Policies, error)

func (*ManagerImpl) Run added in v0.16.0

func (m *ManagerImpl) Run(ctx context.Context, execReq *ExecuteRequest, policies Policies) (*ExecutionResult, error)

type Policies added in v0.16.0

type Policies []*Policy

func DecodePolicies added in v0.16.0

func DecodePolicies(body hcl.Body, diags hcl.Diagnostics, basePath string) (Policies, hcl.Diagnostics)

type Policy

type Policy struct {
	Name        string         `hcl:"name,label"`
	Description string         `hcl:"description,optional"`
	Config      *Configuration `hcl:"configuration,block"`

	Source string `hcl:"source,optional"`

	Policies []*Policy `hcl:"policy,block"`
	Queries  []*Query  `hcl:"query,block"`
	Views    []*View   `hcl:"view,block"`
}

type Provider added in v0.16.0

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

type Query added in v0.16.0

type Query struct {
	Name         string    `hcl:"name,label"`
	Description  string    `hcl:"description,optional"`
	ExpectOutput bool      `hcl:"expect_output,optional"`
	Type         QueryType `hcl:"type,optional"`
	Query        string    `hcl:"query"`
}

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 RemotePolicy added in v0.16.0

type RemotePolicy struct {
	// SourceControl is the source control which the policy hosted on. Github / Gitlab
	SourceControl string

	// Organization is the organization / user which own the policy.
	Organization string

	// Repository is the policy repository name.
	Repository string

	// Repository is the policy repository version.
	Version string
}

func ParsePolicyFromArgs added in v0.16.0

func ParsePolicyFromArgs(args []string) (*RemotePolicy, error)

ParsePolicyFromArgs parses policy execution arguments from given args. The first argument is the repository/policy name we want to run, the second argument is the subpath to execute.

func ParsePolicyFromSource added in v0.16.0

func ParsePolicyFromSource(policy *config.Policy) (*RemotePolicy, error)

func (*RemotePolicy) GetURL added in v0.16.0

func (r *RemotePolicy) GetURL() (string, error)

func (*RemotePolicy) ToPolicyConfig added in v0.16.0

func (r *RemotePolicy) ToPolicyConfig() (*config.Policy, error)

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
	// 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"`
	Description string `hcl:"description,optional"`

	Query *Query `hcl:"query,block"`
}

Jump to

Keyboard shortcuts

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