|
6 | 6 | "context" |
7 | 7 | "encoding/json" |
8 | 8 | "net/http" |
| 9 | + "strconv" |
9 | 10 |
|
10 | 11 | "github.com/go-chi/chi/v5" |
11 | 12 | "github.com/go-chi/render" |
@@ -42,6 +43,7 @@ func newBackupHandler(services Services) *chi.Mux { |
42 | 43 | m.Get("/files", h.listFiles) |
43 | 44 | }) |
44 | 45 | m.Get("/schema", h.describeSchema) |
| 46 | + m.Delete("/cleanup", h.cleanup) |
45 | 47 |
|
46 | 48 | return m |
47 | 49 | } |
@@ -250,6 +252,32 @@ func (h backupHandler) describeSchema(w http.ResponseWriter, r *http.Request) { |
250 | 252 | render.Respond(w, r, convertSchema(cqlSchema)) |
251 | 253 | } |
252 | 254 |
|
| 255 | +func (h backupHandler) cleanup(w http.ResponseWriter, r *http.Request) { |
| 256 | + cluster := mustClusterFromCtx(r) |
| 257 | + |
| 258 | + var ( |
| 259 | + deleteDiskSnapshots bool |
| 260 | + err error |
| 261 | + ) |
| 262 | + if v := r.URL.Query().Get("delete_disk_snapshots"); v != "" { |
| 263 | + deleteDiskSnapshots, err = strconv.ParseBool(v) |
| 264 | + if err != nil { |
| 265 | + respondBadRequest(w, r, util.ErrValidate(errors.Wrap(err, "parse delete_disk_snapshots"))) |
| 266 | + return |
| 267 | + } |
| 268 | + } |
| 269 | + if !deleteDiskSnapshots { |
| 270 | + respondBadRequest(w, r, util.ErrValidate(errors.New("no cleanup specified"))) |
| 271 | + return |
| 272 | + } |
| 273 | + |
| 274 | + if err := h.svc.Cleanup(r.Context(), cluster.ID); err != nil { |
| 275 | + respondError(w, r, errors.Wrap(err, "perform cleanup")) |
| 276 | + return |
| 277 | + } |
| 278 | + w.WriteHeader(http.StatusOK) |
| 279 | +} |
| 280 | + |
253 | 281 | func parseOptionalUUID(v string) (uuid.UUID, error) { |
254 | 282 | if v == "" { |
255 | 283 | return uuid.Nil, nil |
|
0 commit comments