pool: Reddo component-like fields
This commit is contained in:
parent
99983ee6db
commit
337a5fbeba
48 changed files with 291 additions and 163 deletions
|
|
@ -11,9 +11,10 @@ import (
|
|||
// Barrel provides access to the underlying Barrel
|
||||
type Barrel struct {
|
||||
ingredient.Base
|
||||
|
||||
Locker *locker.Locker
|
||||
MStore *mstore.MStore
|
||||
Dependencies struct {
|
||||
Locker *locker.Locker
|
||||
MStore *mstore.MStore
|
||||
}
|
||||
}
|
||||
|
||||
func (barrel *Barrel) DataPath() string {
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ import (
|
|||
//
|
||||
// It also logs the current time into the metadata belonging to this instance.
|
||||
func (barrel *Barrel) Build(ctx context.Context, progress io.Writer, start bool) error {
|
||||
if !barrel.Locker.TryLock(ctx) {
|
||||
if !barrel.Dependencies.Locker.TryLock(ctx) {
|
||||
return locker.Locked
|
||||
}
|
||||
defer barrel.Locker.Unlock(ctx)
|
||||
defer barrel.Dependencies.Locker.Unlock(ctx)
|
||||
|
||||
stack := barrel.Stack()
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ func (barrel *Barrel) Build(ctx context.Context, progress io.Writer, start bool)
|
|||
var lastRebuild = mstore.For[int64]("lastRebuild")
|
||||
|
||||
func (barrel Barrel) LastRebuild(ctx context.Context) (t time.Time, err error) {
|
||||
epoch, err := lastRebuild.Get(ctx, barrel.MStore)
|
||||
epoch, err := lastRebuild.Get(ctx, barrel.Dependencies.MStore)
|
||||
if err == meta.ErrMetadatumNotSet {
|
||||
return t, nil
|
||||
}
|
||||
|
|
@ -61,16 +61,17 @@ func (barrel Barrel) LastRebuild(ctx context.Context) (t time.Time, err error) {
|
|||
}
|
||||
|
||||
func (barrel *Barrel) setLastRebuild(ctx context.Context) error {
|
||||
return lastRebuild.Set(ctx, barrel.MStore, time.Now().Unix())
|
||||
return lastRebuild.Set(ctx, barrel.Dependencies.MStore, time.Now().Unix())
|
||||
}
|
||||
|
||||
type LastRebuildFetcher struct {
|
||||
ingredient.Base
|
||||
|
||||
Barrel *Barrel
|
||||
Dependencies struct {
|
||||
Barrel *Barrel
|
||||
}
|
||||
}
|
||||
|
||||
func (lbr *LastRebuildFetcher) Fetch(ctx context.Context, flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
|
||||
info.LastRebuild, _ = lbr.Barrel.LastRebuild(ctx)
|
||||
info.LastRebuild, _ = lbr.Dependencies.Barrel.LastRebuild(ctx)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ var errCronFailed = exit.Error{
|
|||
}
|
||||
|
||||
func (drush *Drush) Cron(ctx context.Context, progress io.Writer) error {
|
||||
code := drush.Barrel.Shell(ctx, stream.NonInteractive(progress), "/runtime/cron.sh")()
|
||||
code := drush.Dependencies.Barrel.Shell(ctx, stream.NonInteractive(progress), "/runtime/cron.sh")()
|
||||
if code != 0 {
|
||||
// keep going, because we want to run as many crons as possible
|
||||
logging.ProgressF(progress, ctx, "%v", errCronFailed.WithMessageF(drush.Slug, code))
|
||||
|
|
@ -31,7 +31,7 @@ func (drush *Drush) Cron(ctx context.Context, progress io.Writer) error {
|
|||
|
||||
func (drush *Drush) LastCron(ctx context.Context, server *phpx.Server) (t time.Time, err error) {
|
||||
var timestamp int64
|
||||
err = drush.PHP.EvalCode(ctx, server, ×tamp, `$val = \Drupal::state()->get('system.cron_last'); return $val; `)
|
||||
err = drush.Dependencies.PHP.EvalCode(ctx, server, ×tamp, `$val = \Drupal::state()->get('system.cron_last'); return $val; `)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -40,8 +40,9 @@ func (drush *Drush) LastCron(ctx context.Context, server *phpx.Server) (t time.T
|
|||
|
||||
type LastCronFetcher struct {
|
||||
ingredient.Base
|
||||
|
||||
Drush *Drush
|
||||
Dependencies struct {
|
||||
Drush *Drush
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -53,6 +54,6 @@ func (lbr *LastCronFetcher) Fetch(flags ingredient.FetcherFlags, info *status.Wi
|
|||
return
|
||||
}
|
||||
|
||||
info.LastRebuild, _ = lbr.Drush.LastCron(flags.Context, flags.Server)
|
||||
info.LastRebuild, _ = lbr.Dependencies.Drush.LastCron(flags.Context, flags.Server)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,9 @@ import (
|
|||
// Drush implements commands related to drush
|
||||
type Drush struct {
|
||||
ingredient.Base
|
||||
|
||||
Barrel *barrel.Barrel
|
||||
MStore *mstore.MStore
|
||||
PHP *php.PHP
|
||||
Dependencies struct {
|
||||
Barrel *barrel.Barrel
|
||||
MStore *mstore.MStore
|
||||
PHP *php.PHP
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ var errBlindUpdateFailed = exit.Error{
|
|||
|
||||
// Update performs a blind drush update
|
||||
func (drush *Drush) Update(ctx context.Context, progress io.Writer) error {
|
||||
code := drush.Barrel.Shell(ctx, stream.NonInteractive(progress), "/runtime/blind_update.sh")()
|
||||
code := drush.Dependencies.Barrel.Shell(ctx, stream.NonInteractive(progress), "/runtime/blind_update.sh")()
|
||||
if code != 0 {
|
||||
return errBlindUpdateFailed.WithMessageF(drush.Slug, code)
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ func (drush *Drush) Update(ctx context.Context, progress io.Writer) error {
|
|||
const lastUpdate = mstore.For[int64]("lastUpdate")
|
||||
|
||||
func (drush *Drush) LastUpdate(ctx context.Context) (t time.Time, err error) {
|
||||
epoch, err := lastUpdate.Get(ctx, drush.MStore)
|
||||
epoch, err := lastUpdate.Get(ctx, drush.Dependencies.MStore)
|
||||
if err == meta.ErrMetadatumNotSet {
|
||||
return t, nil
|
||||
}
|
||||
|
|
@ -44,13 +44,14 @@ func (drush *Drush) LastUpdate(ctx context.Context) (t time.Time, err error) {
|
|||
}
|
||||
|
||||
func (drush *Drush) setLastUpdate(ctx context.Context) error {
|
||||
return lastUpdate.Set(ctx, drush.MStore, time.Now().Unix())
|
||||
return lastUpdate.Set(ctx, drush.Dependencies.MStore, time.Now().Unix())
|
||||
}
|
||||
|
||||
type LastUpdateFetcher struct {
|
||||
ingredient.Base
|
||||
|
||||
Drush *Drush
|
||||
Dependencies struct {
|
||||
Drush *Drush
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -58,6 +59,6 @@ var (
|
|||
)
|
||||
|
||||
func (lbr *LastUpdateFetcher) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
|
||||
info.LastUpdate, err = lbr.Drush.LastUpdate(flags.Context)
|
||||
info.LastUpdate, err = lbr.Dependencies.Drush.LastUpdate(flags.Context)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,16 @@ import (
|
|||
// Instead, this should code directly defined in go.
|
||||
type Provisioner struct {
|
||||
ingredient.Base
|
||||
Barrel *barrel.Barrel
|
||||
Dependencies struct {
|
||||
Barrel *barrel.Barrel
|
||||
}
|
||||
}
|
||||
|
||||
// Provision provisions an instance, assuming that the required databases already exist.
|
||||
func (provision *Provisioner) Provision(ctx context.Context, progress io.Writer) error {
|
||||
|
||||
// build the container
|
||||
if err := provision.Barrel.Build(ctx, progress, false); err != nil {
|
||||
if err := provision.Dependencies.Barrel.Build(ctx, progress, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +57,7 @@ func (provision *Provisioner) Provision(ctx context.Context, progress io.Writer)
|
|||
// TODO: Move the provision script into the control plane!
|
||||
provisionScript := "sudo PATH=$PATH -u www-data /bin/bash /provision_container.sh " + strings.Join(provisionParams, " ")
|
||||
|
||||
code, err := provision.Barrel.Stack().Run(ctx, stream.NonInteractive(progress), true, "barrel", "/bin/bash", "-c", provisionScript)
|
||||
code, err := provision.Dependencies.Barrel.Stack().Run(ctx, stream.NonInteractive(progress), true, "barrel", "/bin/bash", "-c", provisionScript)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,9 @@ func (barrel *Barrel) Running(ctx context.Context, progress io.Writer) (bool, er
|
|||
|
||||
type RunningFetcher struct {
|
||||
ingredient.Base
|
||||
|
||||
Barrel *Barrel
|
||||
Dependencies struct {
|
||||
Barrel *Barrel
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -28,6 +29,6 @@ var (
|
|||
)
|
||||
|
||||
func (rf *RunningFetcher) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
|
||||
info.Running, err = rf.Barrel.Running(flags.Context, io.Discard)
|
||||
info.Running, err = rf.Dependencies.Barrel.Running(flags.Context, io.Discard)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ import (
|
|||
|
||||
type SSH struct {
|
||||
ingredient.Base
|
||||
Barrel *barrel.Barrel
|
||||
Dependencies struct {
|
||||
Barrel *barrel.Barrel
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -22,7 +24,7 @@ var (
|
|||
)
|
||||
|
||||
func (ssh *SSH) Keys() ([]ssh.PublicKey, error) {
|
||||
file, err := ssh.Environment.Open(ssh.Barrel.AuthorizedKeysPath())
|
||||
file, err := ssh.Environment.Open(ssh.Dependencies.Barrel.AuthorizedKeysPath())
|
||||
if environment.IsNotExist(err) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,10 @@ import (
|
|||
|
||||
type Info struct {
|
||||
ingredient.Base
|
||||
|
||||
PHP *php.PHP
|
||||
Fetchers []ingredient.WissKIFetcher
|
||||
Dependencies struct {
|
||||
PHP *php.PHP
|
||||
Fetchers []ingredient.WissKIFetcher
|
||||
}
|
||||
|
||||
Analytics *lazy.PoolAnalytics
|
||||
}
|
||||
|
|
@ -35,7 +36,7 @@ func (wisski *Info) Information(ctx context.Context, quick bool) (info status.Wi
|
|||
|
||||
// potentially setup a new server
|
||||
if !flags.Quick {
|
||||
flags.Server = wisski.PHP.NewServer()
|
||||
flags.Server = wisski.Dependencies.PHP.NewServer()
|
||||
if err == nil {
|
||||
defer flags.Server.Close()
|
||||
}
|
||||
|
|
@ -43,7 +44,7 @@ func (wisski *Info) Information(ctx context.Context, quick bool) (info status.Wi
|
|||
|
||||
// run all the fetchers!
|
||||
var group errgroup.Group
|
||||
for _, fetcher := range wisski.Fetchers {
|
||||
for _, fetcher := range wisski.Dependencies.Fetchers {
|
||||
fetcher := fetcher
|
||||
group.Go(func() error {
|
||||
return fetcher.Fetch(flags, &info)
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ import (
|
|||
|
||||
type SnapshotsFetcher struct {
|
||||
ingredient.Base
|
||||
|
||||
Info *Info
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
|||
|
|
@ -13,8 +13,9 @@ import (
|
|||
|
||||
type Pathbuilder struct {
|
||||
ingredient.Base
|
||||
|
||||
PHP *php.PHP
|
||||
Dependencies struct {
|
||||
PHP *php.PHP
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -28,7 +29,7 @@ var pathbuilderPHP string
|
|||
//
|
||||
// server is the server to fetch the pathbuilders from, any may be nil.
|
||||
func (pathbuilder *Pathbuilder) All(ctx context.Context, server *phpx.Server) (ids []string, err error) {
|
||||
err = pathbuilder.PHP.ExecScript(ctx, server, &ids, pathbuilderPHP, "all_list")
|
||||
err = pathbuilder.Dependencies.PHP.ExecScript(ctx, server, &ids, pathbuilderPHP, "all_list")
|
||||
slices.Sort(ids)
|
||||
return
|
||||
}
|
||||
|
|
@ -38,7 +39,7 @@ func (pathbuilder *Pathbuilder) All(ctx context.Context, server *phpx.Server) (i
|
|||
//
|
||||
// server is the server to fetch the pathbuilders from, any may be nil.
|
||||
func (pathbuilder *Pathbuilder) Get(ctx context.Context, server *phpx.Server, id string) (xml string, err error) {
|
||||
err = pathbuilder.PHP.ExecScript(ctx, server, &xml, pathbuilderPHP, "one_xml", id)
|
||||
err = pathbuilder.Dependencies.PHP.ExecScript(ctx, server, &xml, pathbuilderPHP, "one_xml", id)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +47,7 @@ func (pathbuilder *Pathbuilder) Get(ctx context.Context, server *phpx.Server, id
|
|||
//
|
||||
// server is the server to fetch the pathbuilders from, any may be nil.
|
||||
func (pathbuilder *Pathbuilder) GetAll(ctx context.Context, server *phpx.Server) (pathbuilders map[string]string, err error) {
|
||||
err = pathbuilder.PHP.ExecScript(ctx, server, &pathbuilders, pathbuilderPHP, "all_xml")
|
||||
err = pathbuilder.Dependencies.PHP.ExecScript(ctx, server, &pathbuilders, pathbuilderPHP, "all_xml")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,9 +20,10 @@ import (
|
|||
// Prefixes implements reading and writing prefix
|
||||
type Prefixes struct {
|
||||
ingredient.Base
|
||||
|
||||
PHP *php.PHP
|
||||
MStore *mstore.MStore
|
||||
Dependencies struct {
|
||||
PHP *php.PHP
|
||||
MStore *mstore.MStore
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -58,7 +59,7 @@ func (prefixes *Prefixes) All(ctx context.Context, server *phpx.Server) ([]strin
|
|||
|
||||
func (wisski *Prefixes) database(ctx context.Context, server *phpx.Server) (prefixes []string, err error) {
|
||||
// get all the ugly prefixes
|
||||
err = wisski.PHP.ExecScript(ctx, server, &prefixes, listURIPrefixesPHP, "list_prefixes")
|
||||
err = wisski.Dependencies.PHP.ExecScript(ctx, server, &prefixes, listURIPrefixesPHP, "list_prefixes")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -149,7 +150,7 @@ var prefix = mstore.For[string]("prefix")
|
|||
|
||||
// Prefixes returns the cached prefixes from the given instance
|
||||
func (wisski *Prefixes) AllCached(ctx context.Context) (results []string, err error) {
|
||||
return prefix.GetAll(ctx, wisski.MStore)
|
||||
return prefix.GetAll(ctx, wisski.Dependencies.MStore)
|
||||
}
|
||||
|
||||
// Update updates the cached prefixes of this instance
|
||||
|
|
@ -158,7 +159,7 @@ func (wisski *Prefixes) Update(ctx context.Context) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return prefix.SetAll(ctx, wisski.MStore, prefixes...)
|
||||
return prefix.SetAll(ctx, wisski.Dependencies.MStore, prefixes...)
|
||||
}
|
||||
|
||||
func (prefixes *Prefixes) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
|
||||
|
|
|
|||
|
|
@ -11,18 +11,19 @@ import (
|
|||
|
||||
type Settings struct {
|
||||
ingredient.Base
|
||||
|
||||
PHP *php.PHP
|
||||
Dependencies struct {
|
||||
PHP *php.PHP
|
||||
}
|
||||
}
|
||||
|
||||
//go:embed settings.php
|
||||
var settingsPHP string
|
||||
|
||||
func (settings *Settings) Get(ctx context.Context, server *phpx.Server, key string) (value any, err error) {
|
||||
err = settings.PHP.ExecScript(ctx, server, &value, settingsPHP, "get_setting", key)
|
||||
err = settings.Dependencies.PHP.ExecScript(ctx, server, &value, settingsPHP, "get_setting", key)
|
||||
return
|
||||
}
|
||||
|
||||
func (settings *Settings) Set(ctx context.Context, server *phpx.Server, key string, value any) error {
|
||||
return settings.PHP.ExecScript(ctx, server, nil, settingsPHP, "set_setting", key, value)
|
||||
return settings.Dependencies.PHP.ExecScript(ctx, server, nil, settingsPHP, "set_setting", key, value)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,9 @@ import (
|
|||
|
||||
type Stats struct {
|
||||
ingredient.Base
|
||||
|
||||
PHP *php.PHP
|
||||
Dependencies struct {
|
||||
PHP *php.PHP
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -25,7 +26,7 @@ var statsPHP string
|
|||
|
||||
// Get fetches all statistics from the server
|
||||
func (stats *Stats) Get(ctx context.Context, server *phpx.Server) (data status.Statistics, err error) {
|
||||
err = stats.PHP.ExecScript(ctx, server, &data, statsPHP, "export_statistics")
|
||||
err = stats.Dependencies.PHP.ExecScript(ctx, server, &data, statsPHP, "export_statistics")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,9 @@ import (
|
|||
|
||||
type PHP struct {
|
||||
ingredient.Base
|
||||
|
||||
Barrel *barrel.Barrel
|
||||
Dependencies struct {
|
||||
Barrel *barrel.Barrel
|
||||
}
|
||||
}
|
||||
|
||||
// ExecScript executes the PHP code as a script on the given server.
|
||||
|
|
|
|||
|
|
@ -21,6 +21,6 @@ func (php *PHP) NewServer() *phpx.Server {
|
|||
}
|
||||
|
||||
func (php *PHP) spawn(ctx context.Context, str stream.IOStream, code string) error {
|
||||
php.Barrel.Shell(ctx, str, "-c", shellescape.QuoteCommand([]string{"drush", "php:eval", code}))()
|
||||
php.Dependencies.Barrel.Shell(ctx, str, "-c", shellescape.QuoteCommand([]string{"drush", "php:eval", code}))()
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ import (
|
|||
var errGetValidator = errors.New("GetPasswordValidator: Unknown Error")
|
||||
|
||||
func (u *Users) GetPasswordValidator(ctx context.Context, username string) (pv PasswordValidator, err error) {
|
||||
server := u.PHP.NewServer()
|
||||
server := u.Dependencies.PHP.NewServer()
|
||||
|
||||
var hash string
|
||||
err = u.PHP.ExecScript(ctx, server, &hash, usersPHP, "get_password_hash", username)
|
||||
err = u.Dependencies.PHP.ExecScript(ctx, server, &hash, usersPHP, "get_password_hash", username)
|
||||
if err != nil {
|
||||
server.Close()
|
||||
return pv, err
|
||||
|
|
|
|||
|
|
@ -14,8 +14,9 @@ import (
|
|||
|
||||
type Users struct {
|
||||
ingredient.Base
|
||||
|
||||
PHP *php.PHP
|
||||
Dependencies struct {
|
||||
PHP *php.PHP
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -27,7 +28,7 @@ var usersPHP string
|
|||
|
||||
// All returns all known usernames
|
||||
func (u *Users) All(ctx context.Context, server *phpx.Server) (users []status.User, err error) {
|
||||
err = u.PHP.ExecScript(ctx, server, &users, usersPHP, "list_users")
|
||||
err = u.Dependencies.PHP.ExecScript(ctx, server, &users, usersPHP, "list_users")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -38,7 +39,7 @@ func (u *Users) Login(ctx context.Context, server *phpx.Server, username string)
|
|||
|
||||
// generate a (relative) link
|
||||
var path string
|
||||
err = u.PHP.ExecScript(ctx, server, &path, usersPHP, "get_login_link", username)
|
||||
err = u.Dependencies.PHP.ExecScript(ctx, server, &path, usersPHP, "get_login_link", username)
|
||||
|
||||
// if something went wrong, return
|
||||
if err != nil {
|
||||
|
|
@ -64,7 +65,7 @@ var errSetPassword = errors.New("SetPassword: Unknown Error")
|
|||
// SetPassword sets the password for a given user
|
||||
func (u *Users) SetPassword(ctx context.Context, server *phpx.Server, username, password string) error {
|
||||
var ok bool
|
||||
err := u.PHP.ExecScript(ctx, server, &ok, usersPHP, "set_user_password", username, password)
|
||||
err := u.Dependencies.PHP.ExecScript(ctx, server, &ok, usersPHP, "set_user_password", username, password)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue