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.
This commit is contained in:
Tom Wiesing 2024-04-08 22:39:32 +02:00
parent 81fa84c244
commit 8235ea9105
No known key found for this signature in database
63 changed files with 288 additions and 197 deletions

View file

@ -29,7 +29,7 @@ var (
)
// Information fetches information about this WissKI.
func (wisski *Info) Information(ctx context.Context, quick bool) (info status.WissKI, err error) {
func (nfo *Info) Information(ctx context.Context, quick bool) (info status.WissKI, err error) {
// setup flags
flags := ingredient.FetcherFlags{
Quick: quick,
@ -43,7 +43,7 @@ func (wisski *Info) Information(ctx context.Context, quick bool) (info status.Wi
Limit: 5,
New: func() *phpx.Server {
atomic.AddUint64(&serversUsed, 1)
return wisski.dependencies.PHP.NewServer()
return nfo.dependencies.PHP.NewServer()
},
Discard: func(s *phpx.Server) {
s.Close()
@ -53,7 +53,7 @@ func (wisski *Info) Information(ctx context.Context, quick bool) (info status.Wi
// setup a dictionary to record data about how long each operation took.
// we use a slice as opposed to a map to avoid having to mutex!
fetcherTimes := make([]time.Duration, len(wisski.dependencies.Fetchers))
fetcherTimes := make([]time.Duration, len(nfo.dependencies.Fetchers))
recordTime := func(i int) func() {
start := time.Now()
return func() {
@ -64,7 +64,7 @@ func (wisski *Info) Information(ctx context.Context, quick bool) (info status.Wi
start := time.Now()
{
var group errgroup.Group
for i, fetcher := range wisski.dependencies.Fetchers {
for i, fetcher := range nfo.dependencies.Fetchers {
fetcher, flags, i := fetcher, flags, i
group.Go(func() error {
// quick: don't need to create servers
@ -101,7 +101,7 @@ func (wisski *Info) Information(ctx context.Context, quick bool) (info status.Wi
// get a map of how long each fetcher took
times := zerolog.Dict()
for i, fetcher := range wisski.dependencies.Fetchers {
for i, fetcher := range nfo.dependencies.Fetchers {
tookSum += fetcherTimes[i]
times = times.Dur(fetcher.Name(), fetcherTimes[i])
}
@ -115,9 +115,11 @@ func (wisski *Info) Information(ctx context.Context, quick bool) (info status.Wi
return
}
func (wisski *Info) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) error {
func (nfo *Info) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) error {
liquid := ingredient.GetLiquid(nfo)
info.Time = time.Now().UTC()
info.Slug = wisski.Slug
info.URL = wisski.URL().String()
info.Slug = liquid.Slug
info.URL = liquid.URL().String()
return nil
}

View file

@ -18,6 +18,6 @@ func (lbr *SnapshotsFetcher) Fetch(flags ingredient.FetcherFlags, info *status.W
return
}
info.Snapshots, _ = lbr.Snapshots(flags.Context)
info.Snapshots, _ = ingredient.GetLiquid(lbr).Snapshots(flags.Context)
return
}