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

Function sourceNamesFromReq

rest_auth.go:361–432  ·  view source on GitHub ↗
(mgr definitionLookuper, rp requestParser,
	method, path string)

Source from the content-addressed store, hash-verified

359var errAliasExpansionTooDeep = fmt.Errorf("alias expansion too deep")
360
361func sourceNamesFromReq(mgr definitionLookuper, rp requestParser,
362 method, path string) ([]string, error) {
363 indexName, _ := rp.GetIndexName()
364 _, indexDefsByName, err := mgr.GetIndexDefs(false)
365 if err != nil {
366 return nil, err
367 }
368 if indexName != "" {
369 indexDef, exists := indexDefsByName[indexName]
370 if !exists || indexDef == nil {
371 if method == "PUT" {
372 // Special case where PUT represents an index creation
373 // when there's no indexDef.
374 return findCouchbaseSourceNames(rp, indexName, indexDefsByName)
375 }
376 return nil, errIndexNotFound
377 }
378
379 var sourceNames []string
380 var currSourceNames []string
381 if indexDef.Type == "fulltext-alias" {
382 // this finds the sources in current definition
383 currSourceNames, err = sourceNamesForAlias(indexName, indexDefsByName, 0)
384 if err != nil {
385 return nil, err
386 }
387 sourceNames = append(sourceNames, currSourceNames...)
388 } else {
389 // first use the source in current definition
390 currSourceNames, err = getSourceNamesFromIndexDef(indexDef)
391 if err != nil {
392 return nil, err
393 }
394
395 // get the target collections from the request
396 targetColls, _ := rp.GetCollectionNames()
397
398 // authenticate against all the sourcenames if its a blanket query
399 if len(targetColls) == 0 {
400 return append(sourceNames, currSourceNames...), nil
401 }
402
403 // authenticate only against the given target collections
404 collMap := cbgt.StringsToMap(targetColls)
405 for _, sn := range currSourceNames {
406 pos := strings.LastIndex(sn, ":") + 1
407 if _, found := collMap[sn[pos:]]; found {
408 sourceNames = append(sourceNames, sn)
409 }
410 }
411 }
412
413 return sourceNames, nil
414 }
415
416 pindexName, err := rp.GetPIndexName()
417 if pindexName == "" || err != nil {
418 return nil, fmt.Errorf("missing indexName/pindexName, err: %v", err)

Callers 2

preparePermsFunction · 0.85
TestSourceNamesFromReqFunction · 0.85

Calls 8

findCouchbaseSourceNamesFunction · 0.85
sourceNamesForAliasFunction · 0.85
GetIndexNameMethod · 0.65
GetIndexDefsMethod · 0.65
GetCollectionNamesMethod · 0.65
GetPIndexNameMethod · 0.65
GetPIndexMethod · 0.65

Tested by 1

TestSourceNamesFromReqFunction · 0.68