client

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: MPL-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMigrationsNotSupported = errors.New("provider doesn't support migrations")
)
View Source
var (
	// Version variable is injected in build time
	Version = "development"
)

Functions

func FilterPolicies added in v0.16.0

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

Types

type Client

type Client struct {
	// Required: List of providers that are required, these providers will be downloaded if DownloadProviders is called.
	Providers []*config.RequiredProvider
	// Optional: Registry url to verify plugins from, defaults to CloudQuery hub
	RegistryURL string
	// Optional: Where to save downloaded providers, by default current working directory, defaults to ./cq/providers
	PluginDirectory string
	// Optional: Where to save downloaded policies, by default current working directory, defaults to ./cq/policy
	PolicyDirectory string
	// Optional: If true cloudquery just runs policy files without using git tag to select a version
	SkipVersioning bool
	// Optional: if this flag is true, plugins downloaded from URL won't be verified when downloaded
	NoVerify bool
	// Optional: DSN connection information for database client will connect to
	DSN string
	// Optional: Skips Building tables on fetch execution
	SkipBuildTables bool
	// Optional: HubProgressUpdater allows the client creator to get called back on download progress and completion.
	HubProgressUpdater ui.Progress
	// Optional: Logger framework can use to log.
	// default: global logger provided.
	Logger hclog.Logger
	// Optional: Hub client to use to download plugins, the Hub is used to download and pluginManager providers binaries
	// if not specified, default cloudquery registry is used.
	Hub registry.Hub
	// manager manages all plugins lifecycle
	Manager *plugin.Manager
	// ModuleManager manages all modules lifecycle
	ModuleManager module.Manager
	// ModuleManager manages all modules lifecycle
	PolicyManager policy.Manager
	// TableCreator defines how table are created in the database
	TableCreator TableCreator
	// contains filtered or unexported fields
}

Client is the client for executing providers, fetching data and running queries and polices

func New

func New(ctx context.Context, options ...Option) (*Client, error)

func (*Client) BuildProviderTables added in v0.14.0

func (c *Client) BuildProviderTables(ctx context.Context, providerName string) error

func (*Client) Close

func (c *Client) Close()

func (*Client) DowngradeProvider added in v0.14.5

func (c *Client) DowngradeProvider(ctx context.Context, providerName string) error

func (*Client) DownloadPolicy added in v0.13.8

func (c *Client) DownloadPolicy(ctx context.Context, args []string) (*policy.RemotePolicy, error)

func (*Client) DownloadProviders added in v0.13.6

func (c *Client) DownloadProviders(ctx context.Context) error

DownloadProviders downloads all provider binaries

func (*Client) DropProvider added in v0.14.5

func (c *Client) DropProvider(ctx context.Context, providerName string) error

func (*Client) ExecuteModule added in v0.15.10

func (c *Client) ExecuteModule(ctx context.Context, req ModuleRunRequest) (*module.ExecutionResult, error)

func (*Client) Fetch

func (c *Client) Fetch(ctx context.Context, request FetchRequest) (*FetchResponse, error)

func (*Client) GetProviderConfiguration

func (c *Client) GetProviderConfiguration(ctx context.Context, providerName string) (*cqproto.GetProviderConfigResponse, error)

func (*Client) GetProviderSchema

func (c *Client) GetProviderSchema(ctx context.Context, providerName string) (*cqproto.GetProviderSchemaResponse, error)

func (*Client) NormalizeResources added in v0.15.5

func (c *Client) NormalizeResources(ctx context.Context, providers []*config.Provider) error

NormalizeResources walks over all given providers and in place normalizes their resources list:

* wildcard expansion * no unknown resources * no duplicate resources

func (*Client) RunPolicies added in v0.16.0

func (c *Client) RunPolicies(ctx context.Context, req *PoliciesRunRequest) ([]*policy.ExecutionResult, error)

func (*Client) SetProviderVersion added in v0.15.1

func (c *Client) SetProviderVersion(ctx context.Context, providerName, version string) error

