Class: Couchbase::Protostellar::Cluster Private

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/protostellar/cluster.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

VALID_CONNECTION_STRING_PARAMS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[
  "trust_certificate",
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/couchbase/protostellar/cluster.rb', line 26

def client
  @client
end

Class Method Details

.connect(connection_string, options) ⇒ Object .connect(connection_string, username, password, options) ⇒ Object .connect(configuration, options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Connect to the Couchbase cluster

Overloads:

  • .connect(connection_string, options) ⇒ Object

    Parameters:

    • connection_string (String)

      connection string used to locate the Couchbase Cluster

    • options (Options::Cluster)

      custom options when creating the cluster connection

  • .connect(connection_string, username, password, options) ⇒ Object

    Parameters:

    • connection_string (String)

      connection string used to locate the Couchbase Cluster

    • username (String)

      name of the user

    • password (String)

      password of the user

    • options (Options::Cluster, nil)

      custom options when creating the cluster connection

  • .connect(configuration, options) ⇒ Object

    Parameters:

Raises:

  • (ArgumentError)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/couchbase/protostellar/cluster.rb', line 44

def self.connect(connection_string_or_config, *args)
  require_relative "connect_options"
  require_relative "bucket"
  require_relative "client"
  require_relative "timeouts"
  require_relative "management/bucket_manager"
  require_relative "request_generator/query"
  require_relative "request_generator/search"
  require_relative "response_converter/query"
  require_relative "response_converter/search"
  require_relative "management/query_index_manager"

  connection_string = nil
  username = nil
  password = nil
  options = nil

  if connection_string_or_config.is_a?(Couchbase::Configuration)
    connection_string = connection_string_or_config.connection_string
    username = connection_string_or_config.username
    password = connection_string_or_config.password
    options = args[0] || Couchbase::Options::Cluster.new
  else
    connection_string = connection_string_or_config
    case args[0]
    when String
      username = args[0]
      password = args[1]
      options = args[2] || Couchbase::Options::Cluster.new
    when Couchbase::Options::Cluster
      options = args[0]
      case options.authenticator
      when Couchbase::PasswordAuthenticator
        username = options.authenticator.username
        password = options.authenticator.password
      when Couchbase::CertificateAuthenticator
        raise Couchbase::Error::FeatureNotAvailable,
              "The #{Couchbase::Protostellar::NAME} protocol does not support the CertificateAuthenticator"
      else
        raise ArgumentError, "options must have authenticator configured"
      end
    else
      raise ArgumentError, "unexpected second argument, have to be String or Couchbase::Options::Cluster"
    end
  end

  raise ArgumentError, "missing username" unless username
  raise ArgumentError, "missing password" unless password

  params = parse_connection_string_params(connection_string)
  connect_options = ConnectOptions.new(
    username: username,
    password: password,
    timeouts: Protostellar::Timeouts.from_cluster_options(options),
    root_certificates: params.key?("trust_certificate") ? File.read(params["trust_certificate"]) : nil
  )
  new(connection_string.split("://")[1].split("?")[0], connect_options)
end

.parse_connection_string_params(connection_string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/couchbase/protostellar/cluster.rb', line 103

def self.parse_connection_string_params(connection_string)
  params =
    if connection_string.include?("?")
      connection_string.split("?")[1].split("&").to_h { |p| p.split("=") }
    else
      {}
    end

  # Show warnings for the connection string parameters that are not supported
  params.each do |k, v|
    warn "Unsupported parameter '#{k}' in connection string (value '#{v}')" unless VALID_CONNECTION_STRING_PARAMS.include?(k)
  end

  params
end

Instance Method Details

#bucket(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



123
124
125
# File 'lib/couchbase/protostellar/cluster.rb', line 123

def bucket(name)
  Bucket.new(@client, name)
end

#bucketsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



127
128
129
# File 'lib/couchbase/protostellar/cluster.rb', line 127

def buckets
  Management::BucketManager.new(@client)
end

#diagnostics(_options = Options::Diagnostics::DEFAULT) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



147
148
149
# File 'lib/couchbase/protostellar/cluster.rb', line 147

def diagnostics(_options = Options::Diagnostics::DEFAULT)
  raise Couchbase::Error::FeatureNotAvailable, "The #{Protostellar::NAME} protocol does not support diagnostics"
end

#disconnectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



119
120
121
# File 'lib/couchbase/protostellar/cluster.rb', line 119

def disconnect
  @client.close
end

#ping(_options = Options::Ping::DEFAULT) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



151
152
153
# File 'lib/couchbase/protostellar/cluster.rb', line 151

def ping(_options = Options::Ping::DEFAULT)
  raise Couchbase::Error::FeatureNotAvailable, "The #{Protostellar::NAME} protocol does not support ping"
end

#query(statement, options = Couchbase::Options::Query::DEFAULT) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



135
136
137
138
139
# File 'lib/couchbase/protostellar/cluster.rb', line 135

def query(statement, options = Couchbase::Options::Query::DEFAULT)
  req = @query_request_generator.query_request(statement, options)
  resps = @client.send_request(req)
  ResponseConverter::Query.to_query_result(resps)
end

#query_indexesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



131
132
133
# File 'lib/couchbase/protostellar/cluster.rb', line 131

def query_indexes
  Management::QueryIndexManager.new(client: @client)
end

#search_query(index_name, query, options = Couchbase::Options::Search::DEFAULT) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



141
142
143
144
145
# File 'lib/couchbase/protostellar/cluster.rb', line 141

def search_query(index_name, query, options = Couchbase::Options::Search::DEFAULT)
  req = @search_request_generator.search_query_request(index_name, query, options)
  resp = @client.send_request(req)
  ResponseConverter::Search.to_search_result(resp, options)
end