Files
kopia/cli/storage_rclone.go
Jarek Kowalski e03971fc59 Upgraded linter to v1.33.0 (#734)
* linter: upgraded to 1.33, disabled some linters

* lint: fixed 'errorlint' errors

This ensures that all error comparisons use errors.Is() or errors.As().
We will be wrapping more errors going forward so it's important that
error checks are not strict everywhere.

Verified that there are no exceptions for errorlint linter which
guarantees that.

* lint: fixed or suppressed wrapcheck errors

* lint: nolintlint and misc cleanups

Co-authored-by: Julio López <julio+gh@kasten.io>
2020-12-21 22:39:22 -08:00

50 lines
1.4 KiB
Go

package cli
import (
"context"
"io/ioutil"
"github.com/alecthomas/kingpin"
"github.com/pkg/errors"
"github.com/kopia/kopia/repo/blob"
"github.com/kopia/kopia/repo/blob/rclone"
)
func init() {
var (
opt rclone.Options
connectFlat bool
embedRCloneConfigFile string
)
RegisterStorageConnectFlags(
"rclone",
"an rclone-based provided",
func(cmd *kingpin.CmdClause) {
cmd.Flag("remote-path", "Rclone remote:path").Required().StringVar(&opt.RemotePath)
cmd.Flag("flat", "Use flat directory structure").BoolVar(&connectFlat)
cmd.Flag("rclone-exe", "Path to rclone binary").StringVar(&opt.RCloneExe)
cmd.Flag("rclone-args", "Pass additional parameters to rclone").StringsVar(&opt.RCloneArgs)
cmd.Flag("rclone-env", "Pass additional environment (key=value) to rclone").StringsVar(&opt.RCloneEnv)
cmd.Flag("embed-rclone-config", "Embed the provider RClone config").ExistingFileVar(&embedRCloneConfigFile)
},
func(ctx context.Context, isNew bool) (blob.Storage, error) {
if connectFlat {
opt.DirectoryShards = []int{}
}
if embedRCloneConfigFile != "" {
cfg, err := ioutil.ReadFile(embedRCloneConfigFile) //nolint:gosec
if err != nil {
return nil, errors.Wrap(err, "unable to read rclone config file")
}
opt.EmbeddedConfig = string(cfg)
}
return rclone.New(ctx, &opt)
},
)
}