gateway: add delete remote source handler
This commit is contained in:
parent
c9fb7258ec
commit
c523bcba4e
|
@ -178,3 +178,28 @@ func (h *RemoteSourcesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,6 +182,7 @@ func (g *Gateway) Run(ctx context.Context) error {
|
|||
remoteSourceHandler := api.NewRemoteSourceHandler(logger, g.ah)
|
||||
createRemoteSourceHandler := api.NewCreateRemoteSourceHandler(logger, g.ah)
|
||||
remoteSourcesHandler := api.NewRemoteSourcesHandler(logger, g.ah)
|
||||
deleteRemoteSourceHandler := api.NewDeleteRemoteSourceHandler(logger, g.ah)
|
||||
|
||||
orgHandler := api.NewOrgHandler(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", authForcedHandler(createRemoteSourceHandler)).Methods("POST")
|
||||
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", authForcedHandler(orgsHandler)).Methods("GET")
|
||||
|
|
Loading…
Reference in New Issue