Exemplo n.º 1
0
func main() {
	logger := newLogger()
	parseFlags(logger)
	installer := installer.New(system.NewOsSystem())
	config := newSSLConfig(logger)

	switch os.Args[1] {
	case "listen":
		portString := os.Args[2]
		port, err := strconv.Atoi(portString)
		if err != nil {
			log.Println("failed to parse port '", portString, "' :", err)
			os.Exit(1)
		}

		l := listener.NewListener(config, installer)
		err = l.ListenAndServe(logger, port)
		if err != nil {
			os.Exit(1)
		}
		l.WaitForServerToExit()

	case "download":
		url := os.Args[2]

		d := downloader.NewDownloader(config, installer)
		err := d.Download(logger, url)
		if err != nil {
			os.Exit(1)
		}

	default:
		usage()
	}

	os.Exit(0)
}
Exemplo n.º 2
0
		allowedNames = []string{"*"}
		system := system.NewOsSystem()
		i = installer.New(system)
		port = spec.GetFreePort()
	})

	JustBeforeEach(func() {
		config, err := auth.NewSSLConfig(
			spec.FixtureFilename("certs/bootstrapper.crt"),
			spec.FixtureFilename("certs/bootstrapper.key"),
			(string)(spec.FixtureData("certs/rootCA.pem")),
			allowedNames,
		)
		Expect(err).ToNot(HaveOccurred())

		l = listener.NewListener(config, i)
	})

	AfterEach(func() {
		if l != nil {
			l.Close()
		}
	})

	Context("when the port is already taken", func() {
		var otherListener *net.TCPListener

		BeforeEach(func() {
			var err error
			otherListener, err = net.ListenTCP("tcp", &net.TCPAddr{Port: port})
			Expect(err).ToNot(HaveOccurred())