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

Function checkSourceCompatability

pindex_bleve.go:3208–3254  ·  view source on GitHub ↗

----------------------------------------------------------------------------- This API determines if the sourceName provided within the index definition is compatible for FTS indexes by obtaining bucket information from the /pools/default/bucket/{bucketName} endpoint.

(mgr *cbgt.Manager, sourceName string)

Source from the content-addressed store, hash-verified

3206// definition is compatible for FTS indexes by obtaining bucket
3207// information from the /pools/default/bucket/{bucketName} endpoint.
3208func checkSourceCompatability(mgr *cbgt.Manager, sourceName string) error {
3209 if mgr == nil {
3210 return nil
3211 }
3212
3213 if len(sourceName) == 0 {
3214 return fmt.Errorf("source name not provided")
3215 }
3216
3217 url := mgr.Server() + "/pools/default/buckets/" + url.QueryEscape(sourceName)
3218 u, err := cbgt.CBAuthURL(url)
3219 if err != nil {
3220 return err
3221 }
3222
3223 resp, err := HttpGet(cbgt.HttpClient(), u)
3224 if err != nil {
3225 return err
3226 }
3227 defer resp.Body.Close()
3228
3229 respBuf, err := ioutil.ReadAll(resp.Body)
3230 if err != nil {
3231 return err
3232 }
3233
3234 rv := struct {
3235 BucketType string `json:"bucketType"`
3236 StorageBackend string `json:"storageBackend"`
3237 }{}
3238
3239 err = UnmarshalJSON(respBuf, &rv)
3240 if err != nil {
3241 return err
3242 }
3243
3244 if rv.BucketType != "membase" && rv.BucketType != "ephemeral" {
3245 return fmt.Errorf("unsupported bucket type")
3246 }
3247
3248 if rv.BucketType == "membase" && rv.StorageBackend != "couchstore" {
3249 return fmt.Errorf("unsupported storage/backend for bucket: %v",
3250 rv.StorageBackend)
3251 }
3252
3253 return nil
3254}

Callers 1

PrepareIndexDefFunction · 0.85

Calls 2

UnmarshalJSONFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected