Esempio n. 1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	flag.Usage = func() {
		fmt.Fprintln(os.Stderr, cli.HelpMessage)
	}

	flag.Parse()

	if flVersion {
		if err := cli.PrintVersion(); err != nil {
			log.Fatal(err)
		}
		return
	}

	if flServerMode {
		fullAddress := fmt.Sprintf("%v:%v", flServerAddress, flServerPort)

		log.Printf("Running dogestry in server mode on '%v'", fullAddress)

		s := server.New(fullAddress)
		s.ServeHttp()
	} else {
		args := flag.Args()

		// Allow 'help', 'version' and 'login' to not require AWS cred env vars
		requireEnvVars := true

		if len(args) == 0 || (args[0] == "help" || args[0] == "login" || args[0] == "version") {
			requireEnvVars = false
		}

		cfg, err := config.NewConfig(flUseMetaService, flServerPort, flForceLocal, requireEnvVars)
		if err != nil {
			log.Fatal(err)
		}

		dogestryCli, err := cli.NewDogestryCli(cfg, flPullHosts)
		if err != nil {
			log.Fatal(err)
		}

		if flLockFile != "" {
			utils.LockByFile(dogestryCli, args, flLockFile)
		} else {
			err = dogestryCli.RunCmd(args...)

			dogestryCli.Cleanup()

			if err != nil {
				log.Fatal(err)
			}
		}
	}
}
Esempio n. 2
0
func TestNewDogestryCli(t *testing.T) {
	cfg, err := config.NewConfig(false, 22375, false, false)
	if err != nil {
		t.Fatalf("Creating dogestry config should work. Error: %v", err)
	}

	dogestryCli, err := NewDogestryCli(cfg, hosts)
	if err != nil {
		t.Fatalf("Creating dogestryCli struct should work. Error: %v", err)
	}

	if dogestryCli.Client == nil {
		t.Fatal("dogestryCli.Client should never be nil.")
	}
}
Esempio n. 3
0
func TestCreateAndReturnTempDirAndCleanup(t *testing.T) {
	cfg, err := config.NewConfig(false, 22375, false, false)
	if err != nil {
		t.Fatalf("Creating dogestry config should work. Error: %v", err)
	}

	dogestryCli, _ := NewDogestryCli(cfg, hosts)

	tmpDir := dogestryCli.CreateAndReturnTempDir()
	if tmpDir == "" {
		t.Fatalf("CreateAndReturnTempDir should always return path to tmp directory. tmpDir: %v", tmpDir)
	}

	dogestryCli.Cleanup()
	if _, err := os.Stat(tmpDir); err == nil {
		t.Fatalf("Cleanup() should remove tmp directory. tmpDir: %v", tmpDir)
	}
}
Esempio n. 4
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	flag.Usage = func() {
		fmt.Fprintln(os.Stderr, cli.HelpMessage)
	}

	flag.Parse()

	if flVersion {
		err := cli.PrintVersion()
		if err != nil {
			log.Fatal(err)
		}
		return
	}

	args := flag.Args()

	cfg, err := config.NewConfig(flUseMetaService)
	if err != nil {
		log.Fatal(err)
	}

	dogestryCli, err := cli.NewDogestryCli(cfg, flPullHosts)
	if err != nil {
		log.Fatal(err)
	}

	if flLockFile != "" {
		utils.LockByFile(dogestryCli, args, flLockFile)
	} else {
		err = dogestryCli.RunCmd(args...)

		if err == nil {
			dogestryCli.Cleanup()
		} else {
			dogestryCli.Cleanup()
			log.Fatal(err)
		}
	}
}
Esempio n. 5
0
func (s *S) SetUpSuite(c *C) {
	testServer.Start()

	auth, _ := aws.GetAuth("abc", "123", "", time.Time{})
	client := s3.New(auth, aws.Region{Name: "faux-region-1", S3Endpoint: testServer.URL})

	tempDir, err := ioutil.TempDir("", "dogestry-test")
	if err != nil {
		c.Fatalf("couldn't get tempdir. Error: %s", err)
	}

	s.TempDir = tempDir

	baseConfig, err := config.NewConfig(false)
	if err != nil {
		c.Fatalf("couldn't initialize config. Error: %s", err)
	}

	s.remote = &S3Remote{
		config:     baseConfig,
		BucketName: "bucket",
		client:     client,
	}
}