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

Function addContextFromFile

pkg/alertcontext/config.go:77–99  ·  view source on GitHub ↗

addContextFromFile merges the context from a file into the context to send to the console.

(toSend map[string][]string, filePath string)

Source from the content-addressed store, hash-verified

75
76// addContextFromFile merges the context from a file into the context to send to the console.
77func addContextFromFile(toSend map[string][]string, filePath string) error {
78 log.Tracef("loading console context from %s", filePath)
79
80 content, err := os.ReadFile(filePath)
81 if err != nil {
82 return err
83 }
84
85 newContext := make(map[string][]string, 0)
86
87 err = yaml.Unmarshal(content, newContext)
88 if err != nil {
89 return fmt.Errorf("%s: %w", filePath, err)
90 }
91
92 err = mergeContext(toSend, newContext)
93 if err != nil && !errors.Is(err, ErrNoContextData) {
94 // having an empty console/context.yaml is not an error
95 return err
96 }
97
98 return nil
99}
100
101// LoadConsoleContext loads the context from the hub (if provided) and the file console_context_path.
102func LoadConsoleContext(c *csconfig.Config, hub *cwhub.Hub) error {

Callers 1

LoadConsoleContextFunction · 0.85

Calls 2

mergeContextFunction · 0.85
TracefMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…