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

Method CheckSupportedCouchbaseVersion

rest/server_context.go:2215–2275  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

2213}
2214
2215func (sc *ServerContext) CheckSupportedCouchbaseVersion(ctx context.Context) error {
2216 clusterSpec := base.CouchbaseClusterSpec{
2217 Server: sc.Config.Bootstrap.Server,
2218 Username: sc.Config.Bootstrap.Username,
2219 Password: sc.Config.Bootstrap.Password,
2220 X509Certpath: sc.Config.Bootstrap.X509CertPath,
2221 X509Keypath: sc.Config.Bootstrap.X509KeyPath,
2222 CACertpath: sc.Config.Bootstrap.CACertPath,
2223 TLSSkipVerify: base.ValDefault(sc.Config.Bootstrap.ServerTLSSkipVerify, false),
2224 }
2225
2226 securityConfig, err := base.GoCBv2SecurityConfig(ctx, base.Ptr(clusterSpec.TLSSkipVerify), clusterSpec.CACertpath)
2227 if err != nil {
2228 return fmt.Errorf("failed to create security config: %v", err)
2229 }
2230
2231 authenticator, err := base.GoCBv2Authenticator(clusterSpec.Username, clusterSpec.Password, clusterSpec.X509Certpath, clusterSpec.X509Keypath)
2232 if err != nil {
2233 return fmt.Errorf("failed to create authenticator: %v", err)
2234 }
2235
2236 cluster, err := gocb.Connect(clusterSpec.Server,
2237 gocb.ClusterOptions{
2238 Authenticator: authenticator,
2239 SecurityConfig: securityConfig,
2240 })
2241 if err != nil {
2242 return fmt.Errorf("failed to create cluster: %v", err)
2243 }
2244
2245 err = cluster.WaitUntilReady(5*time.Second, &gocb.WaitUntilReadyOptions{
2246 ServiceTypes: []gocb.ServiceType{gocb.ServiceTypeManagement},
2247 })
2248 if err != nil {
2249 return fmt.Errorf("failed to wait for cluster to become ready: %v", err)
2250 }
2251
2252 major, minor, err := base.GetClusterVersion(cluster)
2253 if err != nil {
2254 return fmt.Errorf("failed to get cluster version: %v", err)
2255 }
2256
2257 errMsg := fmt.Sprintf(
2258 "Sync Gateway requires Couchbase Server %d.%d or later, but found cluster version %d.%d",
2259 CBXDCRCompatibleMajorVersion,
2260 CBXDCRCompatibleMinorVersion,
2261 major,
2262 minor,
2263 )
2264
2265 if !base.IsMinimumVersion(uint64(major), uint64(minor), CBXDCRCompatibleMajorVersion, CBXDCRCompatibleMinorVersion) {
2266 base.ErrorfCtx(ctx, "%s", errMsg)
2267 return errors.New(errMsg)
2268 }
2269
2270 err = cluster.Close(&gocb.ClusterCloseOptions{})
2271 if err != nil {
2272 base.WarnfCtx(ctx, "Couldn't close cluster: %v", err)

Callers 1

SetupServerContextFunction · 0.95

Calls 10

ValDefaultFunction · 0.92
GoCBv2SecurityConfigFunction · 0.92
PtrFunction · 0.92
GoCBv2AuthenticatorFunction · 0.92
GetClusterVersionFunction · 0.92
IsMinimumVersionFunction · 0.92
ErrorfCtxFunction · 0.92
WarnfCtxFunction · 0.92
ErrorfMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected