aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.example.scfg4
-rw-r--r--pkg/config/config.go22
-rw-r--r--pkg/config/config_test.go8
3 files changed, 34 insertions, 0 deletions
diff --git a/config.example.scfg b/config.example.scfg
index 2ed13cd..5e47548 100644
--- a/config.example.scfg
+++ b/config.example.scfg
@@ -5,6 +5,10 @@ listen-addr unix://var/run/cerrado.sock
root-readme /srv/git/README.md
syntax-highlight monokailight
+# full hostname address plus protocol.
+# This is going to be used to display full link (e.g.: clone link)
+hostname https://domain.tld
+
# if passphrase is empty the whole authentication, private/public repository
# and login UI will be disabled, and only public repository will be displayed.
passphrase $2a$14$VnB/ZcB1DUDkMnosRA6Y7.dj8h5eroslDxTeXlLwfQX/x86mh6WAq
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",