Skip to content

Commit

Permalink
Fix query to path conversion in decision logger
Browse files Browse the repository at this point in the history
The decision logger was using strings.TrimLeft when it should have been
using strings.TrimPrefix. As a result, the prefix was not being trimmed
correctly--leading characters in the cutset "data." were being removed.

Fixes open-policy-agent#783

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
  • Loading branch information
tsandall committed Jun 13, 2018
1 parent 38106f9 commit 49b8276
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/logs/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (p *Plugin) Log(ctx context.Context, decision *server.Info) {

var buf bytes.Buffer

path := strings.Replace(strings.TrimLeft(decision.Query, "data."), ".", "/", -1)
path := strings.Replace(strings.TrimPrefix(decision.Query, "data."), ".", "/", -1)

event := EventV1{
Labels: p.manager.Labels,
Expand Down
4 changes: 2 additions & 2 deletions plugins/logs/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestPluginStart(t *testing.T) {
fixture.plugin.Log(ctx, &server.Info{
Revision: "a",
DecisionID: fmt.Sprint(i),
Query: "data.foo.bar",
Query: "data.tda.bar",
Input: map[string]interface{}{"method": "GET"},
Results: &result,
RemoteAddr: "test",
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestPluginStart(t *testing.T) {
},
Revision: "a",
DecisionID: "153",
Path: "foo/bar",
Path: "tda/bar",
Input: &expInput,
Result: &result,
RequestedBy: "test",
Expand Down

0 comments on commit 49b8276

Please sign in to comment.