policy

package
v0.14.4 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecuteRequest

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

	// UpdateCallback gets called when the client receives updates on policy execution (optional).
	UpdateCallback ExecutionCallback

	// 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
}

ExecuteRequest is a request that triggers policy execution.

type ExecutionCallback

type ExecutionCallback func(name string, passed bool)

ExecutionCallback represents the format of the policy callback function.

type ExecutionResult

type ExecutionResult struct {
	// True if all policies have passed
	Passed bool

	// Map of all query result sets
	Results map[string]*QueryResult
}

ExecutionResult contains all policy execution results.

type Executor

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

Executor implements the execution framework.

func NewExecutor

func NewExecutor(conn *pgxpool.Conn, log hclog.Logger) *Executor

NewExecutor creates a new executor.

func (*Executor) CreateView

func (e *Executor) CreateView(ctx context.Context, v *config.View) error

CreateView creates the given view temporary.

func (*Executor) CreateViews added in v0.14.4

func (e *Executor) CreateViews(ctx context.Context, policy *config.Policy) error

CreateViews creates temporary views for given config.Policy, and any views defined by sub-policies

func (*Executor) ExecutePolicy added in v0.14.4

func (e *Executor) ExecutePolicy(ctx context.Context, execReq *ExecuteRequest, policy *config.Policy) (*ExecutionResult, error)

ExecutePolicy executes given policy and the related sub queries/views. The policy execution first creates all views that are defined in the top-level policy and any sub-policy it includes.

func (*Executor) ExecuteQuery

func (e *Executor) ExecuteQuery(ctx context.Context, q *config.Query) (*QueryResult, error)

ExecuteQuery executes the given query and returns the result.

type Manager

type Manager interface {
	// ParsePolicyHubPath parses a given policy hub path and returns a Policy object.
	ParsePolicyHubPath(args []string, subPolicyPath string) (*Policy, error)

	// DownloadPolicy downloads the given policy.
	DownloadPolicy(ctx context.Context, p *Policy) error

	// RunPolicy runs the given policy.
	RunPolicy(ctx context.Context, execRequest *ExecuteRequest) (*ExecutionResult, 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 *Policy) error

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

func (*ManagerImpl) ParsePolicyHubPath

func (m *ManagerImpl) ParsePolicyHubPath(args []string, subPolicyPath string) (*Policy, error)

ParsePolicyHubPath parses and validates the given arguments into the Policy struct. Given args should follow the following semantic structure: [(organization/)repository-name(@tag)] ([repository-path])

func (*ManagerImpl) RunPolicy

func (m *ManagerImpl) RunPolicy(ctx context.Context, execReq *ExecuteRequest) (*ExecutionResult, error)

RunPolicy runs the given policy.

type Policy

type Policy struct {
	// Organization is the policy org.
	Organization string

	// Repository is the policy repository.
	Repository string

	// RepositoryPath is the policy repository internal path.
	RepositoryPath string

	// Version is the git repository tag that should be used.
	Version string

	// SubPath is the policy sub-path.
	SubPath string
}

Policy represents a single policy.

type QueryResult

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

QueryResult contains the result information from an executed query.

Jump to

Keyboard shortcuts

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