gateway: add delete remote source handler

This commit is contained in:
Simone Gotti 2019-05-10 00:03:03 +02:00
parent c9fb7258ec
commit c523bcba4e
2 changed files with 27 additions and 0 deletions

View File

@ -178,3 +178,28 @@ func (h *RemoteSourcesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
h.log.Errorf("err: %+v", err) h.log.Errorf("err: %+v", err)
} }
} }
type DeleteRemoteSourceHandler struct {
log *zap.SugaredLogger
ah *action.ActionHandler
}
func NewDeleteRemoteSourceHandler(logger *zap.Logger, ah *action.ActionHandler) *DeleteRemoteSourceHandler {
return &DeleteRemoteSourceHandler{log: logger.Sugar(), ah: ah}
}
func (h *DeleteRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
rsRef := vars["remotesourceref"]
err := h.ah.DeleteRemoteSource(ctx, rsRef)
if httpError(w, err) {
h.log.Errorf("err: %+v", err)
return
}
if err := httpResponse(w, http.StatusNoContent, nil); err != nil {
h.log.Errorf("err: %+v", err)
}
}

View File

@ -182,6 +182,7 @@ func (g *Gateway) Run(ctx context.Context) error {
remoteSourceHandler := api.NewRemoteSourceHandler(logger, g.ah) remoteSourceHandler := api.NewRemoteSourceHandler(logger, g.ah)
createRemoteSourceHandler := api.NewCreateRemoteSourceHandler(logger, g.ah) createRemoteSourceHandler := api.NewCreateRemoteSourceHandler(logger, g.ah)
remoteSourcesHandler := api.NewRemoteSourcesHandler(logger, g.ah) remoteSourcesHandler := api.NewRemoteSourcesHandler(logger, g.ah)
deleteRemoteSourceHandler := api.NewDeleteRemoteSourceHandler(logger, g.ah)
orgHandler := api.NewOrgHandler(logger, g.ah) orgHandler := api.NewOrgHandler(logger, g.ah)
orgsHandler := api.NewOrgsHandler(logger, g.ah) orgsHandler := api.NewOrgsHandler(logger, g.ah)
@ -259,6 +260,7 @@ func (g *Gateway) Run(ctx context.Context) error {
apirouter.Handle("/remotesources/{remotesourceref}", authForcedHandler(remoteSourceHandler)).Methods("GET") apirouter.Handle("/remotesources/{remotesourceref}", authForcedHandler(remoteSourceHandler)).Methods("GET")
apirouter.Handle("/remotesources", authForcedHandler(createRemoteSourceHandler)).Methods("POST") apirouter.Handle("/remotesources", authForcedHandler(createRemoteSourceHandler)).Methods("POST")
apirouter.Handle("/remotesources", authOptionalHandler(remoteSourcesHandler)).Methods("GET") apirouter.Handle("/remotesources", authOptionalHandler(remoteSourcesHandler)).Methods("GET")
apirouter.Handle("/remotesources/{remotesourceref}", authForcedHandler(deleteRemoteSourceHandler)).Methods("DELETE")
apirouter.Handle("/orgs/{orgref}", authForcedHandler(orgHandler)).Methods("GET") apirouter.Handle("/orgs/{orgref}", authForcedHandler(orgHandler)).Methods("GET")
apirouter.Handle("/orgs", authForcedHandler(orgsHandler)).Methods("GET") apirouter.Handle("/orgs", authForcedHandler(orgsHandler)).Methods("GET")