func (*Client) TestProvider added in v0.14.6

func (c *Client) TestProvider(ctx context.Context, providerCfg *config.Provider) error

func (*Client) UpgradeProvider added in v0.14.5

func (c *Client) UpgradeProvider(ctx context.Context, providerName string) error

type FetchDoneResult

type FetchDoneResult struct {
	// Map of providers and resources that have finished fetching
	DoneResources map[string]map[string]bool
	// Amount of resources collected so far
	ResourceCount string
}

type FetchRequest

type FetchRequest struct {
	// UpdateCallback allows gets called when the client receives updates on fetch.
	UpdateCallback FetchUpdateCallback
	// Providers list of providers to call for fetching
	Providers []*config.Provider
	// Optional: Disable deletion of data from tables.
	// Use this with caution, as it can create duplicates of data!
	DisableDataDelete bool
	// Optional: Adds extra fields to the provider, this is used for testing purposes.
	ExtraFields map[string]interface{}
}

FetchRequest is provided to the Client to execute a fetch on one or more providers

type FetchResponse added in v0.15.0

type FetchResponse struct {
	ProviderFetchSummary map[string]ProviderFetchSummary
}

FetchResponse is returned after a successful fetch execution, it holds a fetch summary for each provider that was executed.

type FetchUpdate

type FetchUpdate struct {
	Provider string
	Version  string
	// Map of resources that have finished fetching
	FinishedResources map[string]bool
	// Amount of resources collected so far
	ResourceCount uint64
	// Error if any returned by the provider
	Error string
	// PartialFetchResults contains the partial fetch results for this update
	PartialFetchResults []*cqproto.FailedResourceFetch
}

func (FetchUpdate) AllDone

func (f FetchUpdate) AllDone() bool

func (FetchUpdate) DoneCount

func (f FetchUpdate) DoneCount() int

type FetchUpdateCallback

type FetchUpdateCallback func(update FetchUpdate)

type ModuleRunRequest added in v0.15.10

type ModuleRunRequest struct {
	// Name of the module
	Name string

	// Params are the invocation parameters specific to the module
	Params interface{}

	// Providers is the list of providers to process
	Providers []*cqproto.GetProviderSchemaResponse

	// Config is the config profile provided by the user
	Config hcl.Body
}

ModuleRunRequest is the request used to run a module.

type Option

type Option func(options *Client)

type PoliciesRunRequest added in v0.16.0

type PoliciesRunRequest struct {
	// Policies to run
	Policies []*config.Policy

	// PolicyName is optional attr to run specific policy
	PolicyName string

	// OutputDir is the output dir for policy execution output.
	OutputDir string

	// StopOnFailure signals policy execution to stop after first failure.
	StopOnFailure bool

	// RunCallBack is the callback method that is called after every policy execution.
	RunCallback policy.UpdateCallback

	// SkipVersioning if true policy will be executed without checking out the version of the policy repo using git tags
	SkipVersioning bool

	// FailOnViolation if true policy run will return error if there are violations
	FailOnViolation bool
}

PoliciesRunRequest is the request used to run a policy.

type ProviderFetchSummary added in v0.15.0

type ProviderFetchSummary struct {
	ProviderName          string
	PartialFetchErrors    []*cqproto.FailedResourceFetch
	FetchErrors           []error
	TotalResourcesFetched uint64
	FetchResources        map[string]cqproto.ResourceFetchSummary
}

ProviderFetchSummary represents a request for the FetchFinishCallback

func (ProviderFetchSummary) Diagnostics added in v0.15.8

func (p ProviderFetchSummary) Diagnostics() diag.Diagnostics

func (ProviderFetchSummary) HasErrors added in v0.15.1

func (p ProviderFetchSummary) HasErrors() bool

type TableCreator added in v0.14.0

type TableCreator interface {
	CreateTable(ctx context.Context, conn *pgxpool.Conn, t *schema.Table, p *schema.Table) error
}

TableCreator creates tables based on schema received from providers

Jump to

Keyboard shortcuts

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