repository.go 643 Bytes
Newer Older
ale's avatar
ale committed
1 2 3
package tabacco

import (
ale's avatar
ale committed
4
	"errors"
ale's avatar
ale committed
5 6 7 8 9
	"fmt"
)

// RepositorySpec defines the configuration of a repository.
type RepositorySpec struct {
ale's avatar
ale committed
10 11 12
	Name   string                 `yaml:"name"`
	Type   string                 `yaml:"type"`
	Params map[string]interface{} `yaml:"params"`
ale's avatar
ale committed
13 14 15 16
}

// Parse a RepositorySpec and return a Repository instance.
func (spec *RepositorySpec) Parse(shell *Shell) (Repository, error) {
ale's avatar
ale committed
17 18 19 20
	if spec.Name == "" {
		return nil, errors.New("name is empty")
	}

ale's avatar
ale committed
21 22 23 24 25 26 27 28
	switch spec.Type {
	case "restic":
		return newResticRepository(spec.Params, shell)

	default:
		return nil, fmt.Errorf("unknown repository type '%s'", spec.Type)
	}
}