Пример #1
0
func listFolders(tr *oauth.Transport) {
	svc, err := drive.New(tr.Client())
	if err != nil {
		logger.F(err)
	}
	q := "mimeType='application/vnd.google-apps.folder' and trashed=false"
	// TODO: pagination.
	files, err := svc.Files.List().Q(q).Do()
	if err != nil {
		logger.F(err)
	}
	for _, f := range files.Items {
		fmt.Println(f.Title, f.Id)
	}
}
Пример #2
0
func main() {
	flag.Parse()
	// add a lock to the config dir, no two instances should
	// run at the same time
	cfg := config.NewConfig(*flagDataDir)
	err := cfg.Setup()
	if err != nil {
		logger.F("Error initializing configuration.", err)
	}

	if *flagRunAuthWizard {
		cmd.RunAuthWizard(cfg)
		os.Exit(0)
	}

	err = cfg.Load()
	if err != nil {
		logger.F("Did you mean --wizard? Error reading configuration.", err)
	}

	transport := auth.NewTransport(cfg.FirstAccount())
	metaService, _ = metadata.New(cfg.MetadataPath())
	blobManager = blob.New(cfg.BlobPath())

	syncManager := syncer.NewCachedSyncer(
		transport,
		metaService,
		blobManager)

	if *flagBlockSync {
		syncManager.Sync(true)
	}
	syncManager.Start()

	logger.V("mounting...")
	mountpoint := cfg.FirstAccount().LocalPath
	// TODO: Better error checking here. All sorts of things like stale
	// mounts will surface at this moment.
	err = os.MkdirAll(mountpoint, 0774)
	if err != nil {
		logger.V(err)
	}
	shutdownChan := make(chan io.Closer, 1)
	go gracefulShutDown(shutdownChan, mountpoint)
	if err = mount.MountAndServe(mountpoint, metaService, blobManager); err != nil {
		logger.F(err)
	}
}
Пример #3
0
// Run the authorization wizard, generating a config file in the given data
// directory.
func RunAuthWizard(cfg *config.Config) {
	fmt.Println(messageWelcome)
	fmt.Println(messageAddAccount)
	// readConfig will fail loudly by itself, it doesn't return an error
	readConfig(cfg)
	err := cfg.Save()
	if err != nil {
		logger.F(err)
	}
	// Now display the new config to the user.
	err = cfg.Write(os.Stdout)
	if err != nil {
		logger.F(err)
	}
	fmt.Println("\nConfig written to", cfg.ConfigPath())
}
Пример #4
0
func retrieveRefreshToken(act *config.Account) string {
	tr := auth.NewTransport(act)
	url := tr.Config.AuthCodeURL("")
	fmt.Println("Visit this URL to get an authorization code.")
	fmt.Println(url)
	code := readQuestion(authorizationCodeQuestion)
	token, err := tr.Exchange(code)
	if err != nil {
		logger.F("Failed to exchange authorization code.", err)
	}
	return token.RefreshToken
}
Пример #5
0
func readQuestion(opt *question) string {
	var s string
	for s == "" {
		fmt.Printf("%v %v [default=%v]>> ", opt.Usage, Bold(opt.Name), Blue(opt.Default))
		_, err := fmt.Scanln(&s)
		if err != nil && err.Error() != "unexpected newline" {
			logger.F("Bad scan.", err)
		}
		if s == "" {
			s = opt.Default
		}
	}
	return s
}