work around mongo database uri parsing
This commit is contained in:
parent
908ac5c52a
commit
20d867bfcb
@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path"
|
||||
@ -61,7 +62,7 @@ var App = &cli.App{
|
||||
// &cli.BoolFlag{Name: "parse-json"}, //TODO:
|
||||
&cli.StringFlag{Category: "k8s metadata", Name: "pod-namespace", EnvVars: []string{"KUBE_POD_NAMESPACE"}}, // TODO:
|
||||
&cli.StringFlag{Category: "k8s metadata", Name: "node-name", EnvVars: []string{"KUBE_NODE_NAME"}, Required: true},
|
||||
&cli.StringFlag{Category: "secrets", Name: "mongo-uri", EnvVars: []string{"MONGO_URI"}, Usage: "mongodb://foo:bar@host:27017", Required: true},
|
||||
&cli.StringFlag{Category: "secrets", Name: "mongo-uri", EnvVars: []string{"MONGO_URI"}, Usage: "mongodb://foo:bar@host:27017/database", Required: true},
|
||||
},
|
||||
|
||||
Action: func(ctx *cli.Context) error {
|
||||
@ -111,7 +112,15 @@ var App = &cli.App{
|
||||
l.Fatal("connecting to mongo", zap.String("uri", dbOpt.GetURI()), zap.Error(err))
|
||||
}
|
||||
|
||||
state.db = dbClient.Database(dbOpt.Auth.AuthSource).Collection("logs")
|
||||
uriParsed, err := url.ParseRequestURI(ctx.String("mongo-uri"))
|
||||
if err != nil {
|
||||
l.Fatal("parsing URI for mongo database name", zap.Error(err))
|
||||
}
|
||||
if uriParsed.Path == "" {
|
||||
l.Fatal("mongo database name must be set in mongo URI")
|
||||
}
|
||||
|
||||
state.db = dbClient.Database(uriParsed.Path).Collection("logs")
|
||||
|
||||
state.hostInfo, err = getHostInfo(ctx.String("node-name"))
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user