Merge pull request #1892 from govau/fix1891
Use scheme and auth info if present from URL
This commit is contained in:
commit
588b4dd17b
25
cli/root.go
25
cli/root.go
|
@ -25,6 +25,8 @@ import (
|
||||||
"github.com/prometheus/alertmanager/api/v2/client"
|
"github.com/prometheus/alertmanager/api/v2/client"
|
||||||
"github.com/prometheus/alertmanager/cli/config"
|
"github.com/prometheus/alertmanager/cli/config"
|
||||||
"github.com/prometheus/alertmanager/cli/format"
|
"github.com/prometheus/alertmanager/cli/format"
|
||||||
|
|
||||||
|
clientruntime "github.com/go-openapi/runtime/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -63,15 +65,24 @@ const (
|
||||||
|
|
||||||
// NewAlertmanagerClient initializes an alertmanager client with the given URL
|
// NewAlertmanagerClient initializes an alertmanager client with the given URL
|
||||||
func NewAlertmanagerClient(amURL *url.URL) *client.Alertmanager {
|
func NewAlertmanagerClient(amURL *url.URL) *client.Alertmanager {
|
||||||
transportConfig := client.DefaultTransportConfig()
|
address := defaultAmHost + ":" + defaultAmPort
|
||||||
transportConfig.BasePath = defaultAmApiv2path
|
schemes := []string{"http"}
|
||||||
|
|
||||||
if amURL.Host == "" {
|
if amURL.Host != "" {
|
||||||
transportConfig.Host = defaultAmHost + ":" + defaultAmPort
|
address = amURL.Host // URL documents host as host or host:port
|
||||||
} else {
|
|
||||||
transportConfig.Host = amURL.Host
|
|
||||||
}
|
}
|
||||||
return client.NewHTTPClientWithConfig(strfmt.Default, transportConfig)
|
if amURL.Scheme != "" {
|
||||||
|
schemes = []string{amURL.Scheme}
|
||||||
|
}
|
||||||
|
|
||||||
|
cr := clientruntime.New(address, defaultAmApiv2path, schemes)
|
||||||
|
|
||||||
|
if amURL.User != nil {
|
||||||
|
password, _ := amURL.User.Password()
|
||||||
|
cr.DefaultAuthentication = clientruntime.BasicAuth(amURL.User.Username(), password)
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.New(cr, strfmt.Default)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute is the main function for the amtool command
|
// Execute is the main function for the amtool command
|
||||||
|
|
Loading…
Reference in New Issue