Skip to content

Commit e1142c1

Browse files
committed
Add nohint plugin
1 parent c288aec commit e1142c1

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

pkg/mongoproxy/plugins/all/all.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
_ "github.com/wish/mongoproxy/pkg/mongoproxy/plugins/insort"
99
_ "github.com/wish/mongoproxy/pkg/mongoproxy/plugins/limits"
1010
_ "github.com/wish/mongoproxy/pkg/mongoproxy/plugins/mongo"
11+
_ "github.com/wish/mongoproxy/pkg/mongoproxy/plugins/nohint"
1112
_ "github.com/wish/mongoproxy/pkg/mongoproxy/plugins/opentracing"
1213
_ "github.com/wish/mongoproxy/pkg/mongoproxy/plugins/schema"
1314
_ "github.com/wish/mongoproxy/pkg/mongoproxy/plugins/slowlog"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# nohint
2+
3+
This plugin simply removes all hints from incoming queries
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package nohint
2+
3+
import (
4+
"context"
5+
6+
"go.mongodb.org/mongo-driver/bson"
7+
8+
"github.com/wish/mongoproxy/pkg/command"
9+
"github.com/wish/mongoproxy/pkg/mongoproxy/plugins"
10+
)
11+
12+
const (
13+
Name = "nohint"
14+
)
15+
16+
func init() {
17+
plugins.Register(func() plugins.Plugin {
18+
return &NohintPlugin{}
19+
})
20+
}
21+
22+
// This is a plugin that simply strips hints out
23+
type NohintPlugin struct {
24+
}
25+
26+
func (p *NohintPlugin) Name() string { return Name }
27+
28+
// Configure configures this plugin with the given configuration object. Returns
29+
// an error if the configuration is invalid for the plugin.
30+
func (p *NohintPlugin) Configure(d bson.D) error {
31+
return nil
32+
}
33+
34+
// Process is the function executed when a message is called in the pipeline.
35+
func (p *NohintPlugin) Process(ctx context.Context, r *plugins.Request, next plugins.PipelineFunc) (bson.D, error) {
36+
switch cmd := r.Command.(type) {
37+
38+
case *command.Aggregate:
39+
cmd.Hint = nil
40+
41+
case *command.Count:
42+
cmd.Hint = nil
43+
44+
case *command.Delete:
45+
cmd.Hint = nil
46+
47+
case *command.Find:
48+
cmd.Hint = nil
49+
50+
case *command.Update:
51+
cmd.Hint = nil
52+
}
53+
return next(ctx, r)
54+
}

0 commit comments

Comments
 (0)