-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dave Shanley <dave@quobix.com>
- Loading branch information
1 parent
2bf0319
commit 51d877b
Showing
4 changed files
with
154 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2023 Princess B33f Heavy Industries / Dave Shanley | ||
// SPDX-License-Identifier: MIT | ||
|
||
package config | ||
|
||
import ( | ||
"github.com/pb33f/wiretap/shared" | ||
) | ||
|
||
func FindPath(path string, configuration *shared.WiretapConfiguration) []*shared.WiretapPathConfig { | ||
var foundConfigurations []*shared.WiretapPathConfig | ||
for key := range configuration.CompiledPaths { | ||
if configuration.CompiledPaths[key].CompiledKey.Match(path) { | ||
foundConfigurations = append(foundConfigurations, configuration.CompiledPaths[key].PathConfig) | ||
} | ||
} | ||
return foundConfigurations | ||
} |
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,51 @@ | ||
// Copyright 2023 Princess B33f Heavy Industries / Dave Shanley | ||
// SPDX-License-Identifier: MIT | ||
|
||
package config | ||
|
||
import ( | ||
"github.com/mitchellh/mapstructure" | ||
"github.com/pb33f/wiretap/shared" | ||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/assert" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestFindPath(t *testing.T) { | ||
|
||
config := ` | ||
paths: | ||
/pb33f/test/**: | ||
target: / | ||
secure: false | ||
pathRewrite: | ||
'^/pb33f/test/': ''` | ||
|
||
viper.SetConfigType("yaml") | ||
verr := viper.ReadConfig(strings.NewReader(config)) | ||
assert.NoError(t, verr) | ||
|
||
paths := viper.Get("paths") | ||
var pc map[string]*shared.WiretapPathConfig | ||
|
||
derr := mapstructure.Decode(paths, &pc) | ||
assert.NoError(t, derr) | ||
|
||
wcConfig := &shared.WiretapConfiguration{ | ||
PathConfigurations: pc, | ||
} | ||
|
||
// compile paths | ||
wcConfig.CompilePaths() | ||
|
||
res := FindPath("/pb33f/test/123", wcConfig) | ||
assert.Len(t, res, 1) | ||
|
||
res = FindPath("/pb33f/test/123/sing/song", wcConfig) | ||
assert.Len(t, res, 1) | ||
|
||
res = FindPath("/pb33f/no-match/wrong", wcConfig) | ||
assert.Len(t, res, 0) | ||
|
||
} |
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