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

Method handleDeleteCollectionConfigSync

rest/admin_api.go:1104–1160  ·  view source on GitHub ↗

DELETE a collection sync function

()

Source from the content-addressed store, hash-verified

1102
1103// DELETE a collection sync function
1104func (h *handler) handleDeleteCollectionConfigSync() error {
1105 h.assertAdminOnly()
1106
1107 if !h.server.persistentConfig {
1108 return base.HTTPErrorf(http.StatusBadRequest, "endpoint only supports persistent config mode")
1109 }
1110
1111 bucket := h.db.Bucket.GetName()
1112 var updatedConfigStr string
1113 var updatedDbConfig *DatabaseConfig
1114 cas, err := h.server.BootstrapContext.UpdateConfig(h.ctx(), bucket, h.server.Config.Bootstrap.ConfigGroupID, h.db.Name, func(bucketDbConfig *DatabaseConfig) (updatedConfig *DatabaseConfig, err error) {
1115 if h.headerDoesNotMatchEtag(bucketDbConfig.Version) {
1116 return nil, base.HTTPErrorf(http.StatusPreconditionFailed, "Provided If-Match header does not match current config version")
1117 }
1118 if bucketDbConfig.Scopes != nil {
1119 config := bucketDbConfig.Scopes[h.collection.ScopeName].Collections[h.collection.Name]
1120 config.SyncFn = nil
1121 bucketDbConfig.Scopes[h.collection.ScopeName].Collections[h.collection.Name] = config
1122 updatedConfigStr = fmt.Sprintf(`{"scopes": {"%s": {"collections": { "%s": { "sync": null}}}}}`, h.collection.ScopeName, h.collection.Name)
1123 } else if base.IsDefaultCollection(h.collection.ScopeName, h.collection.Name) {
1124 bucketDbConfig.Sync = nil
1125 updatedConfigStr = `{"sync": null}`
1126 }
1127
1128 bucketDbConfig.Version, err = GenerateDatabaseConfigVersionID(h.ctx(), bucketDbConfig.Version, &bucketDbConfig.DbConfig)
1129 if err != nil {
1130 return nil, err
1131 }
1132
1133 bucketDbConfig.SGVersion = base.ProductVersion.String()
1134 updatedDbConfig = bucketDbConfig
1135
1136 return bucketDbConfig, nil
1137 })
1138 if err != nil {
1139 return err
1140 }
1141 updatedDbConfig.cfgCas = cas
1142
1143 dbName := h.db.Name
1144 dbCreds, _ := h.server.Config.DatabaseCredentials[dbName]
1145 bucketCreds, _ := h.server.Config.BucketCredentials[bucket]
1146 if err := updatedDbConfig.setup(h.ctx(), dbName, h.server.Config.Bootstrap, dbCreds, bucketCreds, h.server.Config.IsServerless()); err != nil {
1147 return err
1148 }
1149
1150 h.server._databasesLock.Lock()
1151 defer h.server._databasesLock.Unlock()
1152
1153 // TODO: Dynamic update instead of reload
1154 if err := h.server._reloadDatabaseWithConfig(h.ctx(), *updatedDbConfig, false, false); err != nil {
1155 return err
1156 }
1157
1158 base.Audit(h.ctx(), base.AuditIDUpdateDatabaseConfig, base.AuditFields{base.AuditFieldPayload: updatedConfigStr})
1159 return base.HTTPErrorf(http.StatusOK, "sync function removed")
1160}
1161

Callers

nothing calls this directly

Calls 15

assertAdminOnlyMethod · 0.95
ctxMethod · 0.95
HTTPErrorfFunction · 0.92
IsDefaultCollectionFunction · 0.92
AuditFunction · 0.92
setupMethod · 0.80
IsServerlessMethod · 0.80
GetNameMethod · 0.65
UpdateConfigMethod · 0.65

Tested by

no test coverage detected