MCPcopy
hub / github.com/crowdsecurity/crowdsec / Command

Interface Command

pkg/hubops/plan.go:25–52  ·  view source on GitHub ↗

Command represents an operation that can be performed on a CrowdSec hub item. Each concrete implementation defines a Prepare() method to check for errors and preconditions, decide which sub-commands are required (like installing dependencies) and add them to the action plan.

Source from the content-addressed store, hash-verified

23// Each concrete implementation defines a Prepare() method to check for errors and preconditions,
24// decide which sub-commands are required (like installing dependencies) and add them to the action plan.
25type Command interface {
26 // Prepare sets up the command for execution within the given
27 // ActionPlan. It may add additional commands to the ActionPlan based
28 // on dependencies or prerequisites. Returns a boolean indicating
29 // whether the command execution should be skipped (it can be
30 // redundant, like installing something that is already installed) and
31 // an error if the preparation failed.
32 // NOTE: Returning an error will bubble up from the plan.AddCommand() method,
33 // but Prepare() might already have modified the plan's command slice.
34 Prepare(plan *ActionPlan) (bool, error)
35
36 // Run executes the command within the provided context and ActionPlan.
37 // It performs the actual operation and returns an error if execution fails.
38 // NOTE: Returning an error will currently stop the execution of the action plan.
39 Run(ctx context.Context, plan *ActionPlan) error
40
41 // OperationType returns a unique string representing the type of operation to perform
42 // (e.g., "download", "enable").
43 OperationType() string
44
45 // ItemType returns the type of item the operation is performed on
46 // (e.g., "collections"). Used in confirmation prompt and dry-run.
47 ItemType() string
48
49 // Detail provides further details on the operation,
50 // such as the item's name and version.
51 Detail() string
52}
53
54// UniqueKey generates a unique string key for a Command based on its operation type, item type, and detail.
55// Is is used to avoid adding duplicate commands to the action plan.

Callers 19

AddCommandMethod · 0.65
EvalAlertContextRulesFunction · 0.65
ExecuteMethod · 0.65
TestParseSourceConfigFunction · 0.65
TestDataSourceConfigureFunction · 0.65
TestConfigureByDSNFunction · 0.65
colorizeOpTypeFunction · 0.65
UniqueKeyFunction · 0.65
verboseDescriptionMethod · 0.65

Implementers 5

PurgeCommandpkg/hubops/purge.go
EnableCommandpkg/hubops/enable.go
DownloadCommandpkg/hubops/download.go
DisableCommandpkg/hubops/disable.go
DataRefreshCommandpkg/hubops/datarefresh.go

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…