wisski-cloud-distillery/internal/wisski/liquid/domain.go
Tom Wiesing 8235ea9105
Require access to Still via method
This commit adds a safeguard to accessing the still from a specific
component by requiring access via the component.GetStill method.
2024-04-08 22:39:32 +02:00

40 lines
933 B
Go

package liquid
import (
"net/url"
"github.com/FAU-CDI/wisski-distillery/internal/config"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
)
// Domain returns the full domain name of this WissKI
func (liquid *Liquid) Domain() string {
return component.GetStill(liquid).Config.HTTP.HostFromSlug(liquid.Slug)
}
func (liquid *Liquid) Hostname() string {
return liquid.Domain() + ".wisski"
}
// HostRule returns a host rule for this wisski
func (liquid *Liquid) HostRule() string {
return config.MakeHostRule(liquid.Domain())
}
// URL returns the public URL of this instance
func (liquid *Liquid) URL() *url.URL {
// setup domain and path
url := &url.URL{
Host: liquid.Domain(),
Path: "/",
}
// use http or https scheme depending on if the distillery has it enabled
if component.GetStill(liquid.Malt).Config.HTTP.HTTPSEnabled() {
url.Scheme = "https"
} else {
url.Scheme = "http"
}
return url
}