Esempio 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)
}
Esempio n. 2
0
		system := system.NewOsSystem()
		i = installer.New(system)
	})

	JustBeforeEach(func() {
		listener = spec.StartDownloadServer(port, tarballPath, directorCert)
		tarballURL = fmt.Sprintf("https://localhost:%d/tarball.tgz", port)

		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())
		dl = downloader.NewDownloader(config, i)
	})

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

	It("GETs the given URL, opens the tarball, and runs install.sh", func() {
		err := dl.Download(logger, tarballURL)
		Expect(err).ToNot(HaveOccurred())
		installLog, err := ioutil.ReadFile(path.Join(tmpDir, "install.log"))
		Expect(err).ToNot(HaveOccurred())
		Expect((string)(installLog)).To(Equal("hiya\n"))
	})