示例#1
0
文件: github.go 项目: brianz/empire
func New(e *empire.Empire, opts Options) httpx.Handler {
	r := hookshot.NewRouter()

	secret := opts.Secret
	r.Handle("deployment", hookshot.Authorize(&DeploymentHandler{Deployer: opts.Deployer, environments: opts.Environments}, secret))
	r.Handle("ping", hookshot.Authorize(http.HandlerFunc(Ping), secret))

	return r
}
示例#2
0
func New(tug *tugboat.Tugboat, secret string) http.Handler {
	r := hookshot.NewRouter()

	r.Handle("ping", http.HandlerFunc(Ping))
	r.Handle("deployment", hookshot.Authorize(&DeploymentHandler{tugboat: tug}, secret))

	return r
}
示例#3
0
文件: server.go 项目: atmos/conveyor
func NewServer(c *conveyor.Conveyor, config Config) http.Handler {
	r := mux.NewRouter()

	// Github webhooks
	r.MatcherFunc(githubWebhook).Handler(
		hookshot.Authorize(github.NewServer(c), config.GitHubSecret),
	)

	// API
	r.NotFoundHandler = api.NewServer(c, config.APIAuth)

	return r
}
示例#4
0
func newServer(q conveyor.BuildQueue, c *cli.Context) http.Handler {
	r := mux.NewRouter()

	// Github webhooks
	r.MatcherFunc(githubWebhook).Handler(
		hookshot.Authorize(
			conveyor.NewServer(q),
			c.String("github.secret"),
		),
	)

	// Slack webhooks
	if c.String("slack.token") != "" {
		r.Handle("/slack", newSlackServer(c))
	}

	n := negroni.Classic()
	n.UseHandler(r)

	return n
}
示例#5
0
func TestHooker(t *testing.T) {
	h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		raw, err := ioutil.ReadAll(r.Body)
		if err != nil {
			t.Fatal(err)
		}

		if got, want := string(raw), `{"Data":"foo"}`+"\n"; got != want {
			t.Fatalf("Body => %s; want %s", got, want)
		}

		io.WriteString(w, "ok\n")
	})
	s := httptest.NewServer(hookshot.Authorize(h, "secret"))
	defer s.Close()

	c := NewClient(nil)
	c.Secret = "secret"
	c.URL = s.URL

	body := struct {
		Data string
	}{
		Data: "foo",
	}
	resp, err := c.Trigger("ping", &body)
	if err != nil {
		t.Fatal(err)
	}

	raw, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		t.Fatal(err)
	}

	if got, want := string(raw), "ok\n"; got != want {
		t.Fatalf("Response => %s; want %s", got, want)
	}
}
示例#6
0
func newServer(q conveyor.BuildQueue, c *cli.Context) http.Handler {
	return hookshot.Authorize(
		conveyor.NewServer(q),
		c.String("github.secret"),
	)
}