diff options
Diffstat (limited to 'pkg/config')
| -rw-r--r-- | pkg/config/config.go | 60 | ||||
| -rw-r--r-- | pkg/config/config_test.go | 38 |
2 files changed, 86 insertions, 12 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go index 9dbf449..ff969ec 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -39,6 +39,11 @@ type ( Public bool } + SyntaxHighlight struct { + Dark string + Light string + } + // configuration represents file configuration. // fields needs to be exported to cmp to work configuration struct { @@ -50,7 +55,8 @@ type ( Repositories []*GitRepositoryConfiguration RootReadme string Scans []*scan - SyntaxHighlight string + SyntaxHighlight SyntaxHighlight + Hostname string } // This is a per repository configuration. @@ -74,7 +80,8 @@ type ( removeSuffix bool repositories []*GitRepositoryConfiguration rootReadme string - syntaxHighlight string + syntaxHighlight SyntaxHighlight + hostname string } ) @@ -95,6 +102,7 @@ func LoadConfigurationRepository(configPath string) (*ConfigurationRepository, e passphrase: []byte(config.Passphrase), repositories: config.Repositories, rootReadme: config.RootReadme, + hostname: config.Hostname, syntaxHighlight: config.SyntaxHighlight, removeSuffix: config.RemoveSuffix, orderBy: parseOrderBy(config.OrderBy), @@ -117,12 +125,20 @@ func (c *ConfigurationRepository) GetRootReadme() string { return c.rootReadme } +func (c *ConfigurationRepository) GetHostname() string { + return c.hostname +} + func (c *ConfigurationRepository) GetOrderBy() OrderBy { return c.orderBy } func (c *ConfigurationRepository) GetSyntaxHighlight() string { - return c.syntaxHighlight + return c.syntaxHighlight.Light +} + +func (c *ConfigurationRepository) GetSyntaxHighlightDark() string { + return c.syntaxHighlight.Dark } func (c *ConfigurationRepository) GetListenAddr() string { @@ -219,6 +235,11 @@ func parse(r io.Reader) (*configuration, error) { return nil, err } + err = setHostname(block, &config.Hostname) + if err != nil { + return nil, err + } + err = setListenAddr(block, &config.ListenAddr) if err != nil { return nil, err @@ -311,11 +332,16 @@ func defaultConfiguration() *configuration { return &configuration{ Scans: defaultScans(), RootReadme: "", + Hostname: defaultHostname(), ListenAddr: defaultAddr(), Repositories: make([]*GitRepositoryConfiguration, 0), } } +func defaultHostname() string { + return "https://localhost:8080" +} + func defaultScans() []*scan { return []*scan{} } @@ -339,6 +365,11 @@ func setRootReadme(block scfg.Block, readme *string) error { return setString(scanDir, readme) } +func setHostname(block scfg.Block, hostname *string) error { + scanDir := block.Get("hostname") + return setString(scanDir, hostname) +} + func setPassphrase(block scfg.Block, listenAddr *string) error { scanDir := block.Get("passphrase") return setString(scanDir, listenAddr) @@ -349,9 +380,26 @@ func setAESKey(block scfg.Block, listenAddr *string) error { return setString(scanDir, listenAddr) } -func setSyntaxHighlight(block scfg.Block, listenAddr *string) error { - scanDir := block.Get("syntax-highlight") - return setString(scanDir, listenAddr) +func setSyntaxHighlight(block scfg.Block, sh *SyntaxHighlight) error { + shDir := block.Get("syntax-highlight") + if shDir == nil { + return nil + } + + themes := shDir.Params + if len(themes) > 2 || len(themes) == 0 { + return errors.New("syntax-highlight must contains at most two params and at least one, light then dark theme name") + } + + sh.Light = themes[0] + if len(themes) > 1 { + sh.Dark = themes[1] + } else { + // if dark is not set use light + sh.Dark = sh.Light + } + + return nil } func setOrderby(block scfg.Block, orderBy *string) error { diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 949238e..50744b5 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -25,6 +25,7 @@ func TestFileParsing(t *testing.T) { }, }, ListenAddr: defaultAddr(), + Hostname: defaultHostname(), Repositories: []*GitRepositoryConfiguration{}, }, }, @@ -42,15 +43,32 @@ scan "/srv/git" { }, }, ListenAddr: defaultAddr(), + Hostname: defaultHostname(), Repositories: []*GitRepositoryConfiguration{}, }, }, { + name: "themes", + config: ` +syntax-highlight light dark`, + expectedConfig: &configuration{ + Scans: defaultScans(), + ListenAddr: defaultAddr(), + Hostname: defaultHostname(), + Repositories: []*GitRepositoryConfiguration{}, + SyntaxHighlight: SyntaxHighlight{ + Light: "light", + Dark: "dark", + }, + }, + }, + { name: "minimal repository", config: `repository /srv/git/cerrado.git`, expectedConfig: &configuration{ Scans: defaultScans(), ListenAddr: defaultAddr(), + Hostname: defaultHostname(), Repositories: []*GitRepositoryConfiguration{ { Name: "cerrado.git", @@ -74,6 +92,7 @@ repository /srv/git/cerrado.git { expectedConfig: &configuration{ Scans: defaultScans(), ListenAddr: defaultAddr(), + Hostname: defaultHostname(), Repositories: []*GitRepositoryConfiguration{ { Name: "cerrado", @@ -91,6 +110,7 @@ repository /srv/git/cerrado.git { expectedConfig: &configuration{ Scans: defaultScans(), ListenAddr: defaultAddr(), + Hostname: defaultHostname(), Repositories: []*GitRepositoryConfiguration{}, }, }, @@ -99,6 +119,7 @@ repository /srv/git/cerrado.git { config: `listen-addr unix://var/run/cerrado/cerrado.sock`, expectedConfig: &configuration{ Scans: defaultScans(), + Hostname: defaultHostname(), ListenAddr: "unix://var/run/cerrado/cerrado.sock", Repositories: []*GitRepositoryConfiguration{}, }, @@ -112,6 +133,7 @@ aes-key 8XHptZxSWCGs1m7QzztX5zNQ7D9NiQevVX0DaUTNMbDpRwFzoJiB0U7K6O/kqIt01jJVgzBU syntax-highlight monokailight order-by lastcommit-desc remove-suffix true +hostname https://domain.tld scan "/srv/git" { public true @@ -132,12 +154,16 @@ repository /srv/git/cerrado.git { Path: "/srv/git", }, }, - ListenAddr: "unix://var/run/cerrado/cerrado.sock", - Passphrase: "$2a$14$VnB/ZcB1DUDkMnosRA6Y7.dj8h5eroslDxTeXlLwfQX/x86mh6WAq", - AESKey: "8XHptZxSWCGs1m7QzztX5zNQ7D9NiQevVX0DaUTNMbDpRwFzoJiB0U7K6O/kqIt01jJVgzBUfiR8ES46ZLLb4w==", - SyntaxHighlight: "monokailight", - OrderBy: "lastcommit-desc", - RemoveSuffix: true, + ListenAddr: "unix://var/run/cerrado/cerrado.sock", + Passphrase: "$2a$14$VnB/ZcB1DUDkMnosRA6Y7.dj8h5eroslDxTeXlLwfQX/x86mh6WAq", + AESKey: "8XHptZxSWCGs1m7QzztX5zNQ7D9NiQevVX0DaUTNMbDpRwFzoJiB0U7K6O/kqIt01jJVgzBUfiR8ES46ZLLb4w==", + SyntaxHighlight: SyntaxHighlight{ + Light: "monokailight", + Dark: "monokailight", + }, + OrderBy: "lastcommit-desc", + RemoveSuffix: true, + Hostname: "https://domain.tld", Repositories: []*GitRepositoryConfiguration{ { Name: "linux.git", |
