Exemplo n.º 1
0
func NewGithub(conf GithubConfig) (Github, error) {
	if conf.ServerUrl == "" {
		conf.ServerUrl = GithubServerURL
	}

	var log logging.Logger
	if conf.Log != nil {
		log = conf.Log
	} else {
		log = logging.NewLogger(GITHUB)
	}

	gl := GithubListener{
		GithubConfig: conf,
		Log:          log,
	}

	if conf.Secret == "" {
		return Github{}, errors.New("no github secret provided")
	}

	wh := webhook.New(conf.Secret, gl)
	wh.ContextFunc = githubContextCreator

	gh := Github{
		GithubConfig: conf,
		handler:      wh,
	}

	return gh, nil
}
Exemplo n.º 2
0
Arquivo: main.go Projeto: jrdnull/gh
func main() {
	flag.Parse()
	log.Fatal(http.ListenAndServe(*addr, webhook.New(*secret, slack{})))
}
Exemplo n.º 3
0
func main() {
	if len(os.Args) == 1 {
		die(usage)
	}
	flag.CommandLine.Usage = func() {
		fmt.Fprintln(os.Stderr, usage)
	}
	flag.Parse()
	if flag.NArg() != 1 || flag.Arg(0) == "" {
		die("invalid number of arguments")
	}
	if (*cert == "") != (*key == "") {
		die("both -cert and -key flags must be provided")
	}
	if *debug && *dump == "" {
		*dump = "testdata"
	}
	if *logfile != "" {
		f, err := os.OpenFile(*logfile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
		if err != nil {
			die(err)
		}
		log.SetOutput(f)
		defer f.Close()
	}
	var arg string
	var args = os.Args
	for len(args) != 0 {
		arg, args = args[0], args[1:]
		if arg == "--" {
			break
		}
	}
	sc, err := tsc.New(flag.Arg(0), args)
	if err != nil {
		die(err)
	}
	var listener net.Listener
	if *cert != "" {
		crt, err := tls.LoadX509KeyPair(*cert, *key)
		if err != nil {
			die(err)
		}
		cfg := &tls.Config{
			Certificates: []tls.Certificate{crt},
			Rand:         rand.Reader,
			// Don't offer SSL3.
			MinVersion: tls.VersionTLS10,
			// Workaround TLS_FALLBACK_SCSV bug. For details see:
			// https://go-review.googlesource.com/#/c/1776/
			MaxVersion: tls.VersionTLS12,
			// Don't offer RC4 ciphers.
			CipherSuites: []uint16{
				tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
				tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
				tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
				tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
				tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
				tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
				tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA,
				tls.TLS_RSA_WITH_AES_128_CBC_SHA,
				tls.TLS_RSA_WITH_AES_256_CBC_SHA,
			},
		}
		l, err := tls.Listen("tcp", nonil(*addr, "0.0.0.0:8443"), cfg)
		if err != nil {
			die(err)
		}
		listener = l
	} else {
		l, err := net.Listen("tcp", nonil(*addr, "0.0.0.0:8080"))
		if err != nil {
			die(err)
		}
		listener = l
	}
	var handler http.Handler = webhook.New(*secret, sc)
	if *dump != "" {
		handler = webhook.Dump(*dump, handler)
	}
	log.Printf("INFO Listening on %s . . .", listener.Addr())
	if err := http.Serve(listener, handler); err != nil {
		die(err)
	}
}