MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / handleDeleteDB

Method handleDeleteDB

rest/admin_api.go:1403–1427  ·  view source on GitHub ↗

handleDeleteDB when running in persistent config mode, deletes a database config from the bucket and removes it from the current node. In non-persistent mode, the endpoint just removes the database from the node.

()

Source from the content-addressed store, hash-verified

1401// handleDeleteDB when running in persistent config mode, deletes a database config from the bucket and removes it from the current node.
1402// In non-persistent mode, the endpoint just removes the database from the node.
1403func (h *handler) handleDeleteDB() error {
1404 h.assertAdminOnly()
1405 dbName := h.PathVar("db")
1406
1407 var bucket string
1408
1409 if h.server.persistentConfig {
1410 bucket, _ = h.server.bucketNameFromDbName(h.ctx(), dbName)
1411 err := h.server.BootstrapContext.DeleteConfig(h.ctx(), bucket, h.server.Config.Bootstrap.ConfigGroupID, dbName)
1412 if err != nil {
1413 return base.HTTPErrorf(http.StatusInternalServerError, "couldn't remove database %q from bucket %q: %s", base.MD(dbName), base.MD(bucket), err.Error())
1414 }
1415 h.server.RemoveDatabase(h.ctx(), dbName, fmt.Sprintf("called from %s", h.rq.URL)) // unhandled 404 to allow broken config deletion (CBG-2420)
1416 h.writeRawJSON([]byte("{}"))
1417 base.Audit(h.ctx(), base.AuditIDDeleteDatabase, nil)
1418 return nil
1419 }
1420
1421 if !h.server.RemoveDatabase(h.ctx(), dbName, fmt.Sprintf("called from %s", h.rq.URL)) {
1422 return base.HTTPErrorf(http.StatusNotFound, "no such database %q", dbName)
1423 }
1424 h.writeRawJSON([]byte("{}"))
1425 base.Audit(h.ctx(), base.AuditIDDeleteDatabase, nil)
1426 return nil
1427}
1428
1429// handleGetRawDoc returns the raw version of the stored document for diagnostic purposes.
1430// It can optionally redact UserData in the sync metadata and allows a custom salt for correlating with collected logs.

Callers

nothing calls this directly

Calls 11

assertAdminOnlyMethod · 0.95
PathVarMethod · 0.95
ctxMethod · 0.95
writeRawJSONMethod · 0.95
HTTPErrorfFunction · 0.92
MDFunction · 0.92
AuditFunction · 0.92
bucketNameFromDbNameMethod · 0.80
RemoveDatabaseMethod · 0.80
DeleteConfigMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected