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

Method validateChanges

rest/config.go:726–748  ·  view source on GitHub ↗

validateChanges compares the current DbConfig with the "old" config, and returns an error if any disallowed changes are attempted.

(ctx context.Context, old DbConfig)

Source from the content-addressed store, hash-verified

724// validateChanges compares the current DbConfig with the "old" config, and returns an error if any disallowed changes
725// are attempted.
726func (dbConfig *DbConfig) validateChanges(ctx context.Context, old DbConfig) error {
727 // allow switching from implicit `_default` to explicit `_default` scope
728 _, newIsDefaultScope := dbConfig.Scopes[base.DefaultScope]
729 if old.Scopes == nil && len(dbConfig.Scopes) == 1 && newIsDefaultScope {
730 return nil
731 }
732 // early exit
733 if len(dbConfig.Scopes) != len(old.Scopes) {
734 return fmt.Errorf("cannot change scopes after database creation")
735 }
736 newScopes := make(base.Set, len(dbConfig.Scopes))
737 oldScopes := make(base.Set, len(old.Scopes))
738 for scopeName := range dbConfig.Scopes {
739 newScopes.Add(scopeName)
740 }
741 for scopeName := range old.Scopes {
742 oldScopes.Add(scopeName)
743 }
744 if !newScopes.Equals(oldScopes) {
745 return fmt.Errorf("cannot change scopes after database creation")
746 }
747 return nil
748}
749
750// validate checks the DbConfig for any invalid or unsupported values and return a http error. If validateReplications is true, return an error if any replications are not valid. Otherwise issue a warning.
751func (dbConfig *DbConfig) validate(ctx context.Context, validateOIDCConfig, validateReplications bool) error {

Callers 1

validateConfigUpdateMethod · 0.95

Calls 3

ErrorfMethod · 0.80
AddMethod · 0.45
EqualsMethod · 0.45

Tested by

no test coverage detected