| 359 | var errAliasExpansionTooDeep = fmt.Errorf("alias expansion too deep") |
| 360 | |
| 361 | func 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) |