wisski-cloud-distillery/internal/wisski/ingredient/barrel/running.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

40 lines
998 B
Go

package barrel
import (
"context"
"github.com/FAU-CDI/wisski-distillery/internal/status"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
"github.com/compose-spec/compose-go/errdefs"
)
// Running checks if this WissKI is currently running.
func (barrel *Barrel) Running(ctx context.Context) (bool, error) {
containers, err := ingredient.GetLiquid(barrel).Docker.Containers(ctx, barrel.Stack().Dir)
if err != nil {
// The compose file is gone => the stack doesn't exist.
// Probably means some purging got interrupted.
if errdefs.IsNotFoundError(err) {
return false, nil
}
return false, err
}
return len(containers) > 0, nil
}
type RunningFetcher struct {
ingredient.Base
dependencies struct {
Barrel *Barrel
}
}
var (
_ ingredient.WissKIFetcher = (*RunningFetcher)(nil)
)
func (rf *RunningFetcher) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
info.Running, err = rf.dependencies.Barrel.Running(flags.Context)
return
}