Skip to content

Commit

Permalink
allow regex replace
Browse files Browse the repository at this point in the history
  • Loading branch information
chdxD1 committed Sep 20, 2024
1 parent c8f1de6 commit 73fdf33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ type VRFConfig struct {
}

type Replacement struct {
Old string `yaml:"old"`
New string `yaml:"new"`
Old string `yaml:"old"`
New string `yaml:"new"`
Regex bool `yaml:"regex"`
}

func LoadConfig() (*Config, error) {
Expand Down
7 changes: 6 additions & 1 deletion pkg/frr/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ func fixRouteTargetReload(frrConfig []byte) []byte {
// fixCfgReplacements replaces placeholders in the configuration with the actual values.
func fixCfgReplacements(frrConfig []byte, replacements []config.Replacement) []byte {
for _, replacement := range replacements {
frrConfig = bytes.ReplaceAll(frrConfig, []byte(replacement.Old), []byte(replacement.New))
if !replacement.Regex {
frrConfig = bytes.ReplaceAll(frrConfig, []byte(replacement.Old), []byte(replacement.New))
} else {
re := regexp.MustCompile(replacement.Old)
frrConfig = re.ReplaceAll(frrConfig, []byte(replacement.New))
}
}
return frrConfig
}

0 comments on commit 73fdf33

Please sign in to comment.