MCPcopy Create free account
hub / github.com/couchbase/cbft / ServeHTTP

Method ServeHTTP

rest_backup_restore.go:77–112  ·  view source on GitHub ↗
(
	w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

75}
76
77func (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
114func restoreIndexDefs(indexDefs *cbgt.IndexDefs, cfg cbgt.Cfg) error {
115 curIndexDefs, cas, err := cbgt.CfgGetIndexDefs(cfg)

Callers

nothing calls this directly

Calls 2

processRemapRequestFunction · 0.85
restoreIndexDefsFunction · 0.85

Tested by

no test coverage detected