예제 #1
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
}
예제 #2
0
파일: main.go 프로젝트: rakyll/drivefuse
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
func readAccount() *config.Account {
	cfg := &config.Account{
		LocalPath:    readQuestion(localPathQuestion),
		ClientId:     readQuestion(clientIdQuestion),
		ClientSecret: readQuestion(clientSecretQuestion),
	}
	cfg.RefreshToken = retrieveRefreshToken(cfg)
	for cfg.RemoteId == "" {
		rid := readQuestion(remoteIdQuestion)
		if rid == "L" {
			listFolders(auth.NewTransport(cfg))
		} else {
			cfg.RemoteId = rid
		}
	}
	return cfg
}