Skip to content

Commit

Permalink
mgmtapi: support deleting segments and beacons (scionproto#4465)
Browse files Browse the repository at this point in the history
Support deleting segments and beacons via the management API of the
control and daemon service. This is useful for cleaning up the databases
(e.g., in case the issue mentioned in scionproto#4286 occurs)
  • Loading branch information
oncilla authored Feb 15, 2024
1 parent fce093e commit b344703
Show file tree
Hide file tree
Showing 27 changed files with 1,103 additions and 125 deletions.
26 changes: 26 additions & 0 deletions control/mgmtapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (

type BeaconStore interface {
GetBeacons(context.Context, *beaconstorage.QueryParams) ([]beaconstorage.Beacon, error)
DeleteBeacon(ctx context.Context, idPrefix string) error
}

type Healther interface {
Expand Down Expand Up @@ -378,6 +379,27 @@ func (s *Server) GetBeacon(w http.ResponseWriter, r *http.Request, segmentId Seg
}
}

func (s *Server) DeleteBeacon(w http.ResponseWriter, r *http.Request, segmentId SegmentID) {
if segmentId == "" {
ErrorResponse(w, Problem{
Status: http.StatusBadRequest,
Title: "segment ID is required",
Type: api.StringRef(api.BadRequest),
})
return
}
if err := s.Beacons.DeleteBeacon(r.Context(), segmentId); err != nil {
ErrorResponse(w, Problem{
Detail: api.StringRef(err.Error()),
Status: http.StatusInternalServerError,
Title: "unable to delete beacon",
Type: api.StringRef(api.InternalError),
})
return
}
w.WriteHeader(http.StatusNoContent)
}

func (s *Server) GetBeaconBlob(w http.ResponseWriter, r *http.Request, segmentId SegmentID) {
w.Header().Set("Content-Type", "application/x-pem-file")

Expand Down Expand Up @@ -471,6 +493,10 @@ func (s *Server) GetSegment(w http.ResponseWriter, r *http.Request, id SegmentID
s.SegmentsServer.GetSegment(w, r, id)
}

func (s *Server) DeleteSegment(w http.ResponseWriter, r *http.Request, id SegmentID) {
s.SegmentsServer.DeleteSegment(w, r, id)
}

func (s *Server) GetSegmentBlob(w http.ResponseWriter, r *http.Request, id SegmentID) {
s.SegmentsServer.GetSegmentBlob(w, r, id)
}
Expand Down
234 changes: 234 additions & 0 deletions control/mgmtapi/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions control/mgmtapi/mock_mgmtapi/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b344703

Please sign in to comment.