Add ability to skip TLS verification for amtool (#2663)

* Add ability to skip TLS verification for amtool

Signed-off-by: Nikita Nedvetskii <72229464+nedvna@users.noreply.github.com>
This commit is contained in:
nedvna 2021-08-06 12:12:18 +03:00 committed by GitHub
parent e21cdfbc52
commit c72c4d79f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,8 @@
package cli
import (
"crypto/tls"
"net/http"
"net/url"
"os"
"path"
@ -35,6 +37,7 @@ var (
alertmanagerURL *url.URL
output string
timeout time.Duration
tlsInsecureSkipVerify bool
configFiles = []string{os.ExpandEnv("$HOME/.config/amtool/config.yml"), "/etc/amtool/config.yml"}
legacyFlags = map[string]string{"comment_required": "require-comment"}
@ -78,6 +81,13 @@ func NewAlertmanagerClient(amURL *url.URL) *client.Alertmanager {
cr := clientruntime.New(address, path.Join(amURL.Path, defaultAmApiv2path), schemes)
if tlsInsecureSkipVerify {
transport := http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
cr.Transport = &transport
}
if amURL.User != nil {
password, _ := amURL.User.Password()
cr.DefaultAuthentication = clientruntime.BasicAuth(amURL.User.Username(), password)
@ -98,6 +108,7 @@ func Execute() {
app.Flag("alertmanager.url", "Alertmanager to talk to").URLVar(&alertmanagerURL)
app.Flag("output", "Output formatter (simple, extended, json)").Short('o').Default("simple").EnumVar(&output, "simple", "extended", "json")
app.Flag("timeout", "Timeout for the executed command").Default("30s").DurationVar(&timeout)
app.Flag("tls.insecure.skip.verify", "Skip TLS certificate verification").BoolVar(&tlsInsecureSkipVerify)
app.Version(version.Print("amtool"))
app.GetFlag("help").Short('h')
@ -152,5 +163,9 @@ static configuration:
date.format
Sets the output format for dates. Defaults to "2006-01-02 15:04:05 MST"
tls.insecure.skip.verify
Skips TLS certificate verification for all HTTPS requests.
Defaults to false.
`
)