forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventactivation_service.go
50 lines (39 loc) · 1.32 KB
/
eventactivation_service.go
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
package remoteenvironment
import (
"fmt"
"github.com/kyma-project/kyma/components/remote-environment-broker/pkg/apis/remoteenvironment/v1alpha1"
"k8s.io/client-go/tools/cache"
)
type eventActivationService struct {
informer cache.SharedIndexInformer
}
func newEventActivationService(informer cache.SharedIndexInformer) *eventActivationService {
return &eventActivationService{
informer: informer,
}
}
func (svc *eventActivationService) List(environment string) ([]*v1alpha1.EventActivation, error) {
items, err := svc.informer.GetIndexer().ByIndex("namespace", environment)
if err != nil {
return nil, err
}
return svc.toEventActivations(items)
}
func (svc *eventActivationService) toEventActivation(item interface{}) (*v1alpha1.EventActivation, error) {
eventActivation, ok := item.(*v1alpha1.EventActivation)
if !ok {
return nil, fmt.Errorf("incorrect item type: %T, should be: *EventActivation", item)
}
return eventActivation, nil
}
func (svc *eventActivationService) toEventActivations(items []interface{}) ([]*v1alpha1.EventActivation, error) {
var eventActivations []*v1alpha1.EventActivation
for _, item := range items {
eventActivation, err := svc.toEventActivation(item)
if err != nil {
return nil, err
}
eventActivations = append(eventActivations, eventActivation)
}
return eventActivations, nil
}