aboutsummaryrefslogtreecommitdiff
path: root/pkg/domain/infra/tunnel/events.go
blob: b472ad03a26e2bada94471236af79ee8a7bba523 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package tunnel

import (
	"context"
	"strings"

	"github.com/containers/podman/v4/libpod/events"
	"github.com/containers/podman/v4/pkg/bindings/system"
	"github.com/containers/podman/v4/pkg/domain/entities"

	"github.com/pkg/errors"
)

func (ic *ContainerEngine) Events(ctx context.Context, opts entities.EventsOptions) error {
	filters := make(map[string][]string)
	if len(opts.Filter) > 0 {
		for _, filter := range opts.Filter {
			split := strings.Split(filter, "=")
			if len(split) < 2 {
				return errors.Errorf("invalid filter %q", filter)
			}
			filters[split[0]] = append(filters[split[0]], strings.Join(split[1:], "="))
		}
	}
	binChan := make(chan entities.Event)
	go func() {
		for e := range binChan {
			opts.EventChan <- entities.ConvertToLibpodEvent(e)
		}
		close(opts.EventChan)
	}()
	options := new(system.EventsOptions).WithFilters(filters).WithSince(opts.Since).WithStream(opts.Stream).WithUntil(opts.Until)
	return system.Events(ic.ClientCtx, binChan, nil, options)
}

// GetLastContainerEvent takes a container name or ID and an event status and returns
// the last occurrence of the container event.
func (ic *ContainerEngine) GetLastContainerEvent(ctx context.Context, nameOrID string, containerEvent events.Status) (*events.Event, error) {
	// check to make sure the event.Status is valid
	if _, err := events.StringToStatus(containerEvent.String()); err != nil {
		return nil, err
	}
	var event events.Event
	return &event, nil

	/*
		        FIXME: We need new bindings for this section
			filters := []string{
				fmt.Sprintf("container=%s", nameOrID),
				fmt.Sprintf("event=%s", containerEvent),
				"type=container",
			}

			containerEvents, err := system.GetEvents(ctx, entities.EventsOptions{Filter: filters})
			if err != nil {
				return nil, err
			}
			if len(containerEvents) < 1 {
				return nil, errors.Wrapf(events.ErrEventNotFound, "%s not found", containerEvent.String())
			}
			// return the last element in the slice
			return containerEvents[len(containerEvents)-1], nil
	*/
}