Lots of internal cleanup

This commit is contained in:
Tom Wiesing 2022-09-12 11:15:52 +02:00
parent 8b7fe41309
commit 8210612198
No known key found for this signature in database
13 changed files with 939 additions and 78 deletions

View file

@ -1,25 +0,0 @@
package config
import "strings"
// This file contains derived configuration values
func (cfg Config) HTTPSEnabled() bool {
return cfg.CertbotEmail != ""
}
// Returns the default virtual host
func (cfg Config) DefaultVirtualHost() string {
VIRTUAL_HOST := cfg.DefaultDomain
if len(cfg.SelfExtraDomains) > 0 {
VIRTUAL_HOST += "," + strings.Join(cfg.SelfExtraDomains, ",")
}
return VIRTUAL_HOST
}
func (cfg Config) DefaultLetsencryptHost() string {
if !cfg.HTTPSEnabled() {
return ""
}
return cfg.DefaultVirtualHost()
}

View file

@ -0,0 +1,41 @@
package config
import "strings"
// This file contains domain related derived configuration values.
// HTTPSEnabled returns if the distillery has HTTPS enabled, and false otherwise.
func (cfg Config) HTTPSEnabled() bool {
return cfg.CertbotEmail != ""
}
// IfHttps returns value when the distillery has https enabled, and the empty string otherwise.
func (cfg Config) IfHttps(value string) string {
if !cfg.HTTPSEnabled() {
return ""
}
return value
}
// DefaultHost returns the default hostname for the distillery.
//
// This consists of the [DefaultDomain] as well as [ExtraDomains].
// Domain names are concatinated with commas.
func (cfg Config) DefaultHost() string {
var builder strings.Builder
builder.WriteString(cfg.DefaultDomain)
for _, domain := range cfg.SelfExtraDomains {
builder.WriteRune(',')
builder.WriteString(domain)
}
return builder.String()
}
// DefaultSSLHost returns the default hostname for the ssl version of the distillery.
//
// This is exactly [DefaultHost] when SSL is enabled, and the empty string otherwise.
func (cfg Config) DefaultSSLHost() string {
return cfg.IfHttps(cfg.DefaultHost())
}

View file

@ -0,0 +1,8 @@
package config
import "github.com/FAU-CDI/wisski-distillery/internal/password"
// NewPassword returns a new password using the password settings from this configuration
func (cfg Config) NewPassword() (string, error) {
return password.Password(cfg.PasswordLength)
}

View file

@ -1,4 +1,3 @@
// Package internal contains various utility functions.
//
// These are not subject to version guarantees and may be changed
// These do not directly involve the distillery.
package internal

File diff suppressed because one or more lines are too long