diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2025-06-05 20:46:46 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2025-06-05 20:49:54 +0200 |
commit | cb6060a60d71ce1be1591bb10f499916155160de (patch) | |
tree | 0eaa303fe142a61c0ee7cc3518a5b4d150cf7789 /pkg/config | |
parent | 3739c9e14b0c65a59a520dbfefa459e43af3bf20 (diff) | |
download | cerrado-master.tar.gz cerrado-master.tar.bz2 cerrado-master.zip |
Diffstat (limited to 'pkg/config')
-rw-r--r-- | pkg/config/config.go | 22 | ||||
-rw-r--r-- | pkg/config/config_test.go | 8 |
2 files changed, 30 insertions, 0 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go index 9dbf449..c00586b 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -51,6 +51,7 @@ type ( RootReadme string Scans []*scan SyntaxHighlight string + Hostname string } // This is a per repository configuration. @@ -75,6 +76,7 @@ type ( repositories []*GitRepositoryConfiguration rootReadme string syntaxHighlight string + hostname string } ) @@ -95,6 +97,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,6 +120,10 @@ func (c *ConfigurationRepository) GetRootReadme() string { return c.rootReadme } +func (c *ConfigurationRepository) GetHostname() string { + return c.hostname +} + func (c *ConfigurationRepository) GetOrderBy() OrderBy { return c.orderBy } @@ -219,6 +226,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 +323,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 +356,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) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 949238e..31cf1c0 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,6 +43,7 @@ scan "/srv/git" { }, }, ListenAddr: defaultAddr(), + Hostname: defaultHostname(), Repositories: []*GitRepositoryConfiguration{}, }, }, @@ -51,6 +53,7 @@ scan "/srv/git" { expectedConfig: &configuration{ Scans: defaultScans(), ListenAddr: defaultAddr(), + Hostname: defaultHostname(), Repositories: []*GitRepositoryConfiguration{ { Name: "cerrado.git", @@ -74,6 +77,7 @@ repository /srv/git/cerrado.git { expectedConfig: &configuration{ Scans: defaultScans(), ListenAddr: defaultAddr(), + Hostname: defaultHostname(), Repositories: []*GitRepositoryConfiguration{ { Name: "cerrado", @@ -91,6 +95,7 @@ repository /srv/git/cerrado.git { expectedConfig: &configuration{ Scans: defaultScans(), ListenAddr: defaultAddr(), + Hostname: defaultHostname(), Repositories: []*GitRepositoryConfiguration{}, }, }, @@ -99,6 +104,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 +118,7 @@ aes-key 8XHptZxSWCGs1m7QzztX5zNQ7D9NiQevVX0DaUTNMbDpRwFzoJiB0U7K6O/kqIt01jJVgzBU syntax-highlight monokailight order-by lastcommit-desc remove-suffix true +hostname https://domain.tld scan "/srv/git" { public true @@ -138,6 +145,7 @@ repository /srv/git/cerrado.git { SyntaxHighlight: "monokailight", OrderBy: "lastcommit-desc", RemoveSuffix: true, + Hostname: "https://domain.tld", Repositories: []*GitRepositoryConfiguration{ { Name: "linux.git", |