component/provision: Make components purgable

This commit is contained in:
Tom Wiesing 2022-10-04 13:27:55 +02:00
parent 845e927117
commit 4358320433
No known key found for this signature in database
5 changed files with 46 additions and 31 deletions

View file

@ -4,11 +4,15 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/models"
)
// Provisionable represents a component with a Provision method.
// Provisionable represents a component with a Provision and a Purge method.
type Provisionable interface {
Component
// Provision provisions resources specific to the provided instance.
// Domain holds the full (unique) domain name of the given instance.
Provision(instance models.Instance, domain string) error
// Purge purges resources specific to the provided instance.
// Domain holds the full (unique) domain name of the given instance.
Purge(instance models.Instance, domain string) error
}

View file

@ -4,17 +4,26 @@ import (
"errors"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/pkg/errorx"
"github.com/FAU-CDI/wisski-distillery/pkg/sqle"
)
var errProvisionInvalidDatabaseParams = errors.New("Provision: Invalid parameters")
var errProvisionInvalidGrant = errors.New("Provision: Grant failed")
// ProvisionInstance provisions sql-specific resource for the given instance
// Provision provisions sql-specific resource for the given instance
func (sql *SQL) Provision(instance models.Instance, domain string) error {
return sql.CreateDatabase(instance.SqlDatabase, instance.SqlUsername, instance.SqlPassword)
}
// Purge purges sql-specific resources for the given instance
func (sql *SQL) Purge(instance models.Instance, domain string) error {
return errorx.First(
sql.PurgeDatabase(instance.SqlDatabase),
sql.PurgeUser(instance.SqlUsername),
)
}
// CreateDatabase creates a new database with the given name.
// It then generates a new user, with the name 'user' and the password 'password', that is then granted access to this database.
//

View file

@ -7,6 +7,7 @@ import (
_ "embed"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/pkg/errorx"
"github.com/FAU-CDI/wisski-distillery/pkg/unpack"
"github.com/tkw1536/goprogram/exit"
)
@ -23,6 +24,13 @@ func (ts *Triplestore) Provision(instance models.Instance, domain string) error
return ts.CreateRepository(instance.GraphDBRepository, domain, instance.GraphDBUsername, instance.GraphDBPassword)
}
func (ts *Triplestore) Purge(instance models.Instance, domain string) error {
return errorx.First(
ts.PurgeRepo(instance.GraphDBRepository),
ts.PurgeUser(instance.GraphDBUsername),
)
}
func (ts *Triplestore) CreateRepository(name, domain, user, password string) error {
if err := ts.Wait(); err != nil {
return err