MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / setup

Method setup

rest/config.go:465–551  ·  view source on GitHub ↗

setup populates fields in the dbConfig

(ctx context.Context, dbName string, bootstrapConfig BootstrapConfig, dbCredentials, bucketCredentials *base.CredentialsConfig, forcePerBucketAuth bool)

Source from the content-addressed store, hash-verified

463
464// setup populates fields in the dbConfig
465func (dbConfig *DbConfig) setup(ctx context.Context, dbName string, bootstrapConfig BootstrapConfig, dbCredentials, bucketCredentials *base.CredentialsConfig, forcePerBucketAuth bool) error {
466 dbConfig.Name = dbName
467
468 // use db name as bucket if absent from config (handling for old non-stamped configs)
469 if dbConfig.Bucket == nil {
470 dbConfig.Bucket = &dbConfig.Name
471 }
472
473 dbConfig.inheritFromBootstrap(bootstrapConfig)
474 if bucketCredentials != nil {
475 dbConfig.setDatabaseCredentials(*bucketCredentials)
476 } else if forcePerBucketAuth {
477 return fmt.Errorf("unable to setup database on bucket %q since credentials are not defined in bucket_credentials", base.MD(*dbConfig.Bucket).Redact())
478 }
479 // Per db credentials override bootstrap and bucket level credentials
480 if dbCredentials != nil {
481 dbConfig.setDatabaseCredentials(*dbCredentials)
482 }
483
484 if dbConfig.Server != nil {
485 url, err := url.Parse(*dbConfig.Server)
486 if err != nil {
487 return err
488 }
489 if url.User != nil {
490 // Remove credentials from URL and put them into the DbConfig.Username and .Password:
491 if dbConfig.Username == "" {
492 dbConfig.Username = url.User.Username()
493 }
494 if dbConfig.Password == "" {
495 if password, exists := url.User.Password(); exists {
496 dbConfig.Password = password
497 }
498 }
499 url.User = nil
500 urlStr := url.String()
501 dbConfig.Server = &urlStr
502 }
503
504 }
505 insecureSkipVerify := false
506 if dbConfig.Unsupported != nil {
507 insecureSkipVerify = dbConfig.Unsupported.RemoteConfigTlsSkipVerify
508 }
509
510 // Load Sync Function.
511 if dbConfig.Sync != nil {
512 sync, err := loadJavaScript(ctx, *dbConfig.Sync, insecureSkipVerify)
513 if err != nil {
514 return &JavaScriptLoadError{
515 JSLoadType: SyncFunction,
516 Path: *dbConfig.Sync,
517 Err: err,
518 }
519 }
520 dbConfig.Sync = &sync
521 }
522 // Load Import Filter Function.

Calls 7

inheritFromBootstrapMethod · 0.95
MDFunction · 0.92
loadJavaScriptFunction · 0.85
ErrorfMethod · 0.80
RedactMethod · 0.65
StringMethod · 0.65