Esempio n. 1
0
func createTransferTasks(
	logger *logrus.Logger,
	cfg config.Config,
	dsptchr *dispatcher.Dispatcher,
) {
	logger.Debugf(
		"Found %d remote hosts for the initial transfers", len(cfg.RemoteHosts),
	)
	logger.Debugf("Size of initial transfers = %d bytes", cfg.InitTransferSize)

	for _, remoteHost := range cfg.RemoteHosts {
		host, portStr, err := net.SplitHostPort(remoteHost)
		if err != nil {
			logger.Fatalf("Parsing remote host `%s`: %s", remoteHost, err.Error())
		}
		port, err := strconv.ParseInt(portStr, 10, 16)
		if err != nil {
			logger.Fatalf(
				"Parsing remote host's port `%s`: %s",
				remoteHost, err.Error(),
			)
		}

		dsptchr.Create(api.TransferSpec{
			IP:   net.ParseIP(host),
			Port: uint16(port),
			Size: cfg.InitTransferSize,
		})
	}
}
Esempio n. 2
0
func AddLicense(lic string, stream *logrus.Logger) error {
	token := RawToken(lic)

	if token == nil {
		return fmt.Errorf("License %s is not a valid JWT", lic)
	} else {
		stream.Debugf("License passed syntax checking: %v", token)
	}

	lfile := LicenseFile()
	if lfile == "" {
		return fmt.Errorf("Unable to identify settings file")
	}

	stream.Infof("License file location: %s", lfile)

	// If file doesn't exist, "touch" it
	if _, err := os.Stat(lfile); os.IsNotExist(err) {
		pdir := path.Dir(lfile)
		if pdir == "" {
			return fmt.Errorf("Could't determine parent directory of %s: %v", lfile, err)
		}

		stream.Infof("  Creating parent directories")
		err := os.MkdirAll(pdir, 0777)
		if err != nil {
			return fmt.Errorf("Could't create parent directory %s: %v", pdir, err)
		}

		stream.Infof("  Creating license file")
		f, err := os.Create(lfile)
		if err != nil {
			return fmt.Errorf("Error trying create new licenses file at %s: %v", lfile, err)
		}
		f.Close()
	}

	lics, err := ParseLicenses(lfile, stream)
	if err != nil {
		return fmt.Errorf("License file at %s is corrupted: %v")
	}

	// Check for duplicates
	for _, l := range lics {
		if lic == l {
			stream.Infof("  Not adding '%s' because it is a duplicate of an existing entry", l)
			return nil
		}
	}

	f, err := os.OpenFile(lfile, os.O_RDWR, 0777)
	if err != nil {
		return fmt.Errorf("Error trying to open license file %s: %v", lfile, err)
	}

	_, err = f.Seek(0, 2)
	if err != nil {
		return fmt.Errorf("Error seeking end of license file %s: %v", lfile, err)
	}

	_, err = f.Write([]byte(fmt.Sprintf("%s\n", lic)))
	if err != nil {
		return fmt.Errorf("Error writing license to %s: %v", lfile, err)
	}

	return nil
}