mirror of
https://github.com/restic/restic.git
synced 2025-03-16 00:00:05 +01:00
Introduced Scheme constants for the different repository schemes.
This commit is contained in:
parent
175f6b0424
commit
6b6f7451a7
5 changed files with 17 additions and 11 deletions
|
@ -5,6 +5,8 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
const Scheme = "local"
|
||||
|
||||
// ParseConfig parses a local backend config.
|
||||
func ParseConfig(cfg string) (interface{}, error) {
|
||||
if !strings.HasPrefix(cfg, "local:") {
|
||||
|
|
|
@ -16,6 +16,8 @@ type Config struct {
|
|||
Prefix string
|
||||
}
|
||||
|
||||
const Scheme = "s3"
|
||||
|
||||
const defaultPrefix = "restic"
|
||||
|
||||
// ParseConfig parses the string s and extracts the s3 config. The two
|
||||
|
|
|
@ -11,6 +11,8 @@ type Config struct {
|
|||
User, Host, Dir string
|
||||
}
|
||||
|
||||
const Scheme = "sftp"
|
||||
|
||||
// ParseConfig extracts all information for the sftp connection from the string s.
|
||||
func ParseConfig(s string) (interface{}, error) {
|
||||
if strings.HasPrefix(s, "sftp://") {
|
||||
|
|
|
@ -186,13 +186,13 @@ func open(s string) (backend.Backend, error) {
|
|||
}
|
||||
|
||||
switch loc.Scheme {
|
||||
case "local":
|
||||
case local.Scheme:
|
||||
debug.Log("open", "opening local repository at %#v", loc.Config)
|
||||
return local.Open(loc.Config.(string))
|
||||
case "sftp":
|
||||
case sftp.Scheme:
|
||||
debug.Log("open", "opening sftp repository at %#v", loc.Config)
|
||||
return sftp.OpenWithConfig(loc.Config.(sftp.Config))
|
||||
case "s3":
|
||||
case s3.Scheme:
|
||||
cfg := loc.Config.(s3.Config)
|
||||
if cfg.KeyID == "" {
|
||||
cfg.KeyID = os.Getenv("AWS_ACCESS_KEY_ID")
|
||||
|
@ -219,13 +219,13 @@ func create(s string) (backend.Backend, error) {
|
|||
}
|
||||
|
||||
switch loc.Scheme {
|
||||
case "local":
|
||||
case local.Scheme:
|
||||
debug.Log("open", "create local repository at %#v", loc.Config)
|
||||
return local.Create(loc.Config.(string))
|
||||
case "sftp":
|
||||
case sftp.Scheme:
|
||||
debug.Log("open", "create sftp repository at %#v", loc.Config)
|
||||
return sftp.CreateWithConfig(loc.Config.(sftp.Config))
|
||||
case "s3":
|
||||
case s3.Scheme:
|
||||
cfg := loc.Config.(s3.Config)
|
||||
if cfg.KeyID == "" {
|
||||
cfg.KeyID = os.Getenv("AWS_ACCESS_KEY_ID")
|
||||
|
|
|
@ -24,9 +24,9 @@ type parser struct {
|
|||
// parsers is a list of valid config parsers for the backends. The first parser
|
||||
// is the fallback and should always be set to the local backend.
|
||||
var parsers = []parser{
|
||||
{"local", local.ParseConfig},
|
||||
{"sftp", sftp.ParseConfig},
|
||||
{"s3", s3.ParseConfig},
|
||||
{local.Scheme, local.ParseConfig},
|
||||
{sftp.Scheme, sftp.ParseConfig},
|
||||
{s3.Scheme, s3.ParseConfig},
|
||||
}
|
||||
|
||||
// Parse extracts repository location information from the string s. If s
|
||||
|
@ -51,8 +51,8 @@ func Parse(s string) (u Location, err error) {
|
|||
}
|
||||
|
||||
// try again, with the local parser and the prefix "local:"
|
||||
u.Scheme = "local"
|
||||
u.Config, err = local.ParseConfig("local:" + s)
|
||||
u.Scheme = local.Scheme
|
||||
u.Config, err = local.ParseConfig(local.Scheme + ":" + s)
|
||||
if err != nil {
|
||||
return Location{}, err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue