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

Method handleSGCollect

rest/admin_api.go:1661–1710  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1659}
1660
1661func (h *handler) handleSGCollect() error {
1662 body, err := h.readBody()
1663 if err != nil {
1664 return err
1665 }
1666
1667 var params SGCollectOptions
1668 if err = base.JSONUnmarshal(body, &params); err != nil {
1669 return base.HTTPErrorf(http.StatusBadRequest, "Unable to parse request body: %v", err)
1670 }
1671
1672 if multiError := params.Validate(); multiError != nil {
1673 return base.HTTPErrorf(http.StatusBadRequest, "Invalid options used for sgcollect_info: %v", multiError)
1674 }
1675
1676 addr, err := h.server.getServerAddr(adminServer)
1677 if err != nil {
1678 return base.HTTPErrorf(http.StatusInternalServerError, "Error getting admin server address: %v", err)
1679 }
1680 if h.server.Config.API.HTTPS.TLSCertPath != "" {
1681 addr = "https://" + addr
1682 } else {
1683 addr = "http://" + addr
1684 }
1685 params.adminURL = addr
1686
1687 zipFilename := SGCollectFilename()
1688
1689 logFilePath := h.server.Config.Logging.LogFilePath
1690
1691 ctx := base.CorrelationIDLogCtx(context.WithoutCancel(h.ctx()), fmt.Sprintf("SGCollect-%03d", h.serialNumber))
1692
1693 if err := h.server.SGCollect.Start(ctx, logFilePath, zipFilename, params); err != nil {
1694 return base.HTTPErrorf(http.StatusInternalServerError, "Error running sgcollect_info: %v", err)
1695 }
1696
1697 h.writeRawJSONStatus(http.StatusOK, []byte(`{"status":"started"}`))
1698
1699 auditFields := base.AuditFields{
1700 "output_dir": params.OutputDirectory,
1701 "upload_host": params.UploadHost,
1702 "customer": params.Customer,
1703 "ticket": params.Ticket,
1704 "keep_zip": params.KeepZip,
1705 "zip_filename": zipFilename,
1706 }
1707 base.Audit(h.ctx(), base.AuditIDSyncGatewayCollectInfoStart, auditFields)
1708
1709 return nil
1710}
1711
1712// ////// USERS & ROLES:
1713

Callers

nothing calls this directly

Calls 11

readBodyMethod · 0.95
ValidateMethod · 0.95
ctxMethod · 0.95
writeRawJSONStatusMethod · 0.95
JSONUnmarshalFunction · 0.92
HTTPErrorfFunction · 0.92
CorrelationIDLogCtxFunction · 0.92
AuditFunction · 0.92
SGCollectFilenameFunction · 0.85
StartMethod · 0.65
getServerAddrMethod · 0.45

Tested by

no test coverage detected