forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds configuration mapping. (envoyproxy#79)
Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>
- Loading branch information
Showing
7 changed files
with
83 additions
and
12 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
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,58 @@ | ||
// Copyright The OWASP Coraza contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
"strings" | ||
) | ||
|
||
type rulesFS struct { | ||
fs fs.FS | ||
filesMapping map[string]string | ||
dirsMapping map[string]string | ||
} | ||
|
||
func (r rulesFS) Open(name string) (fs.File, error) { | ||
return r.fs.Open(r.mapPath(name)) | ||
} | ||
|
||
func (r rulesFS) ReadDir(name string) ([]fs.DirEntry, error) { | ||
for a, dst := range r.dirsMapping { | ||
if a == name { | ||
return fs.ReadDir(r.fs, dst) | ||
} | ||
|
||
prefix := a + "/" | ||
if strings.HasPrefix(name, prefix) { | ||
return fs.ReadDir(r.fs, fmt.Sprintf("%s/%s", dst, name[len(prefix):])) | ||
} | ||
} | ||
return fs.ReadDir(r.fs, name) | ||
} | ||
|
||
func (r rulesFS) ReadFile(name string) ([]byte, error) { | ||
return fs.ReadFile(r.fs, r.mapPath(name)) | ||
} | ||
|
||
func (r rulesFS) mapPath(p string) string { | ||
if strings.IndexByte(p, '/') != -1 { | ||
// is not in root, hence we can do dir mapping | ||
for a, dst := range r.dirsMapping { | ||
prefix := a + "/" | ||
if strings.HasPrefix(p, prefix) { | ||
return fmt.Sprintf("%s/%s", dst, p[len(prefix):]) | ||
} | ||
} | ||
} | ||
|
||
for a, dst := range r.filesMapping { | ||
if a == p { | ||
return dst | ||
} | ||
} | ||
|
||
return p | ||
} |
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