cwhub

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (
	HubIndexFile = ".index.json"

	// managed item types
	PARSERS       = "parsers"
	PARSERS_OVFLW = "postoverflows"
	SCENARIOS     = "scenarios"
	COLLECTIONS   = "collections"
)

Variables

View Source
var (
	ItemTypes = []string{PARSERS, PARSERS_OVFLW, SCENARIOS, COLLECTIONS}

	ErrMissingReference = errors.New("Reference(s) missing in collection")

	RawFileURLTemplate = "https://hub-cdn.crowdsec.net/%s/%s"
	HubBranch          = "master"
)
View Source
var ErrIndexNotFound = fmt.Errorf("index not found")

Functions

func AddItem added in v1.0.0

func AddItem(itemType string, item Item) error

func CollecDepsCheck

func CollecDepsCheck(v *Item) error

func DisableItem

func DisableItem(hub *csconfig.Hub, target *Item, purge bool, force bool) error

DisableItem to disable an item managed by the hub, removes the symlink if purge is true

func DisplaySummary

func DisplaySummary()

func DownloadDataIfNeeded added in v1.2.0

func DownloadDataIfNeeded(hub *csconfig.Hub, target Item, force bool) error

func DownloadHubIdx

func DownloadHubIdx(hub *csconfig.Hub) ([]byte, error)

func DownloadItem

func DownloadItem(hub *csconfig.Hub, target *Item, overwrite bool) error

func DownloadLatest

func DownloadLatest(hub *csconfig.Hub, target *Item, overwrite bool, updateOnly bool) error

DownloadLatest will download the latest version of Item to the tdir directory

func EnableItem

func EnableItem(hub *csconfig.Hub, target *Item) error

creates symlink between actual config file at hub.HubDir and hub.ConfigDir Handles collections recursively

func GetData added in v1.5.3

func GetData(data []*types.DataSource, dataDir string) error

func GetHubIdx

func GetHubIdx(hub *csconfig.Hub) error

func GetInstalledItemsAsString added in v1.5.5

func GetInstalledItemsAsString(itemType string) ([]string, error)

func GetItemMap added in v1.0.0

func GetItemMap(itemType string) map[string]Item

func InstallItem added in v1.3.3

func InstallItem(csConfig *csconfig.Config, name string, obtype string, force bool, downloadOnly bool) error

func LoadPkgIndex

func LoadPkgIndex(buff []byte) (map[string]map[string]Item, error)

LoadPkgIndex loads a local .index.json file and returns the map of associated parsers/scenarios/collections

func LocalSync

func LocalSync(hub *csconfig.Hub) ([]string, error)

Updates the info from HubInit() with the local state

func RemoveMany added in v1.3.3

func RemoveMany(csConfig *csconfig.Config, itemType string, name string, all bool, purge bool, forceAction bool)

XXX this must return errors instead of log.Fatal

func SetHubBranch added in v1.4.0

func SetHubBranch()

SetHubBranch sets the package variable that points to the hub branch.

func SyncDir added in v1.0.0

func SyncDir(hub *csconfig.Hub, dir string) ([]string, error)

func UpdateHubIdx

func UpdateHubIdx(hub *csconfig.Hub) error

func UpgradeConfig added in v1.3.3

func UpgradeConfig(csConfig *csconfig.Config, itemType string, name string, force bool)

Types

type DataSet added in v1.5.3

type DataSet struct {
	Data []*types.DataSource `yaml:"data,omitempty"`
}

type Item

type Item struct {
	// descriptive info
	Type                 string   `json:"type,omitempty"                   yaml:"type,omitempty"`                   // parser|postoverflows|scenario|collection(|enrich)
	Stage                string   `json:"stage,omitempty"                  yaml:"stage,omitempty"`                  // Stage for parser|postoverflow: s00-raw/s01-...
	Name                 string   `json:"name,omitempty"`                                                           // as seen in .config.json, usually "author/name"
	FileName             string   `json:"file_name,omitempty"`                                                      // the filename, ie. apache2-logs.yaml
	Description          string   `json:"description,omitempty"            yaml:"description,omitempty"`            // as seen in .config.json
	Author               string   `json:"author,omitempty"`                                                         // as seen in .config.json
	References           []string `json:"references,omitempty"             yaml:"references,omitempty"`             // as seen in .config.json
	BelongsToCollections []string `json:"belongs_to_collections,omitempty" yaml:"belongs_to_collections,omitempty"` // parent collection if any

	// remote (hub) info
	RemotePath string                 `json:"path,omitempty"      yaml:"remote_path,omitempty"` // the path relative to (git | hub API) ie. /parsers/stage/author/file.yaml
	Version    string                 `json:"version,omitempty"`                                // the last version
	Versions   map[string]ItemVersion `json:"versions,omitempty"  yaml:"-"`                     // the list of existing versions

	// local (deployed) info
	LocalPath    string `json:"local_path,omitempty" yaml:"local_path,omitempty"` // the local path relative to ${CFG_DIR}
	LocalVersion string `json:"local_version,omitempty"`
	LocalHash    string `json:"local_hash,omitempty"` // the local meow
	Installed    bool   `json:"installed,omitempty"`
	Downloaded   bool   `json:"downloaded,omitempty"`
	UpToDate     bool   `json:"up_to_date,omitempty"`
	Tainted      bool   `json:"tainted,omitempty"` // has it been locally modified
	Local        bool   `json:"local,omitempty"`   // if it's a non versioned control one

	// if it's a collection, it's not a single file
	Parsers       []string `json:"parsers,omitempty"       yaml:"parsers,omitempty"`
	PostOverflows []string `json:"postoverflows,omitempty" yaml:"postoverflows,omitempty"`
	Scenarios     []string `json:"scenarios,omitempty"     yaml:"scenarios,omitempty"`
	Collections   []string `json:"collections,omitempty"   yaml:"collections,omitempty"`
}

Item can be: parser, scenario, collection..

func GetInstalledItems added in v1.5.5

func GetInstalledItems(itemType string) ([]Item, error)

func GetItem added in v1.0.0

func GetItem(itemType string, itemName string) *Item

func GetItemByPath added in v1.0.0

func GetItemByPath(itemType string, itemPath string) (*Item, error)

GetItemByPath retrieves the item from hubIdx based on the path. To achieve this it will resolve symlink to find associated hub item.

type ItemHubStatus added in v1.2.3

type ItemHubStatus struct {
	Name         string `json:"name"`
	LocalVersion string `json:"local_version"`
	LocalPath    string `json:"local_path"`
	Description  string `json:"description"`
	UTF8Status   string `json:"utf8_status"`
	Status       string `json:"status"`
}

func GetHubStatusForItemType added in v1.2.3

func GetHubStatusForItemType(itemType string, name string, all bool) []ItemHubStatus

Returns a slice of entries for packages: name, status, local_path, local_version, utf8_status (fancy)

type ItemVersion

type ItemVersion struct {
	Digest     string `json:"digest,omitempty"` // meow
	Deprecated bool   `json:"deprecated,omitempty"`
}

type Walker added in v1.5.5

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

func NewWalker added in v1.5.5

func NewWalker(hub *csconfig.Hub) Walker

Jump to

Keyboard shortcuts

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