Move instances into a separate component
This commit is contained in:
parent
233a51d4cd
commit
a8da3f70eb
46 changed files with 553 additions and 551 deletions
61
internal/component/instances/wisski_create.go
Normal file
61
internal/component/instances/wisski_create.go
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package instances
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/stringparser"
|
||||
)
|
||||
|
||||
var errInvalidSlug = errors.New("not a valid slug")
|
||||
|
||||
// Create fills the struct for a new WissKI instance.
|
||||
// It validates that slug is a valid name for an instance.
|
||||
//
|
||||
// It does not perform any checks if the instance already exists, or does the creation in the database.
|
||||
func (instances *Instances) Create(slug string) (wisski WissKI, err error) {
|
||||
|
||||
// make sure that the slug is valid!
|
||||
if _, err := stringparser.ParseSlug(slug); err != nil {
|
||||
return wisski, errInvalidSlug
|
||||
}
|
||||
|
||||
wisski.Instance.Slug = slug
|
||||
wisski.Instance.FilesystemBase = filepath.Join(instances.Dir, slug)
|
||||
|
||||
wisski.Instance.OwnerEmail = ""
|
||||
wisski.Instance.AutoBlindUpdateEnabled = true
|
||||
|
||||
// sql
|
||||
|
||||
wisski.Instance.SqlDatabase = instances.Config.MysqlDatabasePrefix + slug
|
||||
wisski.Instance.SqlUsername = instances.Config.MysqlUserPrefix + slug
|
||||
|
||||
wisski.Instance.SqlPassword, err = instances.Config.NewPassword()
|
||||
if err != nil {
|
||||
return WissKI{}, err
|
||||
}
|
||||
|
||||
// triplestore
|
||||
|
||||
wisski.Instance.GraphDBRepository = instances.Config.GraphDBRepoPrefix + slug
|
||||
wisski.Instance.GraphDBUsername = instances.Config.GraphDBUserPrefix + slug
|
||||
|
||||
wisski.Instance.GraphDBPassword, err = instances.Config.NewPassword()
|
||||
if err != nil {
|
||||
return WissKI{}, err
|
||||
}
|
||||
|
||||
// drupal
|
||||
|
||||
wisski.DrupalUsername = "admin" // TODO: Change this!
|
||||
|
||||
wisski.DrupalPassword, err = instances.Config.NewPassword()
|
||||
if err != nil {
|
||||
return wisski, err
|
||||
}
|
||||
|
||||
// store the instance in the object and return it!
|
||||
wisski.instances = instances
|
||||
return wisski, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue