Remove custom template logic

This commit removes custom template logic in the entire distillery
codebase.
This commit is contained in:
Tom 2023-07-14 14:26:28 +02:00
parent 588cb7ebaa
commit e2f5c66b1c
3 changed files with 24 additions and 210 deletions

View file

@ -1,6 +1,5 @@
# This file is used to initialize a new GraphDB repository.
# In this file the variables ${GRAPHDB_REPO} and ${INSTANCE_DOMAIN} will be replaced.
# All other variables will be left untouched.
# It is filled at runtime.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix rep: <http://www.openrdf.org/config/repository#>.
@ -9,8 +8,8 @@
@prefix owlim: <http://www.ontotext.com/trree/owlim#>.
[] a rep:Repository ;
rep:repositoryID "${GRAPHDB_REPO}" ;
rdfs:label "${INSTANCE_DOMAIN}" ;
rep:repositoryID "{{ .RepositoryID }}" ;
rdfs:label "{{ .Label }}" ;
rep:repositoryImpl [
rep:repositoryType "graphdb:SailRepository" ;
sr:sailImpl [
@ -18,7 +17,7 @@
owlim:owlim-license "" ;
owlim:base-URL "http://${INSTANCE_DOMAIN}/" ;
owlim:base-URL "{{ .BaseURL }}" ;
owlim:defaultNS "" ;
owlim:entity-index-size "10000000" ;
owlim:entity-id-size "32" ;

View file

@ -5,11 +5,11 @@ import (
"context"
"errors"
"net/http"
"text/template"
_ "embed"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/pkg/unpack"
"github.com/tkw1536/goprogram/exit"
)
@ -18,8 +18,20 @@ var errTripleStoreFailedRepository = exit.Error{
ExitCode: exit.ExitGeneric,
}
//go:embed create-repo.ttl
var createRepoTTL []byte
//go:embed create-repo.tpl
var createRepoTpl string
// Template for creating repositories.
//
// NOTE(twiesing): The template is not aware of SparQL syntax, thus this template is very unsafe.
// And should only be used with KNOWN GOOD input.
var creteRepoTemplate = template.Must(template.New("create-repo.tpl").Parse(createRepoTpl))
type createRepoContext struct {
RepositoryID string
Label string
BaseURL string
}
func (ts *Triplestore) Provision(ctx context.Context, instance models.Instance, domain string) error {
return ts.CreateRepository(ctx, instance.GraphDBRepository, domain, instance.GraphDBUsername, instance.GraphDBPassword)
@ -39,12 +51,11 @@ func (ts *Triplestore) CreateRepository(ctx context.Context, name, domain, user,
// prepare the create repo request
var createRepo bytes.Buffer
err := unpack.WriteTemplate(&createRepo, map[string]string{
"GRAPHDB_REPO": name,
"INSTANCE_DOMAIN": domain,
}, bytes.NewReader(createRepoTTL))
if err != nil {
if err := creteRepoTemplate.Execute(&createRepo, createRepoContext{
RepositoryID: name,
Label: domain,
BaseURL: "http://" + domain + "/",
}); err != nil {
return err
}