package host import ( "context" "errors" "github.com/carlosframework/platform/internal/activator" "reflect" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/hostclaim" "github.com/carlosframework/platform/internal/hostfiles" "github.com/carlosframework/platform/internal/registry" "github.com/carlosframework/platform/internal/release" ) // This boundary only reads current-version metadata. Normal C8 still proves // and validates the selected manifest after admission; presence is not proof. func (f *movesFiles) checkServingFilesEvidence(ctx context.Context, o hostclaim.Observed, rt registry.Route) error { if f == nil || f.Data == nil || o.Claim == nil || o.Claim.Holder == nil { return hostbox.ErrUnsupported } if _, err := checkFilesSeedLayout(f, rt, claimEmptyBootstrap(o.Claim.Holder)); err != nil { return err } h := o.Claim.Holder if claimEmptyBootstrap(h) { return nil } if f.emptyRecovery != nil { yes, err := f.emptyRecovery(ctx, o, h.Admissions) if err != nil { return err } if yes { return nil } } bounded, cancel := context.WithTimeout(ctx, hostbox.RequestLimit) defer cancel() chain := movesFilesChain(h, f.HomeRegion, f.Region) if h.Generation == "" { chain = []string{""} } for _, gen := range chain { version, err := f.manifestVersion(bounded, hostfiles.ManifestKey(movesFilesPrefix(h.Location, gen))) if err != nil { return err } if version != "" { return nil } } if f.Evidence != nil { pin, found, err := f.Evidence(bounded, o) if err != nil { return err } if found && pin.NeverPublished() { return nil } } return hostfiles.ErrNoEvidence } func servingFilesPrerequisites(claims release.Store, files ClaimFilesManifest) func(context.Context, registry.Route, hostclaim.Observed) error { return func(ctx context.Context, rt registry.Route, o hostclaim.Observed) error { if o.Claim == nil || o.Claim.Op.Kind != hostclaim.KindServing { return nil } f, ok := files.(interface { checkServingFilesEvidence(context.Context, hostclaim.Observed, registry.Route) error }) if !ok || claims == nil { return hostbox.ErrUnsupported } if err := f.checkServingFilesEvidence(ctx, o, rt); err != nil { if errors.Is(err, hostfiles.ErrNoEvidence) && o.Claim.Holder != nil { return &activator.ServingFilesMissing{Incarnation: o.Claim.Holder.Incarnation} } return err } fresh, err := hostclaim.Read(ctx, claims, o.Host) if err != nil { return err } if fresh.Absent || fresh.ETag != o.ETag || !reflect.DeepEqual(fresh.Claim, o.Claim) { return hostbox.ErrChanged } return ctx.Err() } }