2018-03-01 07:10:04 +00:00
|
|
|
|
package bug
|
2016-11-30 12:08:06 +00:00
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"fmt"
|
|
|
|
|
"net/url"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"runtime"
|
|
|
|
|
"text/template"
|
2016-12-30 08:21:13 +00:00
|
|
|
|
|
|
|
|
|
"github.com/containous/flaeg"
|
2018-03-01 07:10:04 +00:00
|
|
|
|
"github.com/containous/traefik/anonymize"
|
|
|
|
|
"github.com/containous/traefik/cmd"
|
|
|
|
|
"github.com/containous/traefik/cmd/version"
|
2016-11-30 12:08:06 +00:00
|
|
|
|
)
|
|
|
|
|
|
2017-10-02 08:32:02 +00:00
|
|
|
|
const (
|
|
|
|
|
bugTracker = "https://github.com/containous/traefik/issues/new"
|
2017-04-24 09:38:05 +00:00
|
|
|
|
bugTemplate = `<!--
|
2017-06-01 19:27:22 +00:00
|
|
|
|
DO NOT FILE ISSUES FOR GENERAL SUPPORT QUESTIONS.
|
2017-04-24 09:38:05 +00:00
|
|
|
|
|
2017-06-01 19:27:22 +00:00
|
|
|
|
The issue tracker is for reporting bugs and feature requests only.
|
|
|
|
|
For end-user related support questions, refer to one of the following:
|
2017-04-30 10:53:42 +00:00
|
|
|
|
|
2017-06-01 19:27:22 +00:00
|
|
|
|
- Stack Overflow (using the "traefik" tag): https://stackoverflow.com/questions/tagged/traefik
|
2018-06-12 15:04:04 +00:00
|
|
|
|
- the Traefik community Slack channel: https://slack.traefik.io
|
2017-06-01 19:27:22 +00:00
|
|
|
|
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
### Do you want to request a *feature* or report a *bug*?
|
|
|
|
|
|
|
|
|
|
(If you intend to ask a support question: **DO NOT FILE AN ISSUE**.
|
|
|
|
|
Use [Stack Overflow](https://stackoverflow.com/questions/tagged/traefik)
|
2018-06-12 15:04:04 +00:00
|
|
|
|
or [Slack](https://slack.traefik.io) instead.)
|
2017-06-01 19:27:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### What did you do?
|
|
|
|
|
|
|
|
|
|
<!--
|
2017-04-30 10:53:42 +00:00
|
|
|
|
|
|
|
|
|
HOW TO WRITE A GOOD ISSUE?
|
|
|
|
|
|
2017-06-01 19:27:22 +00:00
|
|
|
|
- Respect the issue template as more as possible.
|
|
|
|
|
- If it's possible use the command ` + "`" + "traefik bug" + "`" + `. See https://www.youtube.com/watch?v=Lyz62L8m93I.
|
2017-04-30 10:53:42 +00:00
|
|
|
|
- The title must be short and descriptive.
|
|
|
|
|
- Explain the conditions which led you to write this issue: the context.
|
|
|
|
|
- The context should lead to something, an idea or a problem that you’re facing.
|
|
|
|
|
- Remain clear and concise.
|
|
|
|
|
- Format your messages to help the reader focus on what matters and understand the structure of your message, use Markdown syntax https://help.github.com/articles/github-flavored-markdown
|
2017-04-24 09:38:05 +00:00
|
|
|
|
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
|
2016-11-30 12:08:06 +00:00
|
|
|
|
### What did you expect to see?
|
|
|
|
|
|
|
|
|
|
|
2017-04-24 09:38:05 +00:00
|
|
|
|
|
2016-11-30 12:08:06 +00:00
|
|
|
|
### What did you see instead?
|
2017-03-21 19:56:06 +00:00
|
|
|
|
|
|
|
|
|
|
2017-04-24 09:38:05 +00:00
|
|
|
|
|
|
|
|
|
### Output of ` + "`" + `traefik version` + "`" + `: (_What version of Traefik are you using?_)
|
|
|
|
|
|
|
|
|
|
` + "```" + `
|
|
|
|
|
{{.Version}}
|
|
|
|
|
` + "```" + `
|
|
|
|
|
|
|
|
|
|
### What is your environment & configuration (arguments, toml, provider, platform, ...)?
|
|
|
|
|
|
2017-08-23 22:59:01 +00:00
|
|
|
|
` + "```" + `json
|
2017-04-24 09:38:05 +00:00
|
|
|
|
{{.Configuration}}
|
|
|
|
|
` + "```" + `
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
Add more configuration information here.
|
|
|
|
|
-->
|
|
|
|
|
|
2018-03-21 13:42:07 +00:00
|
|
|
|
### If applicable, please paste the log output at DEBUG level (` + "`" + `--logLevel=DEBUG` + "`" + ` switch)
|
2017-04-24 09:38:05 +00:00
|
|
|
|
|
|
|
|
|
` + "```" + `
|
|
|
|
|
(paste your output here)
|
|
|
|
|
` + "```" + `
|
|
|
|
|
|
2016-11-30 12:08:06 +00:00
|
|
|
|
`
|
|
|
|
|
)
|
|
|
|
|
|
2018-03-01 07:10:04 +00:00
|
|
|
|
// NewCmd builds a new Bug command
|
|
|
|
|
func NewCmd(traefikConfiguration *cmd.TraefikConfiguration, traefikPointersConfiguration *cmd.TraefikConfiguration) *flaeg.Command {
|
2016-11-30 12:08:06 +00:00
|
|
|
|
|
2018-07-03 08:02:03 +00:00
|
|
|
|
// version Command init
|
2016-11-30 12:08:06 +00:00
|
|
|
|
return &flaeg.Command{
|
|
|
|
|
Name: "bug",
|
|
|
|
|
Description: `Report an issue on Traefik bugtracker`,
|
|
|
|
|
Config: traefikConfiguration,
|
|
|
|
|
DefaultPointersConfig: traefikPointersConfiguration,
|
2018-09-07 07:40:03 +00:00
|
|
|
|
Run: runCmd(traefikConfiguration),
|
2016-11-30 12:08:06 +00:00
|
|
|
|
Metadata: map[string]string{
|
|
|
|
|
"parseAllSources": "true",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 07:10:04 +00:00
|
|
|
|
func runCmd(traefikConfiguration *cmd.TraefikConfiguration) func() error {
|
2017-10-02 08:32:02 +00:00
|
|
|
|
return func() error {
|
|
|
|
|
|
2018-03-01 07:10:04 +00:00
|
|
|
|
body, err := createReport(traefikConfiguration)
|
2017-10-02 08:32:02 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 07:10:04 +00:00
|
|
|
|
sendReport(body)
|
2017-10-02 08:32:02 +00:00
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 07:10:04 +00:00
|
|
|
|
func createReport(traefikConfiguration *cmd.TraefikConfiguration) (string, error) {
|
|
|
|
|
var versionPrint bytes.Buffer
|
|
|
|
|
if err := version.GetPrint(&versionPrint); err != nil {
|
2017-10-02 08:32:02 +00:00
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmpl, err := template.New("bug").Parse(bugTemplate)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-02 09:14:03 +00:00
|
|
|
|
config, err := anonymize.Do(traefikConfiguration, true)
|
2017-10-02 08:32:02 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v := struct {
|
|
|
|
|
Version string
|
|
|
|
|
Configuration string
|
|
|
|
|
}{
|
2018-03-01 07:10:04 +00:00
|
|
|
|
Version: versionPrint.String(),
|
2017-10-02 08:32:02 +00:00
|
|
|
|
Configuration: config,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bug bytes.Buffer
|
|
|
|
|
if err := tmpl.Execute(&bug, v); err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bug.String(), nil
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 07:10:04 +00:00
|
|
|
|
func sendReport(body string) {
|
2017-10-02 08:32:02 +00:00
|
|
|
|
URL := bugTracker + "?body=" + url.QueryEscape(body)
|
|
|
|
|
if err := openBrowser(URL); err != nil {
|
|
|
|
|
fmt.Printf("Please file a new issue at %s using this template:\n\n", bugTracker)
|
|
|
|
|
fmt.Print(body)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-05 16:10:03 +00:00
|
|
|
|
func openBrowser(u string) error {
|
2016-11-30 12:08:06 +00:00
|
|
|
|
var err error
|
|
|
|
|
switch runtime.GOOS {
|
|
|
|
|
case "linux":
|
2019-02-05 16:10:03 +00:00
|
|
|
|
err = exec.Command("xdg-open", u).Start()
|
2016-11-30 12:08:06 +00:00
|
|
|
|
case "windows":
|
2019-02-05 16:10:03 +00:00
|
|
|
|
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", u).Start()
|
2016-11-30 12:08:06 +00:00
|
|
|
|
case "darwin":
|
2019-02-05 16:10:03 +00:00
|
|
|
|
err = exec.Command("open", u).Start()
|
2016-11-30 12:08:06 +00:00
|
|
|
|
default:
|
|
|
|
|
err = fmt.Errorf("unsupported platform")
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|