Skip to content
Snippets Groups Projects
Commit 03dc4e63 authored by Ed's avatar Ed Committed by Cyril Tovena
Browse files

Parse the addr into a URL so we can extract the Host name for use in the TLSConfig (#778)

parent f74f2c82
No related branches found
No related tags found
No related merge requests found
...@@ -54,7 +54,8 @@ func listLabelValues(name string) (*logproto.LabelResponse, error) { ...@@ -54,7 +54,8 @@ func listLabelValues(name string) (*logproto.LabelResponse, error) {
} }
func doRequest(path string, out interface{}) error { func doRequest(path string, out interface{}) error {
url := *addr + path addrURL.Path = path
url := addrURL.String()
if !*quiet { if !*quiet {
log.Print(url) log.Print(url)
} }
...@@ -71,7 +72,7 @@ func doRequest(path string, out interface{}) error { ...@@ -71,7 +72,7 @@ func doRequest(path string, out interface{}) error {
CAFile: *tlsCACertPath, CAFile: *tlsCACertPath,
CertFile: *tlsClientCertPath, CertFile: *tlsClientCertPath,
KeyFile: *tlsClientCertKeyPath, KeyFile: *tlsClientCertKeyPath,
ServerName: url, ServerName: addrURL.Host,
InsecureSkipVerify: *tlsSkipVerify, InsecureSkipVerify: *tlsSkipVerify,
}, },
} }
...@@ -110,14 +111,15 @@ func wsConnect(path string) (*websocket.Conn, error) { ...@@ -110,14 +111,15 @@ func wsConnect(path string) (*websocket.Conn, error) {
CAFile: *tlsCACertPath, CAFile: *tlsCACertPath,
CertFile: *tlsClientCertPath, CertFile: *tlsClientCertPath,
KeyFile: *tlsClientCertKeyPath, KeyFile: *tlsClientCertKeyPath,
ServerName: *addr, ServerName: addrURL.Host,
InsecureSkipVerify: *tlsSkipVerify, InsecureSkipVerify: *tlsSkipVerify,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
} }
url := *addr + path addrURL.Path = path
url := addrURL.String()
if strings.HasPrefix(url, "https") { if strings.HasPrefix(url, "https") {
url = strings.Replace(url, "https", "wss", 1) url = strings.Replace(url, "https", "wss", 1)
} else if strings.HasPrefix(url, "http") { } else if strings.HasPrefix(url, "http") {
......
...@@ -2,9 +2,10 @@ package main ...@@ -2,9 +2,10 @@ package main
import ( import (
"log" "log"
"net/url"
"os" "os"
kingpin "gopkg.in/alecthomas/kingpin.v2" "gopkg.in/alecthomas/kingpin.v2"
) )
var ( var (
...@@ -12,7 +13,9 @@ var ( ...@@ -12,7 +13,9 @@ var (
quiet = app.Flag("quiet", "suppress everything but log lines").Default("false").Short('q').Bool() quiet = app.Flag("quiet", "suppress everything but log lines").Default("false").Short('q').Bool()
outputMode = app.Flag("output", "specify output mode [default, raw, jsonl]").Default("default").Short('o').Enum("default", "raw", "jsonl") outputMode = app.Flag("output", "specify output mode [default, raw, jsonl]").Default("default").Short('o').Enum("default", "raw", "jsonl")
addr = app.Flag("addr", "Server address.").Default("https://logs-us-west1.grafana.net").Envar("GRAFANA_ADDR").String() addr = app.Flag("addr", "Server address.").Default("https://logs-us-west1.grafana.net").Envar("GRAFANA_ADDR").String()
addrURL url.URL
username = app.Flag("username", "Username for HTTP basic auth.").Default("").Envar("GRAFANA_USERNAME").String() username = app.Flag("username", "Username for HTTP basic auth.").Default("").Envar("GRAFANA_USERNAME").String()
password = app.Flag("password", "Password for HTTP basic auth.").Default("").Envar("GRAFANA_PASSWORD").String() password = app.Flag("password", "Password for HTTP basic auth.").Default("").Envar("GRAFANA_PASSWORD").String()
...@@ -35,19 +38,27 @@ var ( ...@@ -35,19 +38,27 @@ var (
ignoreLabelsKey = queryCmd.Flag("exclude-label", "Exclude labels given the provided key during output.").Strings() ignoreLabelsKey = queryCmd.Flag("exclude-label", "Exclude labels given the provided key during output.").Strings()
showLabelsKey = queryCmd.Flag("include-label", "Include labels given the provided key during output.").Strings() showLabelsKey = queryCmd.Flag("include-label", "Include labels given the provided key during output.").Strings()
fixedLabelsLen = queryCmd.Flag("labels-length", "Set a fixed padding to labels").Default("0").Int() fixedLabelsLen = queryCmd.Flag("labels-length", "Set a fixed padding to labels").Default("0").Int()
labelsCmd = app.Command("labels", "Find values for a given label.")
labelsCmd = app.Command("labels", "Find values for a given label.") labelName = labelsCmd.Arg("label", "The name of the label.").HintAction(listLabels).String()
labelName = labelsCmd.Arg("label", "The name of the label.").HintAction(listLabels).String()
) )
func main() { func main() {
log.SetOutput(os.Stderr) log.SetOutput(os.Stderr)
switch kingpin.MustParse(app.Parse(os.Args[1:])) { cmd := kingpin.MustParse(app.Parse(os.Args[1:]))
if *addr == "" {
log.Fatalln("Server address cannot be empty")
}
u, err := url.Parse(*addr)
if err != nil {
log.Fatalf("Failed to parse addr into URL: %v", err)
}
addrURL = *u
switch cmd {
case queryCmd.FullCommand(): case queryCmd.FullCommand():
if *addr == "" {
log.Fatalln("Server address cannot be empty")
}
doQuery() doQuery()
case labelsCmd.FullCommand(): case labelsCmd.FullCommand():
doLabels() doLabels()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment