Exemple #1
0
func TestGithubAuthorizerDeployable(t *testing.T) {
	g := githubtest.NewStub()
	ac := acl.NewGithub(g)
	for _, spec := range []struct {
		owner, repo, user string
		want              bool
	}{
		// See the implementation of githubtest.Stub for these stub values
		// TODO(yugui) Specify these values as parameters on instantiating "g".
		{
			owner: "owner_1", repo: "repo_1", user: "******",
			want: false,
		},
		{
			owner: "owner_1", repo: "repo_1", user: "******",
			want: false,
		},
		{
			owner: "some_owner", repo: "repo_2", user: "******",
			want: true,
		},
		{
			owner: "some_owner", repo: "repo_3", user: "******",
			want: true,
		},
	} {
		if got, want := ac.Deployable(spec.owner, spec.repo, spec.user), spec.want; got != want {
			t.Errorf("auth.deployable(%q, %q, %q) = %v; want %v", spec.owner, spec.repo, spec.user, got, want)
		}
	}
}
Exemple #2
0
func main() {
	flag.Parse()
	log.Printf("Starting Goship...")

	ctx := context.Background()
	ctx, cancel := context.WithCancel(ctx)
	defer cancel()

	auth.Initialize(auth.User{Name: *defaultUser, Avatar: *defaultAvatar}, []byte(*cookieSessionHash))

	gcl, err := newGithubClient()
	if err != nil {
		log.Panicf("Failed to build github client: %v", err)
	}

	ac := acl.Null
	if auth.Enabled() {
		ac = acl.NewGithub(gcl)
	}

	if err := os.Mkdir(*dataPath, 0777); err != nil && !os.IsExist(err) {
		log.Fatal("could not create data dir: ", err)
	}

	hub := notification.NewHub(ctx)
	ecl := etcd.NewClient([]string{*ETCDServer})

	assets := helpers.New(*staticFilePath)

	http.Handle("/", auth.Authenticate(HomeHandler{ac: ac, ecl: ecl, assets: assets}))
	http.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
		http.ServeFile(w, r, r.URL.Path[1:])
	})

	dph, err := deploypage.New(assets, fmt.Sprintf("ws://%s/web_push", *bindAddress))
	if err != nil {
		log.Fatal(err)
	}
	http.Handle("/deploy", auth.Authenticate(dph))
	http.Handle("/web_push", websocket.Handler(hub.AcceptConnection))

	dlh := DeployLogHandler{assets: assets}
	http.Handle("/deployLog/", auth.AuthenticateFunc(extractDeployLogHandler(ac, ecl, dlh.ServeHTTP)))
	http.Handle("/output/", auth.AuthenticateFunc(extractOutputHandler(DeployOutputHandler)))

	pch := ProjCommitsHandler{ac: ac, gcl: gcl, ecl: ecl}
	http.Handle("/commits/", auth.AuthenticateFunc(extractCommitHandler(pch.ServeHTTP)))
	http.Handle("/deploy_handler", auth.Authenticate(DeployHandler{ecl: ecl, hub: hub}))
	http.Handle("/lock", auth.Authenticate(lock.NewLock(ecl)))
	http.Handle("/unlock", auth.Authenticate(lock.NewUnlock(ecl)))
	http.Handle("/comment", auth.Authenticate(comment.New(ecl)))
	http.HandleFunc("/auth/github/login", auth.LoginHandler)
	http.HandleFunc("/auth/github/callback", auth.CallbackHandler)
	fmt.Printf("Running on %s\n", *bindAddress)
	log.Fatal(http.ListenAndServe(*bindAddress, nil))
}
Exemple #3
0
func buildHandler(ctx context.Context) (http.Handler, error) {
	gcl, err := newGithubClient()
	if err != nil {
		glog.Errorf("Failed to build github client: %v", err)
		return nil, err
	}

	ac := acl.Null
	if auth.Enabled() {
		ac = acl.NewGithub(gcl)
	}

	if err := os.Mkdir(*dataPath, 0777); err != nil && !os.IsExist(err) {
		glog.Errorf("could not create data dir: %v", err)
		return nil, err
	}

	hub := notification.NewHub(ctx)
	ecl := etcd.NewClient([]string{*ETCDServer})
	assets := helpers.New(*staticFilePath)

	mux := http.NewServeMux()
	mux.Handle("/", auth.Authenticate(HomeHandler{ac: ac, ecl: ecl, assets: assets}))
	mux.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
		http.ServeFile(w, r, r.URL.Path[1:])
	})

	dph, err := deploypage.New(assets, fmt.Sprintf("ws://%s/web_push", *bindAddress))
	if err != nil {
		glog.Errorf("Failed to build deploy page handler: %v", err)
		return nil, err
	}
	mux.Handle("/deploy", auth.Authenticate(dph))
	mux.Handle("/web_push", websocket.Handler(hub.AcceptConnection))

	dlh := DeployLogHandler{assets: assets}
	mux.Handle("/deployLog/", auth.AuthenticateFunc(extractDeployLogHandler(ac, ecl, dlh.ServeHTTP)))
	mux.Handle("/output/", auth.AuthenticateFunc(extractOutputHandler(DeployOutputHandler)))
	mux.Handle("/commits/", auth.Authenticate(commits.New(ac, ecl, gcl, *keyPath)))
	mux.Handle("/deploy_handler", auth.Authenticate(DeployHandler{ecl: ecl, hub: hub}))
	mux.Handle("/lock", auth.Authenticate(lock.NewLock(ecl)))
	mux.Handle("/unlock", auth.Authenticate(lock.NewUnlock(ecl)))
	mux.Handle("/comment", auth.Authenticate(comment.New(ecl)))
	mux.HandleFunc("/auth/github/login", auth.LoginHandler)
	mux.HandleFunc("/auth/github/callback", auth.CallbackHandler)

	return mux, nil
}