2017-07-08 13:38:48 +00:00
|
|
|
package azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
|
2017-08-05 19:46:15 +00:00
|
|
|
"github.com/restic/restic/internal/errors"
|
2017-07-08 13:38:48 +00:00
|
|
|
"github.com/restic/restic/internal/options"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config contains all configuration necessary to connect to an azure compatible
|
|
|
|
// server.
|
|
|
|
type Config struct {
|
|
|
|
AccountName string
|
2022-03-05 18:16:13 +00:00
|
|
|
AccountSAS options.SecretString
|
2021-08-04 20:56:18 +00:00
|
|
|
AccountKey options.SecretString
|
2017-07-08 13:38:48 +00:00
|
|
|
Container string
|
|
|
|
Prefix string
|
|
|
|
|
2021-05-15 21:08:51 +00:00
|
|
|
Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"`
|
2017-07-08 13:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewConfig returns a new Config with the default values filled in.
|
|
|
|
func NewConfig() Config {
|
|
|
|
return Config{
|
|
|
|
Connections: 5,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
options.Register("azure", Config{})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseConfig parses the string s and extracts the azure config. The
|
|
|
|
// configuration format is azure:containerName:/[prefix].
|
|
|
|
func ParseConfig(s string) (interface{}, error) {
|
2017-08-06 18:13:45 +00:00
|
|
|
if !strings.HasPrefix(s, "azure:") {
|
2017-07-08 13:38:48 +00:00
|
|
|
return nil, errors.New("azure: invalid format")
|
|
|
|
}
|
|
|
|
|
2017-08-06 18:13:45 +00:00
|
|
|
// strip prefix "azure:"
|
|
|
|
s = s[6:]
|
|
|
|
|
|
|
|
// use the first entry of the path as the bucket name and the
|
|
|
|
// remainder as prefix
|
|
|
|
data := strings.SplitN(s, ":", 2)
|
|
|
|
if len(data) < 2 {
|
|
|
|
return nil, errors.New("azure: invalid format: bucket name or path not found")
|
2017-07-08 13:38:48 +00:00
|
|
|
}
|
2017-08-06 18:13:45 +00:00
|
|
|
container, path := data[0], path.Clean(data[1])
|
2019-06-30 20:34:47 +00:00
|
|
|
path = strings.TrimPrefix(path, "/")
|
2017-08-06 18:13:45 +00:00
|
|
|
cfg := NewConfig()
|
|
|
|
cfg.Container = container
|
|
|
|
cfg.Prefix = path
|
2017-07-08 13:38:48 +00:00
|
|
|
return cfg, nil
|
|
|
|
}
|