mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 12:25:53 +02:00
logs and user messages: use "parse" and "serialize" instead of marshal/unmarshal (#3240)
This commit is contained in:
parent
1591a0c46e
commit
ce085dc4cd
56 changed files with 87 additions and 87 deletions
|
@ -521,14 +521,14 @@ func (cli *cliAlerts) inspect(details bool, alertIDs ...string) error {
|
||||||
case "json":
|
case "json":
|
||||||
data, err := json.MarshalIndent(alert, "", " ")
|
data, err := json.MarshalIndent(alert, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to marshal alert with id %s: %w", alertID, err)
|
return fmt.Errorf("unable to serialize alert with id %s: %w", alertID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%s\n", string(data))
|
fmt.Printf("%s\n", string(data))
|
||||||
case "raw":
|
case "raw":
|
||||||
data, err := yaml.Marshal(alert)
|
data, err := yaml.Marshal(alert)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to marshal alert with id %s: %w", alertID, err)
|
return fmt.Errorf("unable to serialize alert with id %s: %w", alertID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(string(data))
|
fmt.Println(string(data))
|
||||||
|
|
|
@ -181,7 +181,7 @@ func (cli *cliBouncers) List(out io.Writer, db *database.Client) error {
|
||||||
enc.SetIndent("", " ")
|
enc.SetIndent("", " ")
|
||||||
|
|
||||||
if err := enc.Encode(info); err != nil {
|
if err := enc.Encode(info); err != nil {
|
||||||
return errors.New("failed to marshal")
|
return errors.New("failed to serialize")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -234,7 +234,7 @@ func (cli *cliBouncers) add(bouncerName string, key string) error {
|
||||||
case "json":
|
case "json":
|
||||||
j, err := json.Marshal(key)
|
j, err := json.Marshal(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("unable to marshal api key")
|
return errors.New("unable to serialize api key")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print(string(j))
|
fmt.Print(string(j))
|
||||||
|
@ -458,7 +458,7 @@ func (cli *cliBouncers) inspect(bouncer *ent.Bouncer) error {
|
||||||
enc.SetIndent("", " ")
|
enc.SetIndent("", " ")
|
||||||
|
|
||||||
if err := enc.Encode(newBouncerInfo(bouncer)); err != nil {
|
if err := enc.Encode(newBouncerInfo(bouncer)); err != nil {
|
||||||
return errors.New("failed to marshal")
|
return errors.New("failed to serialize")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -104,7 +104,7 @@ func (cli *cliCapi) register(ctx context.Context, capiUserPrefix string, outputF
|
||||||
|
|
||||||
apiConfigDump, err := yaml.Marshal(apiCfg)
|
apiConfigDump, err := yaml.Marshal(apiCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to marshal api credentials: %w", err)
|
return fmt.Errorf("unable to serialize api credentials: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if dumpFile != "" {
|
if dumpFile != "" {
|
||||||
|
|
|
@ -280,7 +280,7 @@ func (cli *cliConsole) newStatusCmd() *cobra.Command {
|
||||||
}
|
}
|
||||||
data, err := json.MarshalIndent(out, "", " ")
|
data, err := json.MarshalIndent(out, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to marshal configuration: %w", err)
|
return fmt.Errorf("failed to serialize configuration: %w", err)
|
||||||
}
|
}
|
||||||
fmt.Println(string(data))
|
fmt.Println(string(data))
|
||||||
case "raw":
|
case "raw":
|
||||||
|
@ -318,7 +318,7 @@ func (cli *cliConsole) dumpConfig() error {
|
||||||
|
|
||||||
out, err := yaml.Marshal(serverCfg.ConsoleConfig)
|
out, err := yaml.Marshal(serverCfg.ConsoleConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("while marshaling ConsoleConfig (for %s): %w", serverCfg.ConsoleConfigPath, err)
|
return fmt.Errorf("while serializing ConsoleConfig (for %s): %w", serverCfg.ConsoleConfigPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if serverCfg.ConsoleConfigPath == "" {
|
if serverCfg.ConsoleConfigPath == "" {
|
||||||
|
@ -361,7 +361,7 @@ func (cli *cliConsole) setConsoleOpts(args []string, wanted bool) error {
|
||||||
if changed {
|
if changed {
|
||||||
fileContent, err := yaml.Marshal(cfg.API.Server.OnlineClient.Credentials)
|
fileContent, err := yaml.Marshal(cfg.API.Server.OnlineClient.Credentials)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot marshal credentials: %w", err)
|
return fmt.Errorf("cannot serialize credentials: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Updating credentials file: %s", cfg.API.Server.OnlineClient.CredentialsFilePath)
|
log.Infof("Updating credentials file: %s", cfg.API.Server.OnlineClient.CredentialsFilePath)
|
||||||
|
|
|
@ -106,7 +106,7 @@ func ListItems(out io.Writer, wantColor string, itemTypes []string, items map[st
|
||||||
|
|
||||||
x, err := json.MarshalIndent(hubStatus, "", " ")
|
x, err := json.MarshalIndent(hubStatus, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to unmarshal: %w", err)
|
return fmt.Errorf("failed to parse: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
out.Write(x)
|
out.Write(x)
|
||||||
|
@ -158,7 +158,7 @@ func InspectItem(item *cwhub.Item, wantMetrics bool, output string, prometheusUR
|
||||||
case "json":
|
case "json":
|
||||||
b, err := json.MarshalIndent(*item, "", " ")
|
b, err := json.MarshalIndent(*item, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to marshal item: %w", err)
|
return fmt.Errorf("unable to serialize item: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print(string(b))
|
fmt.Print(string(b))
|
||||||
|
|
|
@ -134,7 +134,7 @@ cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios
|
||||||
}
|
}
|
||||||
data, err := yaml.Marshal(configFileData)
|
data, err := yaml.Marshal(configFileData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("marshal: %w", err)
|
return fmt.Errorf("serialize: %w", err)
|
||||||
}
|
}
|
||||||
_, err = fd.Write(data)
|
_, err = fd.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -62,7 +62,7 @@ func NewAppsecRule(cfg configGetter) *cliItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := yaml.Unmarshal(yamlContent, &appsecRule); err != nil {
|
if err := yaml.Unmarshal(yamlContent, &appsecRule); err != nil {
|
||||||
return fmt.Errorf("unable to unmarshal yaml file %s: %w", item.State.LocalPath, err)
|
return fmt.Errorf("unable to parse yaml file %s: %w", item.State.LocalPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ruleType := range appsec_rule.SupportedTypes() {
|
for _, ruleType := range appsec_rule.SupportedTypes() {
|
||||||
|
|
|
@ -147,7 +147,7 @@ func (cli *cliLapi) register(ctx context.Context, apiURL string, outputFile stri
|
||||||
|
|
||||||
apiConfigDump, err := yaml.Marshal(apiCfg)
|
apiConfigDump, err := yaml.Marshal(apiCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to marshal api credentials: %w", err)
|
return fmt.Errorf("unable to serialize api credentials: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if dumpFile != "" {
|
if dumpFile != "" {
|
||||||
|
|
|
@ -232,7 +232,7 @@ func (cli *cliMachines) List(out io.Writer, db *database.Client) error {
|
||||||
enc.SetIndent("", " ")
|
enc.SetIndent("", " ")
|
||||||
|
|
||||||
if err := enc.Encode(info); err != nil {
|
if err := enc.Encode(info); err != nil {
|
||||||
return errors.New("failed to marshal")
|
return errors.New("failed to serialize")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -378,7 +378,7 @@ func (cli *cliMachines) add(args []string, machinePassword string, dumpFile stri
|
||||||
|
|
||||||
apiConfigDump, err := yaml.Marshal(apiCfg)
|
apiConfigDump, err := yaml.Marshal(apiCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to marshal api credentials: %w", err)
|
return fmt.Errorf("unable to serialize api credentials: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if dumpFile != "" && dumpFile != "-" {
|
if dumpFile != "" && dumpFile != "-" {
|
||||||
|
@ -626,7 +626,7 @@ func (cli *cliMachines) inspect(machine *ent.Machine) error {
|
||||||
enc.SetIndent("", " ")
|
enc.SetIndent("", " ")
|
||||||
|
|
||||||
if err := enc.Encode(newMachineInfo(machine)); err != nil {
|
if err := enc.Encode(newMachineInfo(machine)); err != nil {
|
||||||
return errors.New("failed to marshal")
|
return errors.New("failed to serialize")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -648,7 +648,7 @@ func (cli *cliMachines) inspectHub(machine *ent.Machine) error {
|
||||||
enc.SetIndent("", " ")
|
enc.SetIndent("", " ")
|
||||||
|
|
||||||
if err := enc.Encode(machine.Hubstate); err != nil {
|
if err := enc.Encode(machine.Hubstate); err != nil {
|
||||||
return errors.New("failed to marshal")
|
return errors.New("failed to serialize")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -68,7 +68,7 @@ func (cli *cliMetrics) list() error {
|
||||||
case "json":
|
case "json":
|
||||||
x, err := json.MarshalIndent(allMetrics, "", " ")
|
x, err := json.MarshalIndent(allMetrics, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to marshal metric types: %w", err)
|
return fmt.Errorf("failed to serialize metric types: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(string(x))
|
fmt.Println(string(x))
|
||||||
|
|
|
@ -260,7 +260,7 @@ func (ms metricStore) Format(out io.Writer, wantColor string, sections []string,
|
||||||
case "json":
|
case "json":
|
||||||
x, err := json.MarshalIndent(want, "", " ")
|
x, err := json.MarshalIndent(want, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to marshal metrics: %w", err)
|
return fmt.Errorf("failed to serialize metrics: %w", err)
|
||||||
}
|
}
|
||||||
out.Write(x)
|
out.Write(x)
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -172,7 +172,7 @@ func (cli *cliNotifications) newListCmd() *cobra.Command {
|
||||||
} else if cfg.Cscli.Output == "json" {
|
} else if cfg.Cscli.Output == "json" {
|
||||||
x, err := json.MarshalIndent(ncfgs, "", " ")
|
x, err := json.MarshalIndent(ncfgs, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to marshal notification configuration: %w", err)
|
return fmt.Errorf("failed to serialize notification configuration: %w", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("%s", string(x))
|
fmt.Printf("%s", string(x))
|
||||||
} else if cfg.Cscli.Output == "raw" {
|
} else if cfg.Cscli.Output == "raw" {
|
||||||
|
@ -231,7 +231,7 @@ func (cli *cliNotifications) newInspectCmd() *cobra.Command {
|
||||||
} else if cfg.Cscli.Output == "json" {
|
} else if cfg.Cscli.Output == "json" {
|
||||||
x, err := json.MarshalIndent(cfg, "", " ")
|
x, err := json.MarshalIndent(cfg, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to marshal notification configuration: %w", err)
|
return fmt.Errorf("failed to serialize notification configuration: %w", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("%s", string(x))
|
fmt.Printf("%s", string(x))
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ func (cli cliNotifications) newTestCmd() *cobra.Command {
|
||||||
CreatedAt: time.Now().UTC().Format(time.RFC3339),
|
CreatedAt: time.Now().UTC().Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
if err := yaml.Unmarshal([]byte(alertOverride), alert); err != nil {
|
if err := yaml.Unmarshal([]byte(alertOverride), alert); err != nil {
|
||||||
return fmt.Errorf("failed to unmarshal alert override: %w", err)
|
return fmt.Errorf("failed to parse alert override: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginBroker.PluginChannel <- csplugin.ProfileAlert{
|
pluginBroker.PluginChannel <- csplugin.ProfileAlert{
|
||||||
|
@ -387,7 +387,7 @@ cscli notifications reinject <alert_id> -a '{"remediation": true,"scenario":"not
|
||||||
|
|
||||||
if alertOverride != "" {
|
if alertOverride != "" {
|
||||||
if err := json.Unmarshal([]byte(alertOverride), alert); err != nil {
|
if err := json.Unmarshal([]byte(alertOverride), alert); err != nil {
|
||||||
return fmt.Errorf("can't unmarshal data in the alert flag: %w", err)
|
return fmt.Errorf("can't parse data in the alert flag: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,7 +227,7 @@ func setupAsString(cs setup.Setup, outYaml bool) (string, error) {
|
||||||
)
|
)
|
||||||
|
|
||||||
wrap := func(err error) error {
|
wrap := func(err error) error {
|
||||||
return fmt.Errorf("while marshaling setup: %w", err)
|
return fmt.Errorf("while serializing setup: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
indentLevel := 2
|
indentLevel := 2
|
||||||
|
|
|
@ -220,7 +220,7 @@ func (cli *cliSimulation) dumpSimulationFile() error {
|
||||||
|
|
||||||
newConfigSim, err := yaml.Marshal(cfg.Cscli.SimulationConfig)
|
newConfigSim, err := yaml.Marshal(cfg.Cscli.SimulationConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to marshal simulation configuration: %w", err)
|
return fmt.Errorf("unable to serialize simulation configuration: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.WriteFile(cfg.ConfigPaths.SimulationFilePath, newConfigSim, 0o644)
|
err = os.WriteFile(cfg.ConfigPaths.SimulationFilePath, newConfigSim, 0o644)
|
||||||
|
@ -242,7 +242,7 @@ func (cli *cliSimulation) disableGlobalSimulation() error {
|
||||||
|
|
||||||
newConfigSim, err := yaml.Marshal(cfg.Cscli.SimulationConfig)
|
newConfigSim, err := yaml.Marshal(cfg.Cscli.SimulationConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to marshal new simulation configuration: %w", err)
|
return fmt.Errorf("unable to serialize new simulation configuration: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.WriteFile(cfg.ConfigPaths.SimulationFilePath, newConfigSim, 0o644)
|
err = os.WriteFile(cfg.ConfigPaths.SimulationFilePath, newConfigSim, 0o644)
|
||||||
|
|
|
@ -74,7 +74,7 @@ func (cli *cliConfig) backupHub(dirPath string) error {
|
||||||
|
|
||||||
upstreamParsersContent, err := json.MarshalIndent(upstreamParsers, "", " ")
|
upstreamParsersContent, err := json.MarshalIndent(upstreamParsers, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed marshaling upstream parsers: %w", err)
|
return fmt.Errorf("failed to serialize upstream parsers: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.WriteFile(upstreamParsersFname, upstreamParsersContent, 0o644)
|
err = os.WriteFile(upstreamParsersFname, upstreamParsersContent, 0o644)
|
||||||
|
|
|
@ -40,7 +40,7 @@ func (cli *cliConfig) restoreHub(ctx context.Context, dirPath string) error {
|
||||||
|
|
||||||
err = json.Unmarshal(file, &upstreamList)
|
err = json.Unmarshal(file, &upstreamList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error unmarshaling %s: %w", upstreamListFN, err)
|
return fmt.Errorf("error parsing %s: %w", upstreamListFN, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, toinstall := range upstreamList {
|
for _, toinstall := range upstreamList {
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (cli *cliConfig) showKey(key string) error {
|
||||||
case "json":
|
case "json":
|
||||||
data, err := json.MarshalIndent(output, "", " ")
|
data, err := json.MarshalIndent(output, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to marshal configuration: %w", err)
|
return fmt.Errorf("failed to serialize configuration: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(string(data))
|
fmt.Println(string(data))
|
||||||
|
@ -212,14 +212,14 @@ func (cli *cliConfig) show() error {
|
||||||
case "json":
|
case "json":
|
||||||
data, err := json.MarshalIndent(cfg, "", " ")
|
data, err := json.MarshalIndent(cfg, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to marshal configuration: %w", err)
|
return fmt.Errorf("failed to serialize configuration: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(string(data))
|
fmt.Println(string(data))
|
||||||
case "raw":
|
case "raw":
|
||||||
data, err := yaml.Marshal(cfg)
|
data, err := yaml.Marshal(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to marshal configuration: %w", err)
|
return fmt.Errorf("failed to serialize configuration: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(string(data))
|
fmt.Println(string(data))
|
||||||
|
|
|
@ -32,7 +32,7 @@ func runPour(input chan types.Event, holders []leaky.BucketFactory, buckets *lea
|
||||||
if parsed.MarshaledTime != "" {
|
if parsed.MarshaledTime != "" {
|
||||||
z := &time.Time{}
|
z := &time.Time{}
|
||||||
if err := z.UnmarshalText([]byte(parsed.MarshaledTime)); err != nil {
|
if err := z.UnmarshalText([]byte(parsed.MarshaledTime)); err != nil {
|
||||||
log.Warningf("Failed to unmarshal time from event '%s' : %s", parsed.MarshaledTime, err)
|
log.Warningf("Failed to parse time from event '%s' : %s", parsed.MarshaledTime, err)
|
||||||
} else {
|
} else {
|
||||||
log.Warning("Starting buckets garbage collection ...")
|
log.Warning("Starting buckets garbage collection ...")
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ func runPour(input chan types.Event, holders []leaky.BucketFactory, buckets *lea
|
||||||
|
|
||||||
if len(parsed.MarshaledTime) != 0 {
|
if len(parsed.MarshaledTime) != 0 {
|
||||||
if err := lastProcessedItem.UnmarshalText([]byte(parsed.MarshaledTime)); err != nil {
|
if err := lastProcessedItem.UnmarshalText([]byte(parsed.MarshaledTime)); err != nil {
|
||||||
log.Warningf("failed to unmarshal time from event : %s", err)
|
log.Warningf("failed to parse time from event : %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,7 +210,7 @@ func (s *FilePlugin) Configure(ctx context.Context, config *protobufs.Config) (*
|
||||||
d := PluginConfig{}
|
d := PluginConfig{}
|
||||||
err := yaml.Unmarshal(config.Config, &d)
|
err := yaml.Unmarshal(config.Config, &d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Failed to unmarshal config", "error", err)
|
logger.Error("Failed to parse config", "error", err)
|
||||||
return &protobufs.Empty{}, err
|
return &protobufs.Empty{}, err
|
||||||
}
|
}
|
||||||
FileWriteMutex = &sync.Mutex{}
|
FileWriteMutex = &sync.Mutex{}
|
||||||
|
|
|
@ -129,7 +129,7 @@ func DataSourceConfigure(commonConfig configuration.DataSourceCommonCfg, metrics
|
||||||
// once to DataSourceCommonCfg, and then later to the dedicated type of the datasource
|
// once to DataSourceCommonCfg, and then later to the dedicated type of the datasource
|
||||||
yamlConfig, err := yaml.Marshal(commonConfig)
|
yamlConfig, err := yaml.Marshal(commonConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to marshal back interface: %w", err)
|
return nil, fmt.Errorf("unable to serialize back interface: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dataSrc, err := GetDataSourceIface(commonConfig.Source)
|
dataSrc, err := GetDataSourceIface(commonConfig.Source)
|
||||||
|
|
|
@ -393,7 +393,7 @@ func (w *AppsecSource) appsecHandler(rw http.ResponseWriter, r *http.Request) {
|
||||||
rw.WriteHeader(statusCode)
|
rw.WriteHeader(statusCode)
|
||||||
body, err := json.Marshal(appsecResponse)
|
body, err := json.Marshal(appsecResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("unable to marshal response: %s", err)
|
logger.Errorf("unable to serialize response: %s", err)
|
||||||
rw.WriteHeader(http.StatusInternalServerError)
|
rw.WriteHeader(http.StatusInternalServerError)
|
||||||
} else {
|
} else {
|
||||||
rw.Write(body)
|
rw.Write(body)
|
||||||
|
|
|
@ -82,7 +82,7 @@ func (k *KafkaSource) UnmarshalConfig(yamlConfig []byte) error {
|
||||||
k.Config.Mode = configuration.TAIL_MODE
|
k.Config.Mode = configuration.TAIL_MODE
|
||||||
}
|
}
|
||||||
|
|
||||||
k.logger.Debugf("successfully unmarshaled kafka configuration : %+v", k.Config)
|
k.logger.Debugf("successfully parsed kafka configuration : %+v", k.Config)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,7 +196,7 @@ func (ka *KubernetesAuditSource) webhookHandler(w http.ResponseWriter, r *http.R
|
||||||
}
|
}
|
||||||
bytesEvent, err := json.Marshal(auditEvent)
|
bytesEvent, err := json.Marshal(auditEvent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ka.logger.Errorf("Error marshaling audit event: %s", err)
|
ka.logger.Errorf("Error serializing audit event: %s", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ka.logger.Tracef("Got audit event: %s", string(bytesEvent))
|
ka.logger.Tracef("Got audit event: %s", string(bytesEvent))
|
||||||
|
|
|
@ -149,7 +149,7 @@ func (w *WinEventLogSource) buildXpathQuery() (string, error) {
|
||||||
queryList := QueryList{Select: Select{Path: w.config.EventChannel, Query: query}}
|
queryList := QueryList{Select: Select{Path: w.config.EventChannel, Query: query}}
|
||||||
xpathQuery, err := xml.Marshal(queryList)
|
xpathQuery, err := xml.Marshal(queryList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.logger.Errorf("Marshal failed: %v", err)
|
w.logger.Errorf("Serialize failed: %v", err)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
w.logger.Debugf("xpathQuery: %s", xpathQuery)
|
w.logger.Debugf("xpathQuery: %s", xpathQuery)
|
||||||
|
|
|
@ -133,7 +133,7 @@ func LoadConsoleContext(c *csconfig.Config, hub *cwhub.Hub) error {
|
||||||
|
|
||||||
feedback, err := json.Marshal(c.Crowdsec.ContextToSend)
|
feedback, err := json.Marshal(c.Crowdsec.ContextToSend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("marshaling console context: %s", err)
|
return fmt.Errorf("serializing console context: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("console context to send: %s", feedback)
|
log.Debugf("console context to send: %s", feedback)
|
||||||
|
|
|
@ -70,7 +70,7 @@ func (a *apic) GetUsageMetrics() (*models.AllMetrics, []int, error) {
|
||||||
|
|
||||||
err := json.Unmarshal([]byte(dbMetric.Payload), dbPayload)
|
err := json.Unmarshal([]byte(dbMetric.Payload), dbPayload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("unable to unmarshal bouncer metric (%s)", err)
|
log.Errorf("unable to parse bouncer metric (%s)", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ func (a *apic) GetUsageMetrics() (*models.AllMetrics, []int, error) {
|
||||||
|
|
||||||
err := json.Unmarshal([]byte(dbMetric.Payload), dbPayload)
|
err := json.Unmarshal([]byte(dbMetric.Payload), dbPayload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("unable to unmarshal log processor metric (%s)", err)
|
log.Errorf("unable to parse log processor metric (%s)", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ func FormatOneAlert(alert *ent.Alert) *models.Alert {
|
||||||
var Metas models.Meta
|
var Metas models.Meta
|
||||||
|
|
||||||
if err := json.Unmarshal([]byte(eventItem.Serialized), &Metas); err != nil {
|
if err := json.Unmarshal([]byte(eventItem.Serialized), &Metas); err != nil {
|
||||||
log.Errorf("unable to unmarshall events meta '%s' : %s", eventItem.Serialized, err)
|
log.Errorf("unable to parse events meta '%s' : %s", eventItem.Serialized, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
outputAlert.Events = append(outputAlert.Events, &models.Event{
|
outputAlert.Events = append(outputAlert.Events, &models.Event{
|
||||||
|
|
|
@ -183,7 +183,7 @@ func (c *Controller) UsageMetrics(gctx *gin.Context) {
|
||||||
|
|
||||||
jsonPayload, err := json.Marshal(payload)
|
jsonPayload, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Failed to marshal usage metrics: %s", err)
|
logger.Errorf("Failed to serialize usage metrics: %s", err)
|
||||||
c.HandleDBErrors(gctx, err)
|
c.HandleDBErrors(gctx, err)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -245,7 +245,7 @@ func (p *Papi) Pull() error {
|
||||||
if lastTimestampStr == nil {
|
if lastTimestampStr == nil {
|
||||||
binTime, err := lastTimestamp.MarshalText()
|
binTime, err := lastTimestamp.MarshalText()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to marshal last timestamp: %w", err)
|
return fmt.Errorf("failed to serialize last timestamp: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p.DBClient.SetConfigItem(PapiPullKey, string(binTime)); err != nil {
|
if err := p.DBClient.SetConfigItem(PapiPullKey, string(binTime)); err != nil {
|
||||||
|
@ -255,7 +255,7 @@ func (p *Papi) Pull() error {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := lastTimestamp.UnmarshalText([]byte(*lastTimestampStr)); err != nil {
|
if err := lastTimestamp.UnmarshalText([]byte(*lastTimestampStr)); err != nil {
|
||||||
return fmt.Errorf("failed to unmarshal last timestamp: %w", err)
|
return fmt.Errorf("failed to parse last timestamp: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ func (p *Papi) Pull() error {
|
||||||
|
|
||||||
binTime, err := newTime.MarshalText()
|
binTime, err := newTime.MarshalText()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to marshal last timestamp: %w", err)
|
return fmt.Errorf("failed to serialize last timestamp: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = p.handleEvent(event, false)
|
err = p.handleEvent(event, false)
|
||||||
|
|
|
@ -28,7 +28,7 @@ func LoadAppsecRules(hubInstance *cwhub.Hub) error {
|
||||||
|
|
||||||
err = yaml.UnmarshalStrict(content, &rule)
|
err = yaml.UnmarshalStrict(content, &rule)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("unable to unmarshal file %s : %s", hubAppsecRuleItem.State.LocalPath, err)
|
log.Warnf("unable to parse file %s : %s", hubAppsecRuleItem.State.LocalPath, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ func (o *OnlineApiClientCfg) Load() error {
|
||||||
err = dec.Decode(o.Credentials)
|
err = dec.Decode(o.Credentials)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, io.EOF) {
|
if !errors.Is(err, io.EOF) {
|
||||||
return fmt.Errorf("failed unmarshaling api server credentials configuration file '%s': %w", o.CredentialsFilePath, err)
|
return fmt.Errorf("failed to parse api server credentials configuration file '%s': %w", o.CredentialsFilePath, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ func (l *LocalApiClientCfg) Load() error {
|
||||||
err = dec.Decode(&l.Credentials)
|
err = dec.Decode(&l.Credentials)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, io.EOF) {
|
if !errors.Is(err, io.EOF) {
|
||||||
return fmt.Errorf("failed unmarshaling api client credential configuration file '%s': %w", l.CredentialsFilePath, err)
|
return fmt.Errorf("failed to parse api client credential configuration file '%s': %w", l.CredentialsFilePath, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ func TestLoadOnlineApiClientCfg(t *testing.T) {
|
||||||
CredentialsFilePath: "./testdata/bad_lapi-secrets.yaml",
|
CredentialsFilePath: "./testdata/bad_lapi-secrets.yaml",
|
||||||
},
|
},
|
||||||
expected: &ApiCredentialsCfg{},
|
expected: &ApiCredentialsCfg{},
|
||||||
expectedErr: "failed unmarshaling api server credentials",
|
expectedErr: "failed to parse api server credentials",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "missing field configuration",
|
name: "missing field configuration",
|
||||||
|
|
|
@ -42,5 +42,5 @@ func TestNewCrowdSecConfig(t *testing.T) {
|
||||||
func TestDefaultConfig(t *testing.T) {
|
func TestDefaultConfig(t *testing.T) {
|
||||||
x := NewDefaultConfig()
|
x := NewDefaultConfig()
|
||||||
_, err := yaml.Marshal(x)
|
_, err := yaml.Marshal(x)
|
||||||
require.NoError(t, err, "failed marshaling config: %s", err)
|
require.NoError(t, err, "failed to serialize config: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ func (c *LocalApiServerCfg) LoadConsoleConfig() error {
|
||||||
|
|
||||||
err = yaml.Unmarshal(yamlFile, c.ConsoleConfig)
|
err = yaml.Unmarshal(yamlFile, c.ConsoleConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unmarshaling console config file '%s': %w", c.ConsoleConfigPath, err)
|
return fmt.Errorf("parsing console config file '%s': %w", c.ConsoleConfigPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.ConsoleConfig.ShareCustomScenarios == nil {
|
if c.ConsoleConfig.ShareCustomScenarios == nil {
|
||||||
|
|
|
@ -143,7 +143,7 @@ func (c *CrowdsecServiceCfg) DumpContextConfigFile() error {
|
||||||
// XXX: MakeDirs
|
// XXX: MakeDirs
|
||||||
out, err := yaml.Marshal(c.ContextToSend)
|
out, err := yaml.Marshal(c.ContextToSend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("while marshaling ConsoleConfig (for %s): %w", c.ConsoleContextPath, err)
|
return fmt.Errorf("while serializing ConsoleConfig (for %s): %w", c.ConsoleContextPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.MkdirAll(filepath.Dir(c.ConsoleContextPath), 0700); err != nil {
|
if err = os.MkdirAll(filepath.Dir(c.ConsoleContextPath), 0700); err != nil {
|
||||||
|
|
|
@ -52,7 +52,7 @@ func (c *Config) LoadSimulation() error {
|
||||||
|
|
||||||
if err := dec.Decode(&simCfg); err != nil {
|
if err := dec.Decode(&simCfg); err != nil {
|
||||||
if !errors.Is(err, io.EOF) {
|
if !errors.Is(err, io.EOF) {
|
||||||
return fmt.Errorf("while unmarshaling simulation file '%s': %w", c.ConfigPaths.SimulationFilePath, err)
|
return fmt.Errorf("while parsing simulation file '%s': %w", c.ConfigPaths.SimulationFilePath, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ func TestSimulationLoading(t *testing.T) {
|
||||||
},
|
},
|
||||||
Crowdsec: &CrowdsecServiceCfg{},
|
Crowdsec: &CrowdsecServiceCfg{},
|
||||||
},
|
},
|
||||||
expectedErr: "while unmarshaling simulation file './testdata/config.yaml': yaml: unmarshal errors",
|
expectedErr: "while parsing simulation file './testdata/config.yaml': yaml: unmarshal errors",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "basic bad file content",
|
name: "basic bad file content",
|
||||||
|
@ -71,7 +71,7 @@ func TestSimulationLoading(t *testing.T) {
|
||||||
},
|
},
|
||||||
Crowdsec: &CrowdsecServiceCfg{},
|
Crowdsec: &CrowdsecServiceCfg{},
|
||||||
},
|
},
|
||||||
expectedErr: "while unmarshaling simulation file './testdata/config.yaml': yaml: unmarshal errors",
|
expectedErr: "while parsing simulation file './testdata/config.yaml': yaml: unmarshal errors",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ func (s *PluginSuite) readconfig() PluginConfig {
|
||||||
require.NoError(t, err, "unable to read config file %s", s.pluginConfig)
|
require.NoError(t, err, "unable to read config file %s", s.pluginConfig)
|
||||||
|
|
||||||
err = yaml.Unmarshal(orig, &config)
|
err = yaml.Unmarshal(orig, &config)
|
||||||
require.NoError(t, err, "unable to unmarshal config file")
|
require.NoError(t, err, "unable to parse config file")
|
||||||
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ func (s *PluginSuite) readconfig() PluginConfig {
|
||||||
func (s *PluginSuite) writeconfig(config PluginConfig) {
|
func (s *PluginSuite) writeconfig(config PluginConfig) {
|
||||||
t := s.T()
|
t := s.T()
|
||||||
data, err := yaml.Marshal(&config)
|
data, err := yaml.Marshal(&config)
|
||||||
require.NoError(t, err, "unable to marshal config file")
|
require.NoError(t, err, "unable to serialize config file")
|
||||||
|
|
||||||
err = os.WriteFile(s.pluginConfig, data, 0o644)
|
err = os.WriteFile(s.pluginConfig, data, 0o644)
|
||||||
require.NoError(t, err, "unable to write config file %s", s.pluginConfig)
|
require.NoError(t, err, "unable to write config file %s", s.pluginConfig)
|
||||||
|
|
|
@ -79,7 +79,7 @@ func (h *Hub) parseIndex() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(bidx, &h.items); err != nil {
|
if err := json.Unmarshal(bidx, &h.items); err != nil {
|
||||||
return fmt.Errorf("failed to unmarshal index: %w", err)
|
return fmt.Errorf("failed to parse index: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
h.logger.Debugf("%d item types in hub index", len(ItemTypes))
|
h.logger.Debugf("%d item types in hub index", len(ItemTypes))
|
||||||
|
|
|
@ -210,7 +210,7 @@ func newLocalItem(h *Hub, path string, info *itemFileInfo) (*Item, error) {
|
||||||
|
|
||||||
err = yaml.Unmarshal(itemContent, &itemName)
|
err = yaml.Unmarshal(itemContent, &itemName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal %s: %w", path, err)
|
return nil, fmt.Errorf("failed to parse %s: %w", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if itemName.Name != "" {
|
if itemName.Name != "" {
|
||||||
|
|
|
@ -202,7 +202,7 @@ func (m *Machine) assignValues(columns []string, values []any) error {
|
||||||
return fmt.Errorf("unexpected type %T for field hubstate", values[i])
|
return fmt.Errorf("unexpected type %T for field hubstate", values[i])
|
||||||
} else if value != nil && len(*value) > 0 {
|
} else if value != nil && len(*value) > 0 {
|
||||||
if err := json.Unmarshal(*value, &m.Hubstate); err != nil {
|
if err := json.Unmarshal(*value, &m.Hubstate); err != nil {
|
||||||
return fmt.Errorf("unmarshal field hubstate: %w", err)
|
return fmt.Errorf("parsing field hubstate: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case machine.FieldDatasources:
|
case machine.FieldDatasources:
|
||||||
|
@ -210,7 +210,7 @@ func (m *Machine) assignValues(columns []string, values []any) error {
|
||||||
return fmt.Errorf("unexpected type %T for field datasources", values[i])
|
return fmt.Errorf("unexpected type %T for field datasources", values[i])
|
||||||
} else if value != nil && len(*value) > 0 {
|
} else if value != nil && len(*value) > 0 {
|
||||||
if err := json.Unmarshal(*value, &m.Datasources); err != nil {
|
if err := json.Unmarshal(*value, &m.Datasources); err != nil {
|
||||||
return fmt.Errorf("unmarshal field datasources: %w", err)
|
return fmt.Errorf("parsing field datasources: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -13,8 +13,8 @@ var (
|
||||||
ItemNotFound = errors.New("object not found")
|
ItemNotFound = errors.New("object not found")
|
||||||
ParseTimeFail = errors.New("unable to parse time")
|
ParseTimeFail = errors.New("unable to parse time")
|
||||||
ParseDurationFail = errors.New("unable to parse duration")
|
ParseDurationFail = errors.New("unable to parse duration")
|
||||||
MarshalFail = errors.New("unable to marshal")
|
MarshalFail = errors.New("unable to serialize")
|
||||||
UnmarshalFail = errors.New("unable to unmarshal")
|
UnmarshalFail = errors.New("unable to parse")
|
||||||
BulkError = errors.New("unable to insert bulk")
|
BulkError = errors.New("unable to insert bulk")
|
||||||
ParseType = errors.New("unable to parse type")
|
ParseType = errors.New("unable to parse type")
|
||||||
InvalidIPOrRange = errors.New("invalid ip address / range")
|
InvalidIPOrRange = errors.New("invalid ip address / range")
|
||||||
|
|
|
@ -57,7 +57,7 @@ func (h *HubTest) GetAppsecCoverage() ([]Coverage, error) {
|
||||||
|
|
||||||
err = yaml.Unmarshal(yamlFile, configFileData)
|
err = yaml.Unmarshal(yamlFile, configFileData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unmarshal: %v", err)
|
return nil, fmt.Errorf("parsing: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, appsecRulesFile := range configFileData.AppsecRules {
|
for _, appsecRulesFile := range configFileData.AppsecRules {
|
||||||
|
@ -70,7 +70,7 @@ func (h *HubTest) GetAppsecCoverage() ([]Coverage, error) {
|
||||||
|
|
||||||
err = yaml.Unmarshal(yamlFile, appsecRuleData)
|
err = yaml.Unmarshal(yamlFile, appsecRuleData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unmarshal: %v", err)
|
return nil, fmt.Errorf("parsing: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
appsecRuleName := appsecRuleData.Name
|
appsecRuleName := appsecRuleData.Name
|
||||||
|
|
|
@ -111,7 +111,7 @@ func NewTest(name string, hubTest *HubTest) (*HubTestItem, error) {
|
||||||
|
|
||||||
err = yaml.Unmarshal(yamlFile, configFileData)
|
err = yaml.Unmarshal(yamlFile, configFileData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unmarshal: %w", err)
|
return nil, fmt.Errorf("parsing: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
parserAssertFilePath := filepath.Join(testPath, ParserAssertFileName)
|
parserAssertFilePath := filepath.Join(testPath, ParserAssertFileName)
|
||||||
|
@ -201,7 +201,7 @@ func (t *HubTestItem) InstallHub() error {
|
||||||
|
|
||||||
b, err := yaml.Marshal(n)
|
b, err := yaml.Marshal(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to marshal overrides: %w", err)
|
return fmt.Errorf("unable to serialize overrides: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tgtFilename := fmt.Sprintf("%s/parsers/s00-raw/00_overrides.yaml", t.RuntimePath)
|
tgtFilename := fmt.Sprintf("%s/parsers/s00-raw/00_overrides.yaml", t.RuntimePath)
|
||||||
|
|
|
@ -136,7 +136,7 @@ func testOneBucket(t *testing.T, hub *cwhub.Hub, dir string, tomb *tomb.Tomb) er
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := yaml.UnmarshalStrict(out.Bytes(), &stages); err != nil {
|
if err := yaml.UnmarshalStrict(out.Bytes(), &stages); err != nil {
|
||||||
t.Fatalf("failed unmarshaling %s : %s", stagecfg, err)
|
t.Fatalf("failed to parse %s : %s", stagecfg, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
files := []string{}
|
files := []string{}
|
||||||
|
@ -201,7 +201,7 @@ func testFile(t *testing.T, file string, bs string, holders []BucketFactory, res
|
||||||
var ts time.Time
|
var ts time.Time
|
||||||
|
|
||||||
if err := ts.UnmarshalText([]byte(in.MarshaledTime)); err != nil {
|
if err := ts.UnmarshalText([]byte(in.MarshaledTime)); err != nil {
|
||||||
t.Fatalf("Failed to unmarshal time from input event : %s", err)
|
t.Fatalf("Failed to parse time from input event : %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if latest_ts.IsZero() {
|
if latest_ts.IsZero() {
|
||||||
|
|
|
@ -493,7 +493,7 @@ func LoadBucketsState(file string, buckets *Buckets, bucketFactories []BucketFac
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(body, &state); err != nil {
|
if err := json.Unmarshal(body, &state); err != nil {
|
||||||
return fmt.Errorf("can't unmarshal state file %s: %w", file, err)
|
return fmt.Errorf("can't parse state file %s: %w", file, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range state {
|
for k, v := range state {
|
||||||
|
|
|
@ -132,7 +132,7 @@ func DumpBucketsStateAt(deadline time.Time, outputdir string, buckets *Buckets)
|
||||||
})
|
})
|
||||||
bbuckets, err := json.MarshalIndent(serialized, "", " ")
|
bbuckets, err := json.MarshalIndent(serialized, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to unmarshal buckets: %s", err)
|
return "", fmt.Errorf("failed to parse buckets: %s", err)
|
||||||
}
|
}
|
||||||
size, err := tmpFd.Write(bbuckets)
|
size, err := tmpFd.Write(bbuckets)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -203,7 +203,7 @@ func PourItemToBucket(bucket *Leaky, holder BucketFactory, buckets *Buckets, par
|
||||||
var d time.Time
|
var d time.Time
|
||||||
err = d.UnmarshalText([]byte(parsed.MarshaledTime))
|
err = d.UnmarshalText([]byte(parsed.MarshaledTime))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
holder.logger.Warningf("Failed unmarshaling event time (%s) : %v", parsed.MarshaledTime, err)
|
holder.logger.Warningf("Failed to parse event time (%s) : %v", parsed.MarshaledTime, err)
|
||||||
}
|
}
|
||||||
if d.After(lastTs.Add(bucket.Duration)) {
|
if d.After(lastTs.Add(bucket.Duration)) {
|
||||||
bucket.logger.Tracef("bucket is expired (curr event: %s, bucket deadline: %s), kill", d, lastTs.Add(bucket.Duration))
|
bucket.logger.Tracef("bucket is expired (curr event: %s, bucket deadline: %s), kill", d, lastTs.Add(bucket.Duration))
|
||||||
|
|
|
@ -231,7 +231,7 @@ func EventsFromQueue(queue *types.Queue) []*models.Event {
|
||||||
|
|
||||||
raw, err := evt.Time.MarshalText()
|
raw, err := evt.Time.MarshalText()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warningf("while marshaling time '%s' : %s", evt.Time.String(), err)
|
log.Warningf("while serializing time '%s' : %s", evt.Time.String(), err)
|
||||||
} else {
|
} else {
|
||||||
*ovflwEvent.Timestamp = string(raw)
|
*ovflwEvent.Timestamp = string(raw)
|
||||||
}
|
}
|
||||||
|
@ -286,12 +286,12 @@ func NewAlert(leaky *Leaky, queue *types.Queue) (types.RuntimeAlert, error) {
|
||||||
*/
|
*/
|
||||||
start_at, err := leaky.First_ts.MarshalText()
|
start_at, err := leaky.First_ts.MarshalText()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warningf("failed to marshal start ts %s : %s", leaky.First_ts.String(), err)
|
log.Warningf("failed to serialize start ts %s : %s", leaky.First_ts.String(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_at, err := leaky.Ovflw_ts.MarshalText()
|
stop_at, err := leaky.Ovflw_ts.MarshalText()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warningf("failed to marshal ovflw ts %s : %s", leaky.First_ts.String(), err)
|
log.Warningf("failed to serialize ovflw ts %s : %s", leaky.First_ts.String(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
capacity := int32(leaky.Capacity)
|
capacity := int32(leaky.Capacity)
|
||||||
|
|
|
@ -24,7 +24,7 @@ func TimeMachinePour(l *Leaky, msg types.Event) {
|
||||||
|
|
||||||
err = d.UnmarshalText([]byte(msg.MarshaledTime))
|
err = d.UnmarshalText([]byte(msg.MarshaledTime))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warningf("Failed unmarshaling event time (%s) : %v", msg.MarshaledTime, err)
|
log.Warningf("Failed to parse event time (%s) : %v", msg.MarshaledTime, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ func (t *Trigger) OnBucketPour(b *BucketFactory) func(types.Event, *Leaky) *type
|
||||||
|
|
||||||
err := d.UnmarshalText([]byte(msg.MarshaledTime))
|
err := d.UnmarshalText([]byte(msg.MarshaledTime))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warningf("Failed unmarshaling event time (%s) : %v", msg.MarshaledTime, err)
|
log.Warningf("Failed to parse event time (%s) : %v", msg.MarshaledTime, err)
|
||||||
|
|
||||||
d = now
|
d = now
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ func parseDateWithFormat(date, format string) (string, time.Time) {
|
||||||
}
|
}
|
||||||
retstr, err := t.MarshalText()
|
retstr, err := t.MarshalText()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warningf("Failed marshaling '%v'", t)
|
log.Warningf("Failed to serialize '%v'", t)
|
||||||
return "", time.Time{}
|
return "", time.Time{}
|
||||||
}
|
}
|
||||||
return string(retstr), t
|
return string(retstr), t
|
||||||
|
@ -98,7 +98,7 @@ func ParseDate(in string, p *types.Event, plog *log.Entry) (map[string]string, e
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
retstr, err := now.MarshalText()
|
retstr, err := now.MarshalText()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
plog.Warning("Failed marshaling current time")
|
plog.Warning("Failed to serialize current time")
|
||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
ret["MarshaledTime"] = string(retstr)
|
ret["MarshaledTime"] = string(retstr)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
func unmarshalJSON(field string, p *types.Event, plog *log.Entry) (map[string]string, error) {
|
func unmarshalJSON(field string, p *types.Event, plog *log.Entry) (map[string]string, error) {
|
||||||
err := json.Unmarshal([]byte(p.Line.Raw), &p.Unmarshaled)
|
err := json.Unmarshal([]byte(p.Line.Raw), &p.Unmarshaled)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
plog.Errorf("could not unmarshal JSON: %s", err)
|
plog.Errorf("could not parse JSON: %s", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
plog.Tracef("unmarshaled JSON: %+v", p.Unmarshaled)
|
plog.Tracef("unmarshaled JSON: %+v", p.Unmarshaled)
|
||||||
|
|
|
@ -132,7 +132,7 @@ func testOneParser(pctx *UnixParserCtx, ectx EnricherCtx, dir string, b *testing
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = yaml.UnmarshalStrict(out.Bytes(), &parser_configs); err != nil {
|
if err = yaml.UnmarshalStrict(out.Bytes(), &parser_configs); err != nil {
|
||||||
return fmt.Errorf("failed unmarshaling %s: %w", parser_cfg_file, err)
|
return fmt.Errorf("failed to parse %s: %w", parser_cfg_file, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pnodes, err = LoadStages(parser_configs, pctx, ectx)
|
pnodes, err = LoadStages(parser_configs, pctx, ectx)
|
||||||
|
|
|
@ -545,7 +545,7 @@ func Detect(detectReader io.Reader, opts DetectOptions) (Setup, error) {
|
||||||
// }
|
// }
|
||||||
// err = yaml.Unmarshal(svc.AcquisYAML, svc.DataSource)
|
// err = yaml.Unmarshal(svc.AcquisYAML, svc.DataSource)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// return Setup{}, fmt.Errorf("while unmarshaling datasource for service %s: %w", name, err)
|
// return Setup{}, fmt.Errorf("while parsing datasource for service %s: %w", name, err)
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ func decodeSetup(input []byte, fancyErrors bool) (Setup, error) {
|
||||||
dec2.KnownFields(true)
|
dec2.KnownFields(true)
|
||||||
|
|
||||||
if err := dec2.Decode(&ret); err != nil {
|
if err := dec2.Decode(&ret); err != nil {
|
||||||
return ret, fmt.Errorf("while unmarshaling setup file: %w", err)
|
return ret, fmt.Errorf("while parsing setup file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret, nil
|
return ret, nil
|
||||||
|
|
|
@ -819,6 +819,6 @@ update-notifier-motd.timer enabled enabled
|
||||||
setup:
|
setup:
|
||||||
alsdk al; sdf
|
alsdk al; sdf
|
||||||
EOT
|
EOT
|
||||||
assert_output "while unmarshaling setup file: yaml: line 2: could not find expected ':'"
|
assert_output "while parsing setup file: yaml: line 2: could not find expected ':'"
|
||||||
assert_stderr --partial "invalid setup file"
|
assert_stderr --partial "invalid setup file"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue