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

7
env/component.go vendored
View file

@ -14,15 +14,10 @@ import (
"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
func (dis *Distillery) Components() []component.Component {
// TODO: Do we want to cache these components?
return []Component{
return []component.Component{
dis.Web(),
dis.Self(),
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)
}
// 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
func (instance Instance) URL() *url.URL {
// setup domain and path
@ -248,8 +239,8 @@ func (instance Instance) Stack() component.Installable {
"SLUG": instance.Slug,
"VIRTUAL_HOST": instance.Domain(),
"LETSENCRYPT_HOST": instance.dis.IfHttps(instance.Domain()),
"LETSENCRYPT_EMAIL": instance.dis.IfHttps(instance.dis.Config.CertbotEmail),
"LETSENCRYPT_HOST": instance.dis.Config.IfHttps(instance.Domain()),
"LETSENCRYPT_EMAIL": instance.dis.Config.IfHttps(instance.dis.Config.CertbotEmail),
"RUNTIME_DIR": instance.dis.RuntimeDir(),
"GLOBAL_AUTHORIZED_KEYS_FILE": instance.dis.Config.GlobalAuthorizedKeysFile,
@ -280,8 +271,8 @@ func (instance Instance) ReserveStack() component.Installable {
EnvContext: map[string]string{
"VIRTUAL_HOST": instance.Domain(),
"LETSENCRYPT_HOST": instance.dis.IfHttps(instance.Domain()),
"LETSENCRYPT_EMAIL": instance.dis.IfHttps(instance.dis.Config.CertbotEmail),
"LETSENCRYPT_HOST": instance.dis.Config.IfHttps(instance.Domain()),
"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/config"
"github.com/FAU-CDI/wisski-distillery/internal/password"
"github.com/pkg/errors"
)
@ -29,11 +28,6 @@ func (dis *Distillery) InstanceGraphDB(slug string) (repo, user string) {
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")
// 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
sqlPassword, err := dis.NewPassword()
sqlPassword, err := dis.Config.NewPassword()
if err != nil {
return i, err
}
sqlDB, sqlUser := dis.InstanceSQL(slug)
// generate ts data
tsPassword, err := dis.NewPassword()
tsPassword, err := dis.Config.NewPassword()
if err != nil {
return i, err
}
tsRepo, tsUser := dis.InstanceGraphDB(slug)
// generate drupal data
drPassword, err := dis.NewPassword()
drPassword, err := dis.Config.NewPassword()
if err != nil {
return i, err
}