-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lint revive(deep-exit): refactor cmd/crowdsec
- Loading branch information
Showing
4 changed files
with
68 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"gopkg.in/yaml.v3" | ||
|
||
leaky "github.com/crowdsecurity/crowdsec/pkg/leakybucket" | ||
"github.com/crowdsecurity/crowdsec/pkg/parser" | ||
) | ||
|
||
func dumpAllStates() error { | ||
log.Debugf("Dumping parser+bucket states to %s", parser.DumpFolder) | ||
|
||
if err := dumpState( | ||
filepath.Join(parser.DumpFolder, "parser-dump.yaml"), | ||
parser.StageParseCache, | ||
); err != nil { | ||
return fmt.Errorf("while dumping parser state: %w", err) | ||
} | ||
|
||
if err := dumpState( | ||
filepath.Join(parser.DumpFolder, "bucket-dump.yaml"), | ||
bucketOverflows, | ||
); err != nil { | ||
return fmt.Errorf("while dumping bucket overflow state: %w", err) | ||
|
||
} | ||
|
||
if err := dumpState( | ||
filepath.Join(parser.DumpFolder, "bucketpour-dump.yaml"), | ||
leaky.BucketPourCache, | ||
); err != nil { | ||
return fmt.Errorf("while dumping bucket pour state: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func dumpState(destPath string, obj any) error { | ||
dir := filepath.Dir(destPath) | ||
|
||
err := os.MkdirAll(dir, 0o755) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
out, err := yaml.Marshal(obj) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return os.WriteFile(destPath, out, 0o666) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters