// NewFs contstructs an Fs from the path, container:path func NewFs(name, rpath string) (fs.Fs, error) { mode, err := NewNameEncryptionMode(fs.ConfigFileGet(name, "filename_encryption", "standard")) if err != nil { return nil, err } password := fs.ConfigFileGet(name, "password", "") if password == "" { return nil, errors.New("password not set in config file") } password, err = fs.Reveal(password) if err != nil { return nil, errors.Wrap(err, "failed to decrypt password") } salt := fs.ConfigFileGet(name, "password2", "") if salt != "" { salt, err = fs.Reveal(salt) if err != nil { return nil, errors.Wrap(err, "failed to decrypt password2") } } cipher, err := newCipher(mode, password, salt) if err != nil { return nil, errors.Wrap(err, "failed to make cipher") } remote := fs.ConfigFileGet(name, "remote") if strings.HasPrefix(remote, name+":") { return nil, errors.New("can't point crypt remote at itself - check the value of the remote setting") } // Look for a file first remotePath := path.Join(remote, cipher.EncryptFileName(rpath)) wrappedFs, err := fs.NewFs(remotePath) // if that didn't produce a file, look for a directory if err != fs.ErrorIsFile { remotePath = path.Join(remote, cipher.EncryptDirName(rpath)) wrappedFs, err = fs.NewFs(remotePath) } if err != fs.ErrorIsFile && err != nil { return nil, errors.Wrapf(err, "failed to make remote %q to wrap", remotePath) } f := &Fs{ Fs: wrappedFs, name: name, root: rpath, cipher: cipher, mode: mode, } // the features here are ones we could support, and they are // ANDed with the ones from wrappedFs f.features = (&fs.Features{ CaseInsensitive: mode == NameEncryptionOff, DuplicateFiles: true, ReadMimeType: false, // MimeTypes not supported with crypt WriteMimeType: false, }).Fill(f).Mask(wrappedFs) return f, err }
// NewFs contstructs an Fs from the path, container:path func NewFs(name, rpath string) (fs.Fs, error) { mode, err := NewNameEncryptionMode(fs.ConfigFile.MustValue(name, "filename_encryption", "standard")) if err != nil { return nil, err } password := fs.ConfigFile.MustValue(name, "password", "") if password == "" { return nil, errors.New("password not set in config file") } password, err = fs.Reveal(password) if err != nil { return nil, errors.Wrap(err, "failed to decrypt password") } salt := fs.ConfigFile.MustValue(name, "password2", "") if salt != "" { salt, err = fs.Reveal(salt) if err != nil { return nil, errors.Wrap(err, "failed to decrypt password2") } } cipher, err := newCipher(mode, password, salt) if err != nil { return nil, errors.Wrap(err, "failed to make cipher") } remote := fs.ConfigFile.MustValue(name, "remote") // Look for a file first remotePath := path.Join(remote, cipher.EncryptFileName(rpath)) wrappedFs, err := fs.NewFs(remotePath) // if that didn't produce a file, look for a directory if err != fs.ErrorIsFile { remotePath = path.Join(remote, cipher.EncryptDirName(rpath)) wrappedFs, err = fs.NewFs(remotePath) } if err != fs.ErrorIsFile && err != nil { return nil, errors.Wrapf(err, "failed to make remote %q to wrap", remotePath) } f := &Fs{ Fs: wrappedFs, cipher: cipher, mode: mode, name: name, root: rpath, } return f, err }
// Makes a new dropbox from the config func newDropbox(name string) (*dropbox.Dropbox, error) { db := dropbox.NewDropbox() appKey := fs.ConfigFile.MustValue(name, "app_key") if appKey == "" { appKey = rcloneAppKey } appSecret := fs.ConfigFile.MustValue(name, "app_secret") if appSecret == "" { appSecret = fs.Reveal(rcloneAppSecret) } err := db.SetAppInfo(appKey, appSecret) return db, err }
// Globals var ( // Description of how to auth for this app oauthConfig = &oauth2.Config{ Scopes: []string{ "wl.signin", // Allow single sign-on capabilities "wl.offline_access", // Allow receiving a refresh token "onedrive.readwrite", // r/w perms to all of a user's OneDrive files }, Endpoint: oauth2.Endpoint{ AuthURL: "https://login.live.com/oauth20_authorize.srf", TokenURL: "https://login.live.com/oauth20_token.srf", }, ClientID: rcloneClientID, ClientSecret: fs.Reveal(rcloneClientSecret), RedirectURL: oauthutil.RedirectPublicURL, } chunkSize = fs.SizeSuffix(10 * 1024 * 1024) uploadCutoff = fs.SizeSuffix(10 * 1024 * 1024) ) // Register with Fs func init() { fs.Register(&fs.Info{ Name: "onedrive", NewFs: NewFs, Config: func(name string) { err := oauthutil.Config(name, oauthConfig) if err != nil { log.Fatalf("Failed to configure token: %v", err)
rcloneEncryptedClientSecret = "8MrG3pjWyJya4OnO9ZTS4emI+9fa1ouPgvfD2MbTzfDYvO/H5czFxsTXtcji4/Hz3snz8/CrzMzlxvP9//Ty/Q==" ) // Globals var ( // Description of how to auth for this app oauthConfig = &oauth2.Config{ Scopes: []string{ "credentials.r", // Read Openstack credentials }, Endpoint: oauth2.Endpoint{ AuthURL: "https://api.hubic.com/oauth/auth/", TokenURL: "https://api.hubic.com/oauth/token/", }, ClientID: rcloneClientID, ClientSecret: fs.Reveal(rcloneEncryptedClientSecret), RedirectURL: oauthutil.RedirectLocalhostURL, } ) // Register with Fs func init() { fs.Register(&fs.RegInfo{ Name: "hubic", Description: "Hubic", NewFs: NewFs, Config: func(name string) { err := oauthutil.Config("hubic", name, oauthConfig) if err != nil { log.Fatalf("Failed to configure token: %v", err) }