Skip to content

Commit

Permalink
renamed config, which also returns an array now. interceptor is
Browse files Browse the repository at this point in the history
http.handler
  • Loading branch information
facchettos committed Apr 5, 2024
1 parent 1de06bd commit 6eba18e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ func (m *manager) Register(syncer syncertypes.Base) error {
defer m.m.Unlock()

if int, ok := syncer.(Interceptor); ok {
if _, ok := m.interceptors[int.Config().HandlerName]; ok {
return fmt.Errorf("could not add the interceptor %s because the handler name %s is already in use", int.Name(), int.Config().HandlerName)
for _, rule := range int.InterceptedRequests() {
if _, ok := m.interceptors[rule.HandlerName]; ok {
return fmt.Errorf("could not add the interceptor %s because the handler name %s is already in use", int.Name(), rule.HandlerName)
}
m.interceptors[rule.HandlerName] = int
}
m.interceptors[int.Config().HandlerName] = int.Handler()
} else {
m.syncers = append(m.syncers, syncer)
}
Expand All @@ -217,14 +219,14 @@ func (m *manager) Start() error {

func (m *manager) startInterceptors() error {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handlerName := r.Header.Get("Vcluster-Plugin-Handler-Name")
handlerName := r.Header.Get("VCluster-Plugin-Handler-Name")
if handlerName == "" {
responsewriters.InternalError(w, r, errors.New("header Vcluster-Plugin-Handler-Name wasn't set"))
responsewriters.InternalError(w, r, errors.New("header VCluster-Plugin-Handler-Name wasn't set"))
return
}
interceptorHandler, ok := m.interceptors[handlerName]
if !ok {
responsewriters.InternalError(w, r, errors.New("header Vcluster-Plugin-Handler-Name had no match"))
responsewriters.InternalError(w, r, errors.New("header VCluster-Plugin-Handler-Name had no match"))
return
}
interceptorHandler.ServeHTTP(w, r)
Expand Down

0 comments on commit 6eba18e

Please sign in to comment.