( w http.ResponseWriter, req *http.Request)
| 75 | } |
| 76 | |
| 77 | func (h *BucketRestoreIndexHandler) ServeHTTP( |
| 78 | w http.ResponseWriter, req *http.Request) { |
| 79 | bucketName := rest.BucketNameLookup(req) |
| 80 | if bucketName == "" { |
| 81 | rest.ShowError(w, req, "rest_backup_restore: bucket name is required", |
| 82 | http.StatusBadRequest) |
| 83 | return |
| 84 | } |
| 85 | // parse and process the request body. |
| 86 | indexDefs, err := processRemapRequest(req, bucketName) |
| 87 | if err != nil { |
| 88 | rest.ShowError(w, req, fmt.Sprintf("rest_backup_restore: processRemapRequest failed,"+ |
| 89 | " for bucket: %s, err: %v", bucketName, err), http.StatusBadRequest) |
| 90 | return |
| 91 | } |
| 92 | |
| 93 | // restore the remapped index definitions to the Cfg. |
| 94 | err = restoreIndexDefs(indexDefs, h.mgr.Cfg()) |
| 95 | if err != nil { |
| 96 | rest.ShowError(w, req, fmt.Sprintf("rest_backup_restore: "+ |
| 97 | "restoreIndexDefs failed for bucket: %s, err: %v", bucketName, |
| 98 | err), http.StatusBadRequest) |
| 99 | return |
| 100 | } |
| 101 | |
| 102 | // send the remapped index definitions alone to the caller for |
| 103 | // any verification purposes. |
| 104 | rv := struct { |
| 105 | Status string `json:"status"` |
| 106 | IndexDefs *cbgt.IndexDefs `json:"indexDefs"` |
| 107 | }{ |
| 108 | Status: "ok", |
| 109 | IndexDefs: indexDefs, |
| 110 | } |
| 111 | rest.MustEncode(w, rv) |
| 112 | } |
| 113 | |
| 114 | func restoreIndexDefs(indexDefs *cbgt.IndexDefs, cfg cbgt.Cfg) error { |
| 115 | curIndexDefs, cas, err := cbgt.CfgGetIndexDefs(cfg) |
nothing calls this directly
no test coverage detected