-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
60 lines (50 loc) · 1.65 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
)
type AppConfig struct {
Honeypots []HoneypotConfig `yaml:"honeypots"`
}
func LoadConfigurations(configPath string) (*AppConfig, error) {
logInfo("Loading configuration from YAML file: " + configPath)
configFile, err := ioutil.ReadFile(configPath)
if err != nil {
logError("Failed to read configuration file: " + err.Error())
return nil, err
}
var appConfig AppConfig
err = yaml.Unmarshal(configFile, &appConfig)
if err != nil {
logError("Failed to unmarshal YAML configuration: " + err.Error())
return nil, err
}
logInfo(fmt.Sprintf("Found %d configurations in YAML file.", len(appConfig.Honeypots)))
for _, config := range appConfig.Honeypots {
logInfo("Processing configuration for: " + config.Name)
if err := validateHoneypotConfig(config); err != nil {
logError("Validation failed for " + config.Name + ": " + err.Error())
continue
}
existingConfig, err := SelectHoneypotConfig(config.ID)
if err != nil || existingConfig == nil {
logInfo("Inserting new configuration for: " + config.Name)
err = InsertHoneypotConfig(&config)
if err != nil {
logError("Failed to insert configuration for " + config.Name + ": " + err.Error())
continue
}
logSuccess("Successfully inserted configuration for: " + config.Name)
} else {
logInfo("Updating existing configuration for: " + config.Name)
err = UpdateHoneypotConfig(&config)
if err != nil {
logError("Failed to update configuration for " + config.Name + ": " + err.Error())
continue
}
logSuccess("Successfully updated configuration for: " + config.Name)
}
}
return &appConfig, nil
}