Skip to content

Commit

Permalink
Add config version/hash, log
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanohoro committed Nov 3, 2023
1 parent 7f5a44e commit 178e13f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions configs/go/fileshot/fileshot.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version:
2023-10-03
client: 'go-fileshot-default'
conn:
server: 'localhost:57314'
Expand Down
24 changes: 20 additions & 4 deletions src/go/cmd/strelka-fileshot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type matchRich struct {

func main() {
// Declare flags
confPath := flag.String("c", "/etc/strelka/fileshot.yaml", "Path to fileshot configuration file.")
hashPath := flag.String("e", "", "Path to MD5 exclusions list.")
configPath := flag.String("c", "/etc/strelka/fileshot.yaml", "Path to fileshot configuration file.")
hashPath := flag.String("e", "", "Path to hash exclusions list.")
verbose := flag.Bool("v", false, "Enables additional error logging.")
cpuProf := flag.Bool("cpu", false, "Enables cpu profiling.")
heapProf := flag.Bool("heap", false, "Enables heap profiling.")
Expand All @@ -61,11 +61,21 @@ func main() {
}

// Read configuration file
confData, err := os.ReadFile(*confPath)
confData, err := os.ReadFile(*configPath)
if err != nil {
log.Fatalf("failed to read config file %s: %v", *confPath, err)
log.Fatalf("failed to read config file %s: %v", *configPath, err)
}

// Try to recover absolute config file path
absConfigPath, _ := filepath.Abs(*configPath)
if absConfigPath == "" {
absConfigPath = *configPath
}

// Create a new config hash
configHasher := md5.New()
configHasher.Write([]byte(confData))

// Unmarshal configuration data into struct
var conf structs.FileShot
err = yaml.Unmarshal(confData, &conf)
Expand Down Expand Up @@ -105,6 +115,12 @@ func main() {

}

if conf.Version != "" {
log.Printf("Loaded config file v%s %s %s", conf.Version, fmt.Sprintf("%x", configHasher.Sum(nil)), absConfigPath)
} else {
log.Printf("Loaded config file %s %s", fmt.Sprintf("%x", configHasher.Sum(nil)), absConfigPath)
}

// Create a slice to hold the lines of the file
hashes := make([]string, 0)

Expand Down
1 change: 1 addition & 0 deletions src/go/pkg/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type ConfResponse struct {

// defines structures of configuration files
type FileShot struct {
Version string // optional
Client string // optional
Conn ConfConn // required
Throughput ConfThroughput // required
Expand Down

0 comments on commit 178e13f

Please sign in to comment.