Commit ea21cd21 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Switch from YAML to JSON configuration and rule files

- Updated config loading in `cmd/app/config.go` to use JSON instead of YAML
- Modified `internal/service/waf.go` to read WAF rules from JSON file
- Removed YAML library imports and replaced with JSON unmarshaling
- Updated file extensions from `.yaml` to `.json` in file reading logic
parent 59201340
package app package app
import ( import (
"encoding/json"
"os" "os"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"gopkg.in/yaml.v2"
) )
const ( const (
...@@ -41,7 +41,7 @@ type RegionConfig struct { ...@@ -41,7 +41,7 @@ type RegionConfig struct {
} }
func LoadConfig() *Config { func LoadConfig() *Config {
configFile := "config/config.yaml" configFile := "config/config.json"
if envFile := os.Getenv("CONFIG_FILE"); envFile != "" { if envFile := os.Getenv("CONFIG_FILE"); envFile != "" {
configFile = envFile configFile = envFile
} }
...@@ -53,7 +53,11 @@ func LoadConfig() *Config { ...@@ -53,7 +53,11 @@ func LoadConfig() *Config {
} }
var config Config var config Config
if err := yaml.Unmarshal(data, &config); err != nil { // if err := yaml.Unmarshal(data, &config); err != nil {
// log.Err(err).Msg("Failed to parse config file")
// return nil
// }
if err := json.Unmarshal(data, &config); err != nil {
log.Err(err).Msg("Failed to parse config file") log.Err(err).Msg("Failed to parse config file")
return nil return nil
} }
......
...@@ -17,7 +17,6 @@ import ( ...@@ -17,7 +17,6 @@ import (
"gitlab.com/tensorsecurity-rd/waf-console/internal/model" "gitlab.com/tensorsecurity-rd/waf-console/internal/model"
"gitlab.com/tensorsecurity-rd/waf-console/internal/utils" "gitlab.com/tensorsecurity-rd/waf-console/internal/utils"
"gitlab.com/tensorsecurity-rd/waf-console/pkg/apis/waf.security.io/v1alpha1" "gitlab.com/tensorsecurity-rd/waf-console/pkg/apis/waf.security.io/v1alpha1"
"gopkg.in/yaml.v3"
"gorm.io/gorm" "gorm.io/gorm"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
...@@ -349,12 +348,13 @@ func (s *wafService) GetRule(ctx context.Context, ruleID int) (*WafRule, error) ...@@ -349,12 +348,13 @@ func (s *wafService) GetRule(ctx context.Context, ruleID int) (*WafRule, error)
func (s *wafService) SaveRuleCategoryToDB(ctx context.Context) error { func (s *wafService) SaveRuleCategoryToDB(ctx context.Context) error {
var categories []WafRuleCategory var categories []WafRuleCategory
yamlFile, err := os.ReadFile("rules/waf-rules.yaml") jsonFile, err := os.ReadFile("rules/waf-rules.json")
if err != nil { if err != nil {
return fmt.Errorf("error reading yaml file: %v", err) return fmt.Errorf("error reading yaml file: %v", err)
} }
err = yaml.Unmarshal(yamlFile, &categories) // err = yaml.Unmarshal(yamlFile, &categories)
err = json.Unmarshal(jsonFile, &categories)
if err != nil { if err != nil {
return fmt.Errorf("error unmarshaling yaml: %v", err) return fmt.Errorf("error unmarshaling yaml: %v", err)
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment