Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logcli TLS config to use proper server name #778

Merged
merged 1 commit into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cmd/logcli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func listLabelValues(name string) (*logproto.LabelResponse, error) {
}

func doRequest(path string, out interface{}) error {
url := *addr + path
addrURL.Path = path
url := addrURL.String()
if !*quiet {
log.Print(url)
}
Expand All @@ -71,7 +72,7 @@ func doRequest(path string, out interface{}) error {
CAFile: *tlsCACertPath,
CertFile: *tlsClientCertPath,
KeyFile: *tlsClientCertKeyPath,
ServerName: url,
ServerName: addrURL.Host,
InsecureSkipVerify: *tlsSkipVerify,
},
}
Expand Down Expand Up @@ -110,14 +111,15 @@ func wsConnect(path string) (*websocket.Conn, error) {
CAFile: *tlsCACertPath,
CertFile: *tlsClientCertPath,
KeyFile: *tlsClientCertKeyPath,
ServerName: *addr,
ServerName: addrURL.Host,
InsecureSkipVerify: *tlsSkipVerify,
})
if err != nil {
return nil, err
}

url := *addr + path
addrURL.Path = path
url := addrURL.String()
if strings.HasPrefix(url, "https") {
url = strings.Replace(url, "https", "wss", 1)
} else if strings.HasPrefix(url, "http") {
Expand Down
29 changes: 20 additions & 9 deletions cmd/logcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package main

import (
"log"
"net/url"
"os"

kingpin "gopkg.in/alecthomas/kingpin.v2"
"gopkg.in/alecthomas/kingpin.v2"
)

var (
app = kingpin.New("logcli", "A command-line for loki.")
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")

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()
password = app.Flag("password", "Password for HTTP basic auth.").Default("").Envar("GRAFANA_PASSWORD").String()

Expand All @@ -35,19 +38,27 @@ var (
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()
fixedLabelsLen = queryCmd.Flag("labels-length", "Set a fixed padding to labels").Default("0").Int()

labelsCmd = app.Command("labels", "Find values for a given label.")
labelName = labelsCmd.Arg("label", "The name of the label.").HintAction(listLabels).String()
labelsCmd = app.Command("labels", "Find values for a given label.")
labelName = labelsCmd.Arg("label", "The name of the label.").HintAction(listLabels).String()
)

func main() {
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():
if *addr == "" {
log.Fatalln("Server address cannot be empty")
}
doQuery()
case labelsCmd.FullCommand():
doLabels()
Expand Down