예제 #1
0
파일: main.go 프로젝트: ericchiang/acserver
func main() {
	flag.Usage = usage
	flag.Parse()
	args := flag.Args()

	if len(args) != 5 {
		usage()
		return
	}

	if gpgpubkey == nil {
		fmt.Fprintf(os.Stderr, "internal error: gpgpubkey is nil")
		return
	}

	if https == nil {
		fmt.Fprintf(os.Stderr, "internal error: https is nil")
		return
	}

	if port == nil {
		fmt.Fprintf(os.Stderr, "internal error: port is nil")
		return
	}

	serverName = args[0]
	directory = args[1]
	templatedir = args[2]
	username = args[3]
	password = args[4]

	os.RemoveAll(path.Join(directory, "tmp"))
	err := os.MkdirAll(path.Join(directory, "tmp"), 0755)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v", err)
		return
	}

	uploads = make(map[int]*upload)

	authHandler := auth.Basic(username, password)

	r := mux.NewRouter()
	r.HandleFunc("/", renderListOfACIs)
	r.HandleFunc("/pubkeys.gpg", getPubkeys)

	n0 := negroni.New(authHandler)
	n0.UseHandler(handler{initiateUpload})
	r.Handle("/{image}/startupload", n0)

	n1 := negroni.New(authHandler)
	n1.UseHandler(handler{uploadManifest})
	r.Handle("/manifest/{num}", n1)

	n2 := negroni.New(authHandler)
	n2.UseHandler(handler{receiveUpload(tmpSigPath, gotSig)})
	r.Handle("/signature/{num}", n2)

	n3 := negroni.New(authHandler)
	n3.UseHandler(handler{receiveUpload(tmpACIPath, gotACI)})
	r.Handle("/aci/{num}", n3)

	n4 := negroni.New(authHandler)
	n4.UseHandler(handler{completeUpload})
	r.Handle("/complete/{num}", n4)

	n := negroni.New(negroni.NewStatic(http.Dir(directory)),
		negroni.NewRecovery(), negroni.NewLogger())
	n.UseHandler(r)
	n.Run(":" + strconv.Itoa(*port))
}
예제 #2
0
파일: main.go 프로젝트: dgonyeo/acserver
func main() {
	flag.Usage = usage
	flag.Parse()
	args := flag.Args()

	if len(args) != 5 {
		usage()
		return
	}

	if gpgpubkey == nil {
		fmt.Fprintf(os.Stderr, "internal error: gpgpubkey is nil")
		return
	}

	if https == nil {
		fmt.Fprintf(os.Stderr, "internal error: https is nil")
		return
	}

	if port == nil {
		fmt.Fprintf(os.Stderr, "internal error: port is nil")
		return
	}

	serverName = args[0]
	directory = args[1]
	templatedir = args[2]
	username = args[3]
	password = args[4]

	os.RemoveAll(path.Join(directory, "tmp"))
	err := os.MkdirAll(path.Join(directory, "tmp"), 0755)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v", err)
		return
	}

	uploads = make(map[int]*upload)

	authHandler := func(h http.HandlerFunc) http.Handler {
		return authBasic(username, password, h)
	}

	r := mux.NewRouter()
	r.HandleFunc("/", renderListOfACIs)
	r.HandleFunc("/pubkeys.gpg", getPubkeys)
	r.Handle("/{image}/startupload", authHandler(initiateUpload))
	r.Handle("/manifest/{num}", authHandler(uploadManifest))
	r.Handle("/signature/{num}", authHandler(receiveUpload(tmpSigPath, gotSig)))
	r.Handle("/aci/{num}", authHandler(receiveUpload(tmpACIPath, gotACI)))
	r.Handle("/complete/{num}", authHandler(completeUpload))

	r.NotFoundHandler = http.FileServer(http.Dir(directory))

	h := handlers.LoggingHandler(os.Stderr, r)

	addr := ":" + strconv.Itoa(*port)
	log.Println("Listening on", addr)
	log.Fatal(http.ListenAndServe(addr, h))
}