Пример #1
0
func sourceNamesFromReq(mgr definitionLookuper, req *http.Request,
	method, path string) ([]string, error) {
	sourceNames := make([]string, 0)
	indexName := rest.IndexNameLookup(req)
	if indexName != "" {
		_, indexDefsByName, err := mgr.GetIndexDefs(false)
		if err != nil {
			return nil, err
		}

		indexDef, exists := indexDefsByName[indexName]
		if !exists || indexDef == nil {
			if method == "PUT" {
				// Special case where PUT can mean CREATE, which
				// we assume when there's no indexDef.
				return sourceNamesFromReq(mgr, req, "CREATE", path)
			} else if method == "CREATE" {
				sourceName, err := findCouchbaseSourceName(req, indexName)
				if err != nil {
					return nil, err
				}
				sourceNames = append(sourceNames, sourceName)
				return sourceNames, nil
			} else {
				return nil, errIndexNotFound
			}
		}

		if indexDef.Type == "fulltext-alias" {
			// per MB-18868 only expand alias sources for these specific requests
			if (req.Method == http.MethodGet &&
				strings.HasSuffix(path, "/count")) ||
				(req.Method == http.MethodPost &&
					strings.HasSuffix(path, "/query")) {
				aliasSourceNames, err := sourceNamesForAlias(indexName, indexDefsByName, 0)
				if err != nil {
					return nil, err
				}
				sourceNames = append(sourceNames, aliasSourceNames...)
			}
		} else {
			sourceNames = append(sourceNames, indexDef.SourceName)
		}
	} else {
		pindexName := rest.PIndexNameLookup(req)
		if pindexName != "" {
			pindex := mgr.GetPIndex(pindexName)
			if pindex == nil {
				return nil, errPIndexNotFound
			}

			sourceNames = append(sourceNames, pindex.SourceName)
		} else {
			return nil, fmt.Errorf("missing indexName/pindexName")
		}
	}

	return sourceNames, nil
}
Пример #2
0
func GetAuditEventData(eventId uint32, req *http.Request) interface{} {
	switch eventId {
	case AuditDeleteIndexEvent, AuditCreateUpdateIndexEvent:
		indexName := rest.IndexNameLookup(req)
		d := IndexAuditLog{
			GenericFields: audit.GetAuditBasicFields(req),
			IndexName:     indexName,
		}
		return d
	case AuditConfigReplanEvent, AuditRunGCEvent,
		AuditProfileCPUEvent, AuditProfileMemoryEvent:
		return audit.GetAuditBasicFields(req)
	case AuditControlEvent:
		indexName := rest.IndexNameLookup(req)
		d := IndexControlAuditLog{
			GenericFields: audit.GetAuditBasicFields(req),
			IndexName:     indexName,
			Control:       rest.MuxVariableLookup(req, "op"),
		}
		return d
	}
	return nil
}