Skip to content

Commit

Permalink
Adds maxDiffEntries and maxDatabaseEntires flags to wrserver and …
Browse files Browse the repository at this point in the history
…wrlookup. The default value of 0 means that both will be ignored unless set.

PiperOrigin-RevId: 640202575
  • Loading branch information
rvilgalys authored and copybara-github committed Jun 4, 2024
1 parent 658f85c commit cf2e944
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
26 changes: 15 additions & 11 deletions cmd/wrlookup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ import (
)

var (
apiKeyFlag = flag.String("apikey", "", "specify your Web Risk API key")
databaseFlag = flag.String("db", "", "path to the Web Risk database. By default persistent storage is disabled (not recommended).")
serverURLFlag = flag.String("server", webrisk.DefaultServerURL, "Web Risk API server address.")
proxyFlag = flag.String("proxy", "", "proxy to use to connect to the HTTP server")
threatTypesFlag = flag.String("threatTypes", "ALL", "threat types to check against")
apiKeyFlag = flag.String("apikey", "", "specify your Web Risk API key")
databaseFlag = flag.String("db", "", "path to the Web Risk database. By default persistent storage is disabled (not recommended).")
serverURLFlag = flag.String("server", webrisk.DefaultServerURL, "Web Risk API server address.")
proxyFlag = flag.String("proxy", "", "proxy to use to connect to the HTTP server")
threatTypesFlag = flag.String("threatTypes", "ALL", "threat types to check against")
maxDiffEntriesFlag = flag.Int("maxDiffEntries", 0, "maximum number of diff entries to return from a ComputeThreatListDiff request")
maxDatabaseEntriesFlag = flag.Int("maxDatabaseEntries", 0, "maximum number of database entries to be stored in the local database")
)

const usage = `wrlookup: command-line tool to lookup URLs with Web Risk.
Expand Down Expand Up @@ -81,12 +83,14 @@ func main() {
os.Exit(codeInvalid)
}
sb, err := webrisk.NewUpdateClient(webrisk.Config{
APIKey: *apiKeyFlag,
DBPath: *databaseFlag,
Logger: os.Stderr,
ServerURL: *serverURLFlag,
ProxyURL: *proxyFlag,
ThreatListArg: *threatTypesFlag,
APIKey: *apiKeyFlag,
DBPath: *databaseFlag,
Logger: os.Stderr,
ServerURL: *serverURLFlag,
ProxyURL: *proxyFlag,
ThreatListArg: *threatTypesFlag,
MaxDiffEntries: int32(*maxDiffEntriesFlag),
MaxDatabaseEntries: int32(*maxDatabaseEntriesFlag),
})
if err != nil {
fmt.Fprintln(os.Stderr, "Unable to initialize Web Risk client: ", err)
Expand Down
26 changes: 15 additions & 11 deletions cmd/wrserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,13 @@ const (
)

var (
apiKeyFlag = flag.String("apikey", os.Getenv("APIKEY"), "specify your Web Risk API key")
srvAddrFlag = flag.String("srvaddr", "0.0.0.0:8080", "TCP network address the HTTP server should use")
proxyFlag = flag.String("proxy", "", "proxy to use to connect to the HTTP server")
databaseFlag = flag.String("db", "", "path to the Web Risk database.")
threatTypesFlag = flag.String("threatTypes", "ALL", "threat types to check against")
apiKeyFlag = flag.String("apikey", os.Getenv("APIKEY"), "specify your Web Risk API key")
srvAddrFlag = flag.String("srvaddr", "0.0.0.0:8080", "TCP network address the HTTP server should use")
proxyFlag = flag.String("proxy", "", "proxy to use to connect to the HTTP server")
databaseFlag = flag.String("db", "", "path to the Web Risk database.")
threatTypesFlag = flag.String("threatTypes", "ALL", "threat types to check against")
maxDiffEntriesFlag = flag.Int("maxDiffEntries", 0, "maximum number of diff entries to return from a ComputeThreatListDiff request")
maxDatabaseEntriesFlag = flag.Int("maxDatabaseEntries", 0, "maximum number of database entries to be stored in the local database")
)

var threatTemplate = map[webrisk.ThreatType]string{
Expand Down Expand Up @@ -477,7 +479,7 @@ func runServer(srv *http.Server) (chan os.Signal, <-chan struct{}) {
// start listening for interrupts
exit := make(chan os.Signal, 1)
down := make(chan struct{})

// runs shutdown and cleanup on an exit signal
go func() {
<-exit
Expand Down Expand Up @@ -518,11 +520,13 @@ func main() {
os.Exit(1)
}
conf := webrisk.Config{
APIKey: *apiKeyFlag,
ProxyURL: *proxyFlag,
DBPath: *databaseFlag,
ThreatListArg: *threatTypesFlag,
Logger: os.Stderr,
APIKey: *apiKeyFlag,
ProxyURL: *proxyFlag,
DBPath: *databaseFlag,
ThreatListArg: *threatTypesFlag,
MaxDiffEntries: int32(*maxDiffEntriesFlag),
MaxDatabaseEntries: int32(*maxDatabaseEntriesFlag),
Logger: os.Stderr,
}
wr, err := webrisk.NewUpdateClient(conf)
if err != nil {
Expand Down

0 comments on commit cf2e944

Please sign in to comment.