func getServiceAccountClient(keyJsonfilePath string) (*http.Client, error) { data, err := ioutil.ReadFile(os.ExpandEnv(keyJsonfilePath)) if err != nil { return nil, errors.Wrap(err, "error opening credentials file") } conf, err := google.JWTConfigFromJSON(data, storageConfig.Scopes...) if err != nil { return nil, errors.Wrap(err, "error processing credentials") } ctxWithSpecialClient := oauthutil.Context() return oauth2.NewClient(ctxWithSpecialClient, conf.TokenSource(ctxWithSpecialClient)), nil }
// NewFs contstructs an Fs from the path, container:path func NewFs(name, root string) (fs.Fs, error) { if uploadChunkSize > maxUploadChunkSize { return nil, fmt.Errorf("Chunk size too big, must be < %v", maxUploadChunkSize) } db, err := newDropbox(name) if err != nil { return nil, err } f := &Fs{ name: name, db: db, } f.setRoot(root) // Read the token from the config file token := fs.ConfigFile.MustValue(name, "token") // Set our custom context which enables our custom transport for timeouts etc db.SetContext(oauthutil.Context()) // Authorize the client db.SetAccessToken(token) // See if the root is actually an object entry, err := f.db.Metadata(f.slashRoot, false, false, "", "", metadataLimit) if err == nil && !entry.IsDir { remote := path.Base(f.root) newRoot := path.Dir(f.root) if newRoot == "." { newRoot = "" } f.setRoot(newRoot) obj := f.NewFsObject(remote) // return a Fs Limited to this object return fs.NewLimited(f, obj), nil } return f, nil }
// NewFs contstructs an Fs from the path, container:path func NewFs(name, root string) (fs.Fs, error) { if uploadChunkSize > maxUploadChunkSize { return nil, errors.Errorf("chunk size too big, must be < %v", maxUploadChunkSize) } db, err := newDropbox(name) if err != nil { return nil, err } f := &Fs{ name: name, db: db, } f.features = (&fs.Features{CaseInsensitive: true, ReadMimeType: true}).Fill(f) f.setRoot(root) // Read the token from the config file token := fs.ConfigFileGet(name, "token") // Set our custom context which enables our custom transport for timeouts etc db.SetContext(oauthutil.Context()) // Authorize the client db.SetAccessToken(token) // See if the root is actually an object entry, err := f.db.Metadata(f.slashRoot, false, false, "", "", metadataLimit) if err == nil && !entry.IsDir { newRoot := path.Dir(f.root) if newRoot == "." { newRoot = "" } f.setRoot(newRoot) // return an error with an fs which points to the parent return f, fs.ErrorIsFile } return f, nil }