// Create the backend specified by URI. func create(s string) (restic.Backend, error) { debug.Log("parsing location %v", s) loc, err := location.Parse(s) if err != nil { return nil, err } switch loc.Scheme { case "local": debug.Log("create local repository at %#v", loc.Config) return local.Create(loc.Config.(string)) case "sftp": debug.Log("create sftp repository at %#v", loc.Config) return sftp.CreateWithConfig(loc.Config.(sftp.Config)) case "s3": cfg := loc.Config.(s3.Config) if cfg.KeyID == "" { cfg.KeyID = os.Getenv("AWS_ACCESS_KEY_ID") } if cfg.Secret == "" { cfg.Secret = os.Getenv("AWS_SECRET_ACCESS_KEY") } debug.Log("create s3 repository at %#v", loc.Config) return s3.Open(cfg) case "rest": return rest.Open(loc.Config.(rest.Config)) } debug.Log("invalid repository scheme: %v", s) return nil, errors.Fatalf("invalid scheme %q", loc.Scheme) }
// Open the backend specified by a location config. func open(s string) (backend.Backend, error) { debug.Log("open", "parsing location %v", s) loc, err := location.Parse(s) if err != nil { return nil, err } switch loc.Scheme { case "local": debug.Log("open", "opening local repository at %#v", loc.Config) return local.Open(loc.Config.(string)) case "sftp": debug.Log("open", "opening sftp repository at %#v", loc.Config) return sftp.OpenWithConfig(loc.Config.(sftp.Config)) case "s3": cfg := loc.Config.(s3.Config) if cfg.KeyID == "" { cfg.KeyID = os.Getenv("AWS_ACCESS_KEY_ID") } if cfg.Secret == "" { cfg.Secret = os.Getenv("AWS_SECRET_ACCESS_KEY") } debug.Log("open", "opening s3 repository at %#v", cfg) return s3.Open(cfg) case "rest": return rest.Open(loc.Config.(rest.Config)) } debug.Log("open", "invalid repository location: %v", s) return nil, fmt.Errorf("invalid scheme %q", loc.Scheme) }
// Open the backend specified by a location config. func open(s string) (restic.Backend, error) { debug.Log("parsing location %v", s) loc, err := location.Parse(s) if err != nil { return nil, errors.Fatalf("parsing repository location failed: %v", err) } var be restic.Backend switch loc.Scheme { case "local": debug.Log("opening local repository at %#v", loc.Config) be, err = local.Open(loc.Config.(string)) case "sftp": debug.Log("opening sftp repository at %#v", loc.Config) be, err = sftp.OpenWithConfig(loc.Config.(sftp.Config)) case "s3": cfg := loc.Config.(s3.Config) if cfg.KeyID == "" { cfg.KeyID = os.Getenv("AWS_ACCESS_KEY_ID") } if cfg.Secret == "" { cfg.Secret = os.Getenv("AWS_SECRET_ACCESS_KEY") } debug.Log("opening s3 repository at %#v", cfg) be, err = s3.Open(cfg) case "rest": be, err = rest.Open(loc.Config.(rest.Config)) default: return nil, errors.Fatalf("invalid backend: %q", loc.Scheme) } if err != nil { return nil, errors.Fatalf("unable to open repo at %v: %v", s, err) } return be, nil }