This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (70 loc) · 3.01 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"os"
"strings"
"github.com/achilleasa/mongolite/cmd"
"github.com/achilleasa/mongolite/protocol"
"gopkg.in/urfave/cli.v2"
)
func main() {
app := &cli.App{
Name: "mongolite",
Usage: "An experimental proxy that speaks the mongodb wire protocol and uses sqlite as a backend",
Flags: []cli.Flag{
&cli.StringFlag{Name: "listen-address", Value: ":37017", Usage: "the address to listen for incoming client connections"},
&cli.StringFlag{Name: "listen-tls-file", Value: "", Usage: "path to a file with a TLS cert/pk for the server if TLS support should be enabled"},
&cli.StringFlag{Name: "listen-tls-file-password", Value: "", Usage: "password for decrypting TLS cert/pk data"},
},
Commands: []*cli.Command{
{
Name: "serve",
Usage: "Emulate a mongo server using a configurable backend",
Flags: []cli.Flag{
&cli.StringFlag{Name: "backend", Value: "dummy", Usage: "the type of backend to use. Ssupported backends: dummy"},
},
Action: cmd.EmulateServer,
Category: "tools",
},
{
Name: "tools",
Usage: "Helper tools",
Subcommands: []*cli.Command{
{
Name: "proxy",
Usage: "Proxy (and optionaly record) incoming connections to a remote mongod instance",
Flags: []cli.Flag{
&cli.StringFlag{Name: "remote-address", Value: "127.0.0.1:27017", Usage: "the address of a remote mongod instance to proxy connections to"},
&cli.StringFlag{Name: "remote-tls-file", Value: "", Usage: "path to a file with a TLS cert/pk for the remote mongod if TLS support should be enabled"},
&cli.StringFlag{Name: "remote-tls-file-password", Value: "", Usage: "password for decrypting TLS cert/pk data"},
&cli.BoolFlag{Name: "remote-tls-no-verify", Usage: "skip TLS verification when connecting to remote mongod"},
&cli.StringFlag{Name: "rec-requests-to", Value: "", Usage: "a filename for recroding client requests (only if specified)"},
&cli.StringFlag{Name: "rec-responses-to", Value: "", Usage: "a filename for recording server responses (only if specified)"},
},
Action: cmd.ProxyToRemote,
Category: "tools",
},
{
Name: "analyze",
ArgsUsage: "FILE",
Usage: "Decode and analyze recorded requests",
Description: `
Decode and analyze recorded mongo client request stream from FILE. If a value
of '-' is provided for the FILE argument, the tool will read the request stream
from STDIN`,
Flags: []cli.Flag{
&cli.IntFlag{Name: "offset", Value: 0, Usage: "number of request entries to skip"},
&cli.IntFlag{Name: "limit", Value: 0, Usage: "number of request entries to display; if 0 all entries will be displayed"},
&cli.StringSliceFlag{Name: "filter", Usage: "only show requests of `TYPE`. Supported types: " + strings.Join(protocol.AllRequestTypeNames(), ", ")},
},
Action: cmd.AnalyzeStream,
Category: "tools",
},
},
},
},
Before: cmd.SetupLogger,
}
if err := app.Run(os.Args); err != nil {
cmd.ExitErrorHandler(err)
}
}