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

@ -10,8 +10,6 @@ import (
type Dis struct { type Dis struct {
component.ComponentBase component.ComponentBase
// TODO: SQL Component
Executable string // path to the current executable Executable string // path to the current executable
} }
@ -29,8 +27,8 @@ func (dis Dis) Stack() component.Installable {
EnvPath: "dis.env", EnvPath: "dis.env",
EnvContext: map[string]string{ EnvContext: map[string]string{
"VIRTUAL_HOST": dis.Config.DefaultVirtualHost(), "VIRTUAL_HOST": dis.Config.DefaultHost(),
"LETSENCRYPT_HOST": dis.Config.DefaultLetsencryptHost(), "LETSENCRYPT_HOST": dis.Config.DefaultSSLHost(),
"LETSENCRYPT_EMAIL": dis.Config.CertbotEmail, "LETSENCRYPT_EMAIL": dis.Config.CertbotEmail,
"CONFIG_PATH": dis.Config.ConfigPath, "CONFIG_PATH": dis.Config.ConfigPath,

View file

@ -41,8 +41,8 @@ func (resolver Resolver) Stack() component.Installable {
EnvPath: "resolver.env", EnvPath: "resolver.env",
EnvContext: map[string]string{ EnvContext: map[string]string{
"VIRTUAL_HOST": resolver.Config.DefaultVirtualHost(), "VIRTUAL_HOST": resolver.Config.DefaultHost(),
"LETSENCRYPT_HOST": resolver.Config.DefaultLetsencryptHost(), "LETSENCRYPT_HOST": resolver.Config.DefaultSSLHost(),
"LETSENCRYPT_EMAIL": resolver.Config.CertbotEmail, "LETSENCRYPT_EMAIL": resolver.Config.CertbotEmail,
"CONFIG_PATH": resolver.Config.ConfigPath, "CONFIG_PATH": resolver.Config.ConfigPath,

View file

@ -32,8 +32,8 @@ func (self Self) Stack() component.Installable {
EnvPath: "self.env", EnvPath: "self.env",
EnvContext: map[string]string{ EnvContext: map[string]string{
"VIRTUAL_HOST": self.Config.DefaultVirtualHost(), "VIRTUAL_HOST": self.Config.DefaultHost(),
"LETSENCRYPT_HOST": self.Config.DefaultLetsencryptHost(), "LETSENCRYPT_HOST": self.Config.DefaultSSLHost(),
"LETSENCRYPT_EMAIL": self.Config.CertbotEmail, "LETSENCRYPT_EMAIL": self.Config.CertbotEmail,
"TARGET": TARGET, "TARGET": TARGET,
"OVERRIDES_FILE": self.Config.SelfOverridesFile, "OVERRIDES_FILE": self.Config.SelfOverridesFile,

7
env/component.go vendored
View file

@ -14,15 +14,10 @@ import (
"github.com/FAU-CDI/wisski-distillery/component/web" "github.com/FAU-CDI/wisski-distillery/component/web"
) )
// TODO: Remove me when migration is complete
type Component = component.Component
// TODO: Move everything into specific subpackages
// Stacks returns the Stacks of this distillery // Stacks returns the Stacks of this distillery
func (dis *Distillery) Components() []component.Component { func (dis *Distillery) Components() []component.Component {
// TODO: Do we want to cache these components? // TODO: Do we want to cache these components?
return []Component{ return []component.Component{
dis.Web(), dis.Web(),
dis.Self(), dis.Self(),
dis.Resolver(), dis.Resolver(),

17
env/instances.go vendored
View file

@ -201,15 +201,6 @@ func (instance Instance) Domain() string {
return fmt.Sprintf("%s.%s", instance.Slug, instance.dis.Config.DefaultDomain) return fmt.Sprintf("%s.%s", instance.Slug, instance.dis.Config.DefaultDomain)
} }
// IfHttps returns value if the distillery has https enabled, the empty string otherwise
// TODO: Fix this into config!
func (dis *Distillery) IfHttps(value string) string {
if !dis.Config.HTTPSEnabled() {
return ""
}
return value
}
// URL returns the public URL of this instance // URL returns the public URL of this instance
func (instance Instance) URL() *url.URL { func (instance Instance) URL() *url.URL {
// setup domain and path // setup domain and path
@ -248,8 +239,8 @@ func (instance Instance) Stack() component.Installable {
"SLUG": instance.Slug, "SLUG": instance.Slug,
"VIRTUAL_HOST": instance.Domain(), "VIRTUAL_HOST": instance.Domain(),
"LETSENCRYPT_HOST": instance.dis.IfHttps(instance.Domain()), "LETSENCRYPT_HOST": instance.dis.Config.IfHttps(instance.Domain()),
"LETSENCRYPT_EMAIL": instance.dis.IfHttps(instance.dis.Config.CertbotEmail), "LETSENCRYPT_EMAIL": instance.dis.Config.IfHttps(instance.dis.Config.CertbotEmail),
"RUNTIME_DIR": instance.dis.RuntimeDir(), "RUNTIME_DIR": instance.dis.RuntimeDir(),
"GLOBAL_AUTHORIZED_KEYS_FILE": instance.dis.Config.GlobalAuthorizedKeysFile, "GLOBAL_AUTHORIZED_KEYS_FILE": instance.dis.Config.GlobalAuthorizedKeysFile,
@ -280,8 +271,8 @@ func (instance Instance) ReserveStack() component.Installable {
EnvContext: map[string]string{ EnvContext: map[string]string{
"VIRTUAL_HOST": instance.Domain(), "VIRTUAL_HOST": instance.Domain(),
"LETSENCRYPT_HOST": instance.dis.IfHttps(instance.Domain()), "LETSENCRYPT_HOST": instance.dis.Config.IfHttps(instance.Domain()),
"LETSENCRYPT_EMAIL": instance.dis.IfHttps(instance.dis.Config.CertbotEmail), "LETSENCRYPT_EMAIL": instance.dis.Config.IfHttps(instance.dis.Config.CertbotEmail),
}, },
} }
} }

View file

@ -5,7 +5,6 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/bookkeeping" "github.com/FAU-CDI/wisski-distillery/internal/bookkeeping"
"github.com/FAU-CDI/wisski-distillery/internal/config" "github.com/FAU-CDI/wisski-distillery/internal/config"
"github.com/FAU-CDI/wisski-distillery/internal/password"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -29,11 +28,6 @@ func (dis *Distillery) InstanceGraphDB(slug string) (repo, user string) {
return return
} }
// Password returns a new password
func (dis *Distillery) NewPassword() (value string, err error) {
return password.Password(dis.Config.PasswordLength)
}
var errInvalidSlug = errors.New("Not a valid slug") var errInvalidSlug = errors.New("Not a valid slug")
// NewInstance fills the struct for a new distillery instance. // NewInstance fills the struct for a new distillery instance.
@ -48,21 +42,21 @@ func (dis *Distillery) NewInstance(slug string) (i Instance, err error) {
} }
// generate sql data // generate sql data
sqlPassword, err := dis.NewPassword() sqlPassword, err := dis.Config.NewPassword()
if err != nil { if err != nil {
return i, err return i, err
} }
sqlDB, sqlUser := dis.InstanceSQL(slug) sqlDB, sqlUser := dis.InstanceSQL(slug)
// generate ts data // generate ts data
tsPassword, err := dis.NewPassword() tsPassword, err := dis.Config.NewPassword()
if err != nil { if err != nil {
return i, err return i, err
} }
tsRepo, tsUser := dis.InstanceGraphDB(slug) tsRepo, tsUser := dis.InstanceGraphDB(slug)
// generate drupal data // generate drupal data
drPassword, err := dis.NewPassword() drPassword, err := dis.Config.NewPassword()
if err != nil { if err != nil {
return i, err return i, err
} }

6
go.mod
View file

@ -3,13 +3,13 @@ module github.com/FAU-CDI/wisski-distillery
go 1.18 go 1.18
require ( require (
github.com/FAU-CDI/wdresolve v0.0.0-20220909150742-34bde844301d github.com/FAU-CDI/wdresolve v0.0.0-20220911200729-e66b93ed2b69
github.com/Showmax/go-fqdn v1.0.0 github.com/Showmax/go-fqdn v1.0.0
github.com/alessio/shellescape v1.4.1 github.com/alessio/shellescape v1.4.1
github.com/feiin/sqlstring v0.3.0 github.com/feiin/sqlstring v0.3.0
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/tkw1536/goprogram v0.0.11 github.com/tkw1536/goprogram v0.0.11
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561
gorm.io/driver/mysql v1.3.6 gorm.io/driver/mysql v1.3.6
gorm.io/gorm v1.23.8 gorm.io/gorm v1.23.8
) )
@ -19,6 +19,6 @@ require (
github.com/jessevdk/go-flags v1.5.0 // indirect github.com/jessevdk/go-flags v1.5.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect github.com/jinzhu/now v1.1.5 // indirect
golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 // indirect golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
) )

6
go.sum
View file

@ -1,5 +1,7 @@
github.com/FAU-CDI/wdresolve v0.0.0-20220909150742-34bde844301d h1:boaE5bElltxs75SrC/sCjmsPmMnk0kcSuMYCjeo6pfE= github.com/FAU-CDI/wdresolve v0.0.0-20220909150742-34bde844301d h1:boaE5bElltxs75SrC/sCjmsPmMnk0kcSuMYCjeo6pfE=
github.com/FAU-CDI/wdresolve v0.0.0-20220909150742-34bde844301d/go.mod h1:9L2AZlOgDtg1WZ9Z1P1nBjqOY/b0mVrVE7UvO20pO2Q= github.com/FAU-CDI/wdresolve v0.0.0-20220909150742-34bde844301d/go.mod h1:9L2AZlOgDtg1WZ9Z1P1nBjqOY/b0mVrVE7UvO20pO2Q=
github.com/FAU-CDI/wdresolve v0.0.0-20220911200729-e66b93ed2b69 h1:wjiRzjx8G7Vm/rqHuAv9qMeLNHV3RmO9SNkh8VrvsBQ=
github.com/FAU-CDI/wdresolve v0.0.0-20220911200729-e66b93ed2b69/go.mod h1:9L2AZlOgDtg1WZ9Z1P1nBjqOY/b0mVrVE7UvO20pO2Q=
github.com/Showmax/go-fqdn v1.0.0 h1:0rG5IbmVliNT5O19Mfuvna9LL7zlHyRfsSvBPZmF9tM= github.com/Showmax/go-fqdn v1.0.0 h1:0rG5IbmVliNT5O19Mfuvna9LL7zlHyRfsSvBPZmF9tM=
github.com/Showmax/go-fqdn v1.0.0/go.mod h1:SfrFBzmDCtCGrnHhoDjuvFnKsWjEQX/Q9ARZvOrJAko= github.com/Showmax/go-fqdn v1.0.0/go.mod h1:SfrFBzmDCtCGrnHhoDjuvFnKsWjEQX/Q9ARZvOrJAko=
github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0=
@ -21,9 +23,13 @@ github.com/tkw1536/goprogram v0.0.11 h1:RDcPvpObL6mViB2knUj+v0AyP+XL6vvMEA0auB2A
github.com/tkw1536/goprogram v0.0.11/go.mod h1:rX9MKOpJ9qAu4jHV2+n64SKmm3c2D3Hh1V8zC1H3jB4= github.com/tkw1536/goprogram v0.0.11/go.mod h1:rX9MKOpJ9qAu4jHV2+n64SKmm3c2D3Hh1V8zC1H3jB4=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA= golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA= golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 h1:fqTvyMIIj+HRzMmnzr9NtpHP6uVpvB5fkHcgPDC4nu8= golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 h1:fqTvyMIIj+HRzMmnzr9NtpHP6uVpvB5fkHcgPDC4nu8=
golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 h1:wM1k/lXfpc5HdkJJyW9GELpd8ERGdnh8sMGL6Gzq3Ho=
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc= golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
gorm.io/driver/mysql v1.3.6 h1:BhX1Y/RyALb+T9bZ3t07wLnPZBukt+IRkMn8UZSNbGM= gorm.io/driver/mysql v1.3.6 h1:BhX1Y/RyALb+T9bZ3t07wLnPZBukt+IRkMn8UZSNbGM=

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. // Package internal contains various utility functions.
// // These do not directly involve the distillery.
// These are not subject to version guarantees and may be changed
package internal package internal

File diff suppressed because one or more lines are too long