diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/config/config.go | 52 | ||||
-rw-r--r-- | pkg/config/config_test.go | 32 |
2 files changed, 49 insertions, 35 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go index c17e6df..1ad5108 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -30,7 +30,7 @@ type ( // configuration represents file configuration. // fields needs to be exported to cmp to work configuration struct { - Scan *scan + Scans []*scan RootReadme string ListenAddr string Passphrase string @@ -82,10 +82,12 @@ func LoadConfigurationRepository(configPath string) (*ConfigurationRepository, e syntaxHighlight: config.SyntaxHighlight, } - if config.Scan.Path != "" { - err = repo.expandOnScanPath(config.Scan.Path, config.Scan.Public) - if err != nil { - return nil, err + for _, scan := range config.Scans { + if scan.Path != "" { + err = repo.expandOnScanPath(scan.Path, scan.Public) + if err != nil { + return nil, err + } } } @@ -179,7 +181,7 @@ func parse(r io.Reader) (*configuration, error) { config := defaultConfiguration() - err = setScan(block, config.Scan) + err = setScan(block, &config.Scans) if err != nil { return nil, err } @@ -269,18 +271,15 @@ func setRepositories(block scfg.Block, repositories *[]*GitRepositoryConfigurati func defaultConfiguration() *configuration { return &configuration{ - Scan: defaultScan(), + Scans: defaultScans(), RootReadme: "", ListenAddr: defaultAddr(), Repositories: make([]*GitRepositoryConfiguration, 0), } } -func defaultScan() *scan { - return &scan{ - Public: false, - Path: "", - } +func defaultScans() []*scan { + return []*scan{} } func defaultAddr() string { @@ -322,18 +321,27 @@ func setListenAddr(block scfg.Block, listenAddr *string) error { return setString(scanDir, listenAddr) } -func setScan(block scfg.Block, scan *scan) error { - scanDir := block.Get("scan") - if scanDir == nil { - return nil - } - err := setString(scanDir, &scan.Path) - if err != nil { - return err +func setScan(block scfg.Block, scans *[]*scan) error { + for _, scanDir := range block.GetAll("scan") { + s := &scan{} + if scanDir == nil { + return nil + } + err := setString(scanDir, &s.Path) + if err != nil { + return err + } + + public := scanDir.Children.Get("public") + err = setBool(public, &s.Public) + if err != nil { + return err + } + + *scans = append(*scans, s) } - public := scanDir.Children.Get("public") - return setBool(public, &scan.Public) + return nil } func setBool(dir *scfg.Directive, field *bool) error { diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 9080351..cc58ce9 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -18,9 +18,11 @@ func TestFileParsing(t *testing.T) { name: "minimal scan", config: `scan "/srv/git"`, expectedConfig: &configuration{ - Scan: &scan{ - Public: false, - Path: "/srv/git", + Scans: []*scan{ + { + Public: false, + Path: "/srv/git", + }, }, ListenAddr: defaultAddr(), Repositories: []*GitRepositoryConfiguration{}, @@ -33,9 +35,11 @@ scan "/srv/git" { public true }`, expectedConfig: &configuration{ - Scan: &scan{ - Public: true, - Path: "/srv/git", + Scans: []*scan{ + { + Public: true, + Path: "/srv/git", + }, }, ListenAddr: defaultAddr(), Repositories: []*GitRepositoryConfiguration{}, @@ -45,7 +49,7 @@ scan "/srv/git" { name: "minimal repository", config: `repository /srv/git/cerrado.git`, expectedConfig: &configuration{ - Scan: defaultScan(), + Scans: defaultScans(), ListenAddr: defaultAddr(), Repositories: []*GitRepositoryConfiguration{ { @@ -68,7 +72,7 @@ repository /srv/git/cerrado.git { about readme.txt }`, expectedConfig: &configuration{ - Scan: defaultScan(), + Scans: defaultScans(), ListenAddr: defaultAddr(), Repositories: []*GitRepositoryConfiguration{ { @@ -85,7 +89,7 @@ repository /srv/git/cerrado.git { name: "minimal listen", config: ``, expectedConfig: &configuration{ - Scan: defaultScan(), + Scans: defaultScans(), ListenAddr: defaultAddr(), Repositories: []*GitRepositoryConfiguration{}, }, @@ -94,7 +98,7 @@ repository /srv/git/cerrado.git { name: "complete listen", config: `listen-addr unix://var/run/cerrado/cerrado.sock`, expectedConfig: &configuration{ - Scan: defaultScan(), + Scans: defaultScans(), ListenAddr: "unix://var/run/cerrado/cerrado.sock", Repositories: []*GitRepositoryConfiguration{}, }, @@ -120,9 +124,11 @@ repository /srv/git/cerrado.git { about readme.txt }`, expectedConfig: &configuration{ - Scan: &scan{ - Public: true, - Path: "/srv/git", + Scans: []*scan{ + { + Public: true, + Path: "/srv/git", + }, }, ListenAddr: "unix://var/run/cerrado/cerrado.sock", Passphrase: "$2a$14$VnB/ZcB1DUDkMnosRA6Y7.dj8h5eroslDxTeXlLwfQX/x86mh6WAq", |