Documentation
¶
Index ¶
- Constants
- Variables
- func FilterPolicies(args []string, configPolicies []*config.Policy, policyName string) ([]*config.Policy, error)
- func GenerateExecutionResultFile(result *ExecutionResult, outputDir string) error
- type Configuration
- type ExecuteRequest
- type ExecutionResult
- type Executor
- type Manager
- type ManagerImpl
- func (m *ManagerImpl) DownloadPolicy(ctx context.Context, p *RemotePolicy) error
- func (m *ManagerImpl) Load(ctx context.Context, p *config.Policy, execReq *ExecuteRequest) (Policies, error)
- func (m *ManagerImpl) Run(ctx context.Context, execReq *ExecuteRequest, policies Policies) (*ExecutionResult, error)
- type Policies
- type Policy
- type Provider
- type Query
- type QueryResult
- type QueryType
- type RemotePolicy
- type Update
- type UpdateCallback
- type View
Constants ¶
const (
CloudQueryOrg = "cloudquery-policies"
)
Variables ¶
var ErrPolicyOrQueryNotFound = errors.New("selected policy/query is not found")
Functions ¶
func FilterPolicies ¶ added in v0.17.0
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.
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 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 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
}
type UpdateCallback ¶ added in v0.16.0
type UpdateCallback func(update Update)