generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 7
/
processor.go
63 lines (53 loc) · 1.75 KB
/
processor.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
51
52
53
54
55
56
57
58
59
60
61
62
63
package subscribed
import (
"net/http"
"github.com/kyma-project/eventing-publisher-proxy/pkg/legacy"
"go.uber.org/zap"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
"github.com/kyma-project/eventing-manager/pkg/logger"
)
const processorName = "processor"
type Processor struct {
SubscriptionLister *cache.GenericLister
Prefix string
Namespace string
Logger *logger.Logger
}
func (p Processor) extractEventsFromSubscriptions(
writer http.ResponseWriter,
request *http.Request,
) {
eventsMap := make(map[Event]bool)
subsList, err := (*p.SubscriptionLister).List(labels.Everything())
if err != nil {
p.namedLogger().Errorw("Failed to fetch subscriptions", "error", err)
RespondWithErrorAndLog(err, writer)
return
}
appName := legacy.ParseApplicationNameFromPath(request.URL.Path)
for _, sObj := range subsList {
sub, err := ConvertRuntimeObjToSubscription(sObj)
if err != nil {
p.namedLogger().Errorw("Failed to convert a runtime obj to a Subscription", "error", err)
continue
}
if sub.Spec.Types != nil {
eventsForSub := FilterEventTypeVersions(p.Prefix, appName, sub)
eventsMap = AddUniqueEventsToResult(eventsForSub, eventsMap)
}
}
events := ConvertEventsMapToSlice(eventsMap)
RespondWithBody(writer, Events{
EventsInfo: events,
}, http.StatusOK)
}
func (p Processor) ExtractEventsFromSubscriptions(writer http.ResponseWriter, request *http.Request) {
p.extractEventsFromSubscriptions(writer, request)
}
func (p Processor) ExtractEventsFromSubscriptionsV1alpha1(writer http.ResponseWriter, request *http.Request) {
p.extractEventsFromSubscriptions(writer, request)
}
func (p Processor) namedLogger() *zap.SugaredLogger {
return p.Logger.WithContext().Named(processorName)
}