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

Function getSourceNamesFromIndexDef

rest_auth.go:212–259  ·  view source on GitHub ↗
(indexDef *cbgt.IndexDef)

Source from the content-addressed store, hash-verified

210}
211
212func getSourceNamesFromIndexDef(indexDef *cbgt.IndexDef) ([]string, error) {
213 if len(indexDef.Params) > 0 {
214 bleveParamBytes := []byte(indexDef.Params)
215 docConfig, _, _, err := jsonparser.Get(bleveParamBytes, "doc_config")
216 if err != nil {
217 // couldn't find doc_config to detect the mode
218 return []string{indexDef.SourceName}, nil
219 }
220
221 docConfigMode, _, _, _ := jsonparser.Get(docConfig, "mode")
222 if strings.HasPrefix(string(docConfigMode), ConfigModeCollPrefix) {
223 // look up the scope/collection details from the cache.
224 scopeName, collectionNames := metaFieldValCache.getScopeCollectionNames(indexDef.Name)
225 if len(scopeName) > 0 && len(collectionNames) > 0 {
226 sourceNames := make([]string, len(collectionNames))
227 for i := range collectionNames {
228 sourceNames[i] = indexDef.SourceName + ":" + scopeName + ":" + collectionNames[i]
229 }
230 return sourceNames, nil
231 }
232
233 // parse it again if the cache is empty like that in a unit test.
234 bmapping, _, _, err := jsonparser.Get(bleveParamBytes, "mapping")
235 if err != nil {
236 return nil, err
237 }
238
239 mapping := bleve.NewIndexMapping()
240 err = UnmarshalJSON(bmapping, mapping)
241 if err != nil {
242 return nil, err
243 }
244
245 sName, colNames, _, err := getScopeCollTypeMappings(mapping, true)
246 if err != nil {
247 return nil, err
248 }
249
250 sourceNames := make([]string, len(colNames))
251 for i, colName := range colNames {
252 sourceNames[i] = indexDef.SourceName + ":" + sName + ":" + colName
253 }
254 return sourceNames, nil
255 }
256 }
257
258 return []string{indexDef.SourceName}, nil
259}
260
261// an interface to abstract the bare minimum aspect of a cbgt.Manager
262// that we need, so that we can stub the interface for testing

Callers 4

sourceNamesForAliasFunction · 0.85
sourceNamesFromReqFunction · 0.85
findCouchbaseSourceNamesFunction · 0.85
ServeHTTPMethod · 0.85

Calls 4

UnmarshalJSONFunction · 0.85
getScopeCollTypeMappingsFunction · 0.85
GetMethod · 0.80

Tested by

no test coverage detected