()
| 1160 | } |
| 1161 | |
| 1162 | func (h *handler) handlePutCollectionConfigSync() error { |
| 1163 | h.assertAdminOnly() |
| 1164 | |
| 1165 | if !h.server.persistentConfig { |
| 1166 | return base.HTTPErrorf(http.StatusBadRequest, "endpoint only supports persistent config mode") |
| 1167 | } |
| 1168 | |
| 1169 | js, err := h.readJavascript() |
| 1170 | if err != nil { |
| 1171 | return err |
| 1172 | } |
| 1173 | |
| 1174 | bucket := h.db.Bucket.GetName() |
| 1175 | dbName := h.db.Name |
| 1176 | |
| 1177 | var updatedConfigStr string |
| 1178 | var updatedDbConfig *DatabaseConfig |
| 1179 | cas, err := h.server.BootstrapContext.UpdateConfig(h.ctx(), bucket, h.server.Config.Bootstrap.ConfigGroupID, dbName, func(bucketDbConfig *DatabaseConfig) (updatedConfig *DatabaseConfig, err error) { |
| 1180 | if h.headerDoesNotMatchEtag(bucketDbConfig.Version) { |
| 1181 | return nil, base.HTTPErrorf(http.StatusPreconditionFailed, "Provided If-Match header does not match current config version") |
| 1182 | } |
| 1183 | |
| 1184 | if bucketDbConfig.Scopes != nil { |
| 1185 | config := bucketDbConfig.Scopes[h.collection.ScopeName].Collections[h.collection.Name] |
| 1186 | config.SyncFn = &js |
| 1187 | bucketDbConfig.Scopes[h.collection.ScopeName].Collections[h.collection.Name] = config |
| 1188 | updatedConfigStr = fmt.Sprintf(`{"scopes": {"%s": {"collections": { "%s": { "sync": "%s"}}}}}`, h.collection.ScopeName, h.collection.Name, js) |
| 1189 | } else if base.IsDefaultCollection(h.collection.ScopeName, h.collection.Name) { |
| 1190 | bucketDbConfig.Sync = &js |
| 1191 | updatedConfigStr = fmt.Sprintf(`{"sync": "%s"}`, js) |
| 1192 | } |
| 1193 | |
| 1194 | validateReplications := false |
| 1195 | if err := bucketDbConfig.validate(h.ctx(), !h.getBoolQuery(paramDisableOIDCValidation), validateReplications); err != nil { |
| 1196 | return nil, base.NewHTTPError(http.StatusBadRequest, err.Error()) |
| 1197 | } |
| 1198 | |
| 1199 | bucketDbConfig.Version, err = GenerateDatabaseConfigVersionID(h.ctx(), bucketDbConfig.Version, &bucketDbConfig.DbConfig) |
| 1200 | if err != nil { |
| 1201 | return nil, err |
| 1202 | } |
| 1203 | |
| 1204 | bucketDbConfig.SGVersion = base.ProductVersion.String() |
| 1205 | updatedDbConfig = bucketDbConfig |
| 1206 | return bucketDbConfig, nil |
| 1207 | }) |
| 1208 | if err != nil { |
| 1209 | return err |
| 1210 | } |
| 1211 | updatedDbConfig.cfgCas = cas |
| 1212 | |
| 1213 | dbCreds, _ := h.server.Config.DatabaseCredentials[dbName] |
| 1214 | bucketCreds, _ := h.server.Config.BucketCredentials[bucket] |
| 1215 | if err := updatedDbConfig.setup(h.ctx(), dbName, h.server.Config.Bootstrap, dbCreds, bucketCreds, h.server.Config.IsServerless()); err != nil { |
| 1216 | return err |
| 1217 | } |
| 1218 | |
| 1219 | h.server._databasesLock.Lock() |
nothing calls this directly
no test coverage detected