github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/domain/infra/tunnel/events.go (about) 1 package tunnel 2 3 import ( 4 "context" 5 "strings" 6 7 "github.com/hanks177/podman/v4/libpod/events" 8 "github.com/hanks177/podman/v4/pkg/bindings/system" 9 "github.com/hanks177/podman/v4/pkg/domain/entities" 10 11 "github.com/pkg/errors" 12 ) 13 14 func (ic *ContainerEngine) Events(ctx context.Context, opts entities.EventsOptions) error { 15 filters := make(map[string][]string) 16 if len(opts.Filter) > 0 { 17 for _, filter := range opts.Filter { 18 split := strings.Split(filter, "=") 19 if len(split) < 2 { 20 return errors.Errorf("invalid filter %q", filter) 21 } 22 filters[split[0]] = append(filters[split[0]], strings.Join(split[1:], "=")) 23 } 24 } 25 binChan := make(chan entities.Event) 26 go func() { 27 for e := range binChan { 28 opts.EventChan <- entities.ConvertToLibpodEvent(e) 29 } 30 close(opts.EventChan) 31 }() 32 options := new(system.EventsOptions).WithFilters(filters).WithSince(opts.Since).WithStream(opts.Stream).WithUntil(opts.Until) 33 return system.Events(ic.ClientCtx, binChan, nil, options) 34 } 35 36 // GetLastContainerEvent takes a container name or ID and an event status and returns 37 // the last occurrence of the container event. 38 func (ic *ContainerEngine) GetLastContainerEvent(ctx context.Context, nameOrID string, containerEvent events.Status) (*events.Event, error) { 39 // check to make sure the event.Status is valid 40 if _, err := events.StringToStatus(containerEvent.String()); err != nil { 41 return nil, err 42 } 43 var event events.Event 44 return &event, nil 45 46 /* 47 FIXME: We need new bindings for this section 48 filters := []string{ 49 fmt.Sprintf("container=%s", nameOrID), 50 fmt.Sprintf("event=%s", containerEvent), 51 "type=container", 52 } 53 54 containerEvents, err := system.GetEvents(ctx, entities.EventsOptions{Filter: filters}) 55 if err != nil { 56 return nil, err 57 } 58 if len(containerEvents) < 1 { 59 return nil, errors.Wrapf(events.ErrEventNotFound, "%s not found", containerEvent.String()) 60 } 61 // return the last element in the slice 62 return containerEvents[len(containerEvents)-1], nil 63 */ 64 }