wisski-cloud-distillery/internal/dis/component/triplestore/triplestore.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

77 lines
2 KiB
Go

package triplestore
import (
"embed"
"path/filepath"
"time"
config_package "github.com/FAU-CDI/wisski-distillery/internal/config"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/tkw1536/pkglib/yamlx"
"gopkg.in/yaml.v3"
)
type Triplestore struct {
component.Base
BaseURL string // upstream server url
PollInterval time.Duration // duration to wait for during wait
}
var (
_ component.Backupable = (*Triplestore)(nil)
_ component.Snapshotable = (*Triplestore)(nil)
_ component.Installable = (*Triplestore)(nil)
_ component.Provisionable = (*Triplestore)(nil)
)
func (ts *Triplestore) Path() string {
return filepath.Join(component.GetStill(ts).Config.Paths.Root, "core", "triplestore")
}
func (Triplestore) Context(parent component.InstallationContext) component.InstallationContext {
return parent
}
//go:embed all:triplestore
var resources embed.FS
func (ts *Triplestore) Stack() component.StackWithResources {
config := component.GetStill(ts).Config
return component.MakeStack(ts, component.StackWithResources{
Resources: resources,
ContextPath: "triplestore",
CopyContextFiles: []string{"graphdb.zip"}, // TODO: Move into constant?
EnvContext: map[string]string{
"DOCKER_NETWORK_NAME": config.Docker.Network(),
"HOST_RULE": config.HTTP.HostRule(config_package.TriplestoreDomain.Domain()),
"HTTPS_ENABLED": config.HTTP.HTTPSEnabledEnv(),
},
ComposerYML: func(root *yaml.Node) (*yaml.Node, error) {
// ts is exposed => everything is fine
if config.HTTP.TS.Set && config.HTTP.TS.Value {
return root, nil
}
// not exposed => remove the appropriate labels
if err := yamlx.ReplaceWith(root, []string{
"eu.wiss-ki.barrel.distillery=${DOCKER_NETWORK_NAME}",
}, "services", "triplestore", "labels"); err != nil {
return nil, err
}
return root, nil
},
MakeDirs: []string{
filepath.Join("data", "data"),
filepath.Join("data", "work"),
filepath.Join("data", "logs"),
filepath.Join("data", "import"),
},
})
}