yugabyte-ycql-driver 3.2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +13 -0
- data/README.md +242 -0
- data/ext/cassandra_murmur3/cassandra_murmur3.c +178 -0
- data/ext/cassandra_murmur3/extconf.rb +2 -0
- data/lib/cassandra/address_resolution.rb +36 -0
- data/lib/cassandra/address_resolution/policies.rb +2 -0
- data/lib/cassandra/address_resolution/policies/ec2_multi_region.rb +56 -0
- data/lib/cassandra/address_resolution/policies/none.rb +35 -0
- data/lib/cassandra/aggregate.rb +123 -0
- data/lib/cassandra/argument.rb +51 -0
- data/lib/cassandra/attr_boolean.rb +33 -0
- data/lib/cassandra/auth.rb +100 -0
- data/lib/cassandra/auth/providers.rb +17 -0
- data/lib/cassandra/auth/providers/password.rb +65 -0
- data/lib/cassandra/cassandra_logger.rb +80 -0
- data/lib/cassandra/cluster.rb +331 -0
- data/lib/cassandra/cluster/client.rb +1612 -0
- data/lib/cassandra/cluster/connection_pool.rb +78 -0
- data/lib/cassandra/cluster/connector.rb +372 -0
- data/lib/cassandra/cluster/control_connection.rb +962 -0
- data/lib/cassandra/cluster/failed_connection.rb +35 -0
- data/lib/cassandra/cluster/metadata.rb +142 -0
- data/lib/cassandra/cluster/options.rb +145 -0
- data/lib/cassandra/cluster/registry.rb +284 -0
- data/lib/cassandra/cluster/schema.rb +405 -0
- data/lib/cassandra/cluster/schema/cql_type_parser.rb +112 -0
- data/lib/cassandra/cluster/schema/fetchers.rb +1627 -0
- data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +175 -0
- data/lib/cassandra/cluster/schema/partitioners.rb +21 -0
- data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +45 -0
- data/lib/cassandra/cluster/schema/partitioners/ordered.rb +37 -0
- data/lib/cassandra/cluster/schema/partitioners/random.rb +37 -0
- data/lib/cassandra/cluster/schema/replication_strategies.rb +21 -0
- data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +102 -0
- data/lib/cassandra/cluster/schema/replication_strategies/none.rb +39 -0
- data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +44 -0
- data/lib/cassandra/column.rb +66 -0
- data/lib/cassandra/column_container.rb +326 -0
- data/lib/cassandra/compression.rb +69 -0
- data/lib/cassandra/compression/compressors/lz4.rb +73 -0
- data/lib/cassandra/compression/compressors/snappy.rb +69 -0
- data/lib/cassandra/custom_data.rb +53 -0
- data/lib/cassandra/driver.rb +260 -0
- data/lib/cassandra/errors.rb +784 -0
- data/lib/cassandra/execution/info.rb +69 -0
- data/lib/cassandra/execution/options.rb +267 -0
- data/lib/cassandra/execution/profile.rb +153 -0
- data/lib/cassandra/execution/profile_manager.rb +71 -0
- data/lib/cassandra/execution/trace.rb +192 -0
- data/lib/cassandra/executors.rb +113 -0
- data/lib/cassandra/function.rb +156 -0
- data/lib/cassandra/function_collection.rb +85 -0
- data/lib/cassandra/future.rb +794 -0
- data/lib/cassandra/host.rb +102 -0
- data/lib/cassandra/index.rb +118 -0
- data/lib/cassandra/keyspace.rb +473 -0
- data/lib/cassandra/listener.rb +87 -0
- data/lib/cassandra/load_balancing.rb +121 -0
- data/lib/cassandra/load_balancing/policies.rb +20 -0
- data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +172 -0
- data/lib/cassandra/load_balancing/policies/round_robin.rb +141 -0
- data/lib/cassandra/load_balancing/policies/token_aware.rb +149 -0
- data/lib/cassandra/load_balancing/policies/white_list.rb +100 -0
- data/lib/cassandra/materialized_view.rb +92 -0
- data/lib/cassandra/null_logger.rb +56 -0
- data/lib/cassandra/protocol.rb +102 -0
- data/lib/cassandra/protocol/coder.rb +1085 -0
- data/lib/cassandra/protocol/cql_byte_buffer.rb +418 -0
- data/lib/cassandra/protocol/cql_protocol_handler.rb +448 -0
- data/lib/cassandra/protocol/request.rb +41 -0
- data/lib/cassandra/protocol/requests/auth_response_request.rb +51 -0
- data/lib/cassandra/protocol/requests/batch_request.rb +117 -0
- data/lib/cassandra/protocol/requests/credentials_request.rb +51 -0
- data/lib/cassandra/protocol/requests/execute_request.rb +122 -0
- data/lib/cassandra/protocol/requests/options_request.rb +39 -0
- data/lib/cassandra/protocol/requests/prepare_request.rb +59 -0
- data/lib/cassandra/protocol/requests/query_request.rb +112 -0
- data/lib/cassandra/protocol/requests/register_request.rb +38 -0
- data/lib/cassandra/protocol/requests/startup_request.rb +49 -0
- data/lib/cassandra/protocol/requests/void_query_request.rb +24 -0
- data/lib/cassandra/protocol/response.rb +28 -0
- data/lib/cassandra/protocol/responses/already_exists_error_response.rb +50 -0
- data/lib/cassandra/protocol/responses/auth_challenge_response.rb +36 -0
- data/lib/cassandra/protocol/responses/auth_success_response.rb +36 -0
- data/lib/cassandra/protocol/responses/authenticate_response.rb +36 -0
- data/lib/cassandra/protocol/responses/error_response.rb +142 -0
- data/lib/cassandra/protocol/responses/event_response.rb +30 -0
- data/lib/cassandra/protocol/responses/function_failure_error_response.rb +52 -0
- data/lib/cassandra/protocol/responses/prepared_result_response.rb +62 -0
- data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +59 -0
- data/lib/cassandra/protocol/responses/read_failure_error_response.rb +71 -0
- data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +61 -0
- data/lib/cassandra/protocol/responses/ready_response.rb +43 -0
- data/lib/cassandra/protocol/responses/result_response.rb +42 -0
- data/lib/cassandra/protocol/responses/rows_result_response.rb +39 -0
- data/lib/cassandra/protocol/responses/schema_change_event_response.rb +73 -0
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +70 -0
- data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +37 -0
- data/lib/cassandra/protocol/responses/status_change_event_response.rb +39 -0
- data/lib/cassandra/protocol/responses/supported_response.rb +36 -0
- data/lib/cassandra/protocol/responses/topology_change_event_response.rb +33 -0
- data/lib/cassandra/protocol/responses/unavailable_error_response.rb +58 -0
- data/lib/cassandra/protocol/responses/unprepared_error_response.rb +48 -0
- data/lib/cassandra/protocol/responses/void_result_response.rb +34 -0
- data/lib/cassandra/protocol/responses/write_failure_error_response.rb +73 -0
- data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +63 -0
- data/lib/cassandra/protocol/v1.rb +326 -0
- data/lib/cassandra/protocol/v3.rb +358 -0
- data/lib/cassandra/protocol/v4.rb +478 -0
- data/lib/cassandra/reconnection.rb +49 -0
- data/lib/cassandra/reconnection/policies.rb +20 -0
- data/lib/cassandra/reconnection/policies/constant.rb +46 -0
- data/lib/cassandra/reconnection/policies/exponential.rb +79 -0
- data/lib/cassandra/result.rb +276 -0
- data/lib/cassandra/retry.rb +154 -0
- data/lib/cassandra/retry/policies.rb +21 -0
- data/lib/cassandra/retry/policies/default.rb +53 -0
- data/lib/cassandra/retry/policies/downgrading_consistency.rb +73 -0
- data/lib/cassandra/retry/policies/fallthrough.rb +39 -0
- data/lib/cassandra/session.rb +270 -0
- data/lib/cassandra/statement.rb +32 -0
- data/lib/cassandra/statements.rb +23 -0
- data/lib/cassandra/statements/batch.rb +146 -0
- data/lib/cassandra/statements/bound.rb +65 -0
- data/lib/cassandra/statements/prepared.rb +235 -0
- data/lib/cassandra/statements/simple.rb +118 -0
- data/lib/cassandra/statements/void.rb +38 -0
- data/lib/cassandra/table.rb +240 -0
- data/lib/cassandra/time.rb +103 -0
- data/lib/cassandra/time_uuid.rb +78 -0
- data/lib/cassandra/timestamp_generator.rb +37 -0
- data/lib/cassandra/timestamp_generator/simple.rb +38 -0
- data/lib/cassandra/timestamp_generator/ticking_on_duplicate.rb +58 -0
- data/lib/cassandra/trigger.rb +67 -0
- data/lib/cassandra/tuple.rb +131 -0
- data/lib/cassandra/types.rb +1704 -0
- data/lib/cassandra/udt.rb +443 -0
- data/lib/cassandra/util.rb +464 -0
- data/lib/cassandra/uuid.rb +110 -0
- data/lib/cassandra/uuid/generator.rb +212 -0
- data/lib/cassandra/version.rb +21 -0
- data/lib/datastax/cassandra.rb +47 -0
- data/lib/ycql.rb +842 -0
- metadata +243 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
module AddressResolution
|
21
|
+
module Policies
|
22
|
+
# This policy resolves private ips of the hosts in the same datacenter and
|
23
|
+
# public ips of hosts in other datacenters.
|
24
|
+
#
|
25
|
+
# @note Initializing this policy is not necessary, you should just pass
|
26
|
+
# `:ec_multi_region` to the `:address_resolution` option of
|
27
|
+
# {Cassandra.cluster}
|
28
|
+
class EC2MultiRegion
|
29
|
+
# @private
|
30
|
+
def initialize(resolver = Resolv)
|
31
|
+
@resolver = resolver
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns ip address after a double DNS lookup. First, it will get
|
35
|
+
# hostname from a given ip, then resolve the resulting hostname. This
|
36
|
+
# policy works because AWS public hostnames resolve to a private ip
|
37
|
+
# address within the same datacenter.
|
38
|
+
#
|
39
|
+
# @param address [IPAddr] node ip address from Cassandra's system table
|
40
|
+
#
|
41
|
+
# @return [IPAddr] private ip withing the same datacenter, public ip
|
42
|
+
# otherwise. Returns original address if DNS lookups fail.
|
43
|
+
def resolve(address)
|
44
|
+
@resolver.each_name(Resolv::DNS::Name.create(address.reverse)) do |name|
|
45
|
+
@resolver.each_address(name) do |addr|
|
46
|
+
return ::IPAddr.new(addr)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# default to original address if reverse DNS lookup failed
|
51
|
+
address
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
module AddressResolution
|
21
|
+
module Policies
|
22
|
+
# The default address resolution policy. Always returns original address.
|
23
|
+
class None
|
24
|
+
# Returns original address.
|
25
|
+
#
|
26
|
+
# @param address [IPAddr] node ip address from Cassandra's system table
|
27
|
+
#
|
28
|
+
# @return [IPAddr] same as `address`
|
29
|
+
def resolve(address)
|
30
|
+
address
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
# Represents a cassandra user defined aggregate
|
21
|
+
# @see Cassandra::Keyspace#each_aggregate
|
22
|
+
# @see Cassandra::Keyspace#aggregate
|
23
|
+
# @see Cassandra::Keyspace#has_aggregate?
|
24
|
+
class Aggregate
|
25
|
+
# @private
|
26
|
+
attr_reader :keyspace
|
27
|
+
# @return [String] aggregate name
|
28
|
+
attr_reader :name
|
29
|
+
# @return [Cassandra::Type] aggregate return type
|
30
|
+
attr_reader :type
|
31
|
+
# @return [Array<Cassandra::Type>] aggregate argument types
|
32
|
+
attr_reader :argument_types
|
33
|
+
# @return [Cassandra::Type] aggregate state type
|
34
|
+
attr_reader :state_type
|
35
|
+
# @return [Object, nil] the initial value of the aggregate state or nil
|
36
|
+
attr_reader :initial_state
|
37
|
+
# @return [Cassandra::Function] the state function used by this aggregate
|
38
|
+
attr_reader :state_function
|
39
|
+
# @return [Cassandra::Function] the final function used by this aggregate
|
40
|
+
attr_reader :final_function
|
41
|
+
|
42
|
+
# @private
|
43
|
+
def initialize(keyspace,
|
44
|
+
name,
|
45
|
+
type,
|
46
|
+
argument_types,
|
47
|
+
state_type,
|
48
|
+
initial_state,
|
49
|
+
state_function,
|
50
|
+
final_function)
|
51
|
+
@keyspace = keyspace
|
52
|
+
@name = name
|
53
|
+
@type = type
|
54
|
+
@argument_types = argument_types
|
55
|
+
@state_type = state_type
|
56
|
+
@initial_state = initial_state
|
57
|
+
@state_function = state_function
|
58
|
+
@final_function = final_function
|
59
|
+
end
|
60
|
+
|
61
|
+
# @private
|
62
|
+
def eql?(other)
|
63
|
+
other.is_a?(Aggregate) && \
|
64
|
+
@keyspace == other.keyspace && \
|
65
|
+
@name == other.name && \
|
66
|
+
@type == other.type && \
|
67
|
+
@argument_types == other.argument_types && \
|
68
|
+
@state_type == other.state_type && \
|
69
|
+
@initial_state == other.initial_state && \
|
70
|
+
@state_function == other.state_function && \
|
71
|
+
@final_function == other.final_function
|
72
|
+
end
|
73
|
+
alias == eql?
|
74
|
+
|
75
|
+
# @private
|
76
|
+
def hash
|
77
|
+
@hash ||= begin
|
78
|
+
h = 17
|
79
|
+
h = 31 * h + @keyspace.hash
|
80
|
+
h = 31 * h + @name.hash
|
81
|
+
h = 31 * h + @type.hash
|
82
|
+
h = 31 * h + @argument_types.hash
|
83
|
+
h = 31 * h + @state_type.hash
|
84
|
+
h = 31 * h + @initial_state.hash
|
85
|
+
h = 31 * h + @state_function.hash
|
86
|
+
h = 31 * h + @final_function.hash
|
87
|
+
h
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# @private
|
92
|
+
def inspect
|
93
|
+
"#<Cassandra::Aggregate:0x#{object_id.to_s(16)} " \
|
94
|
+
"@keyspace=#{@keyspace.inspect}, " \
|
95
|
+
"@name=#{@name.inspect}, " \
|
96
|
+
"@type=#{@type.inspect}, " \
|
97
|
+
"@argument_types=#{@argument_types.inspect}, " \
|
98
|
+
"@initial_state=#{@initial_state.inspect}, " \
|
99
|
+
"@state_function=#{@state_function.inspect}, " \
|
100
|
+
"@final_function=#{@final_function.inspect}>"
|
101
|
+
end
|
102
|
+
|
103
|
+
# @return [String] a cql representation of this aggregate
|
104
|
+
def to_cql
|
105
|
+
cql = 'CREATE AGGREGATE simplex.average('
|
106
|
+
first = true
|
107
|
+
@argument_types.each do |type|
|
108
|
+
if first
|
109
|
+
first = false
|
110
|
+
else
|
111
|
+
cql << ', '
|
112
|
+
end
|
113
|
+
cql << type.to_s
|
114
|
+
end
|
115
|
+
cql << ')'
|
116
|
+
cql << "\n SFUNC #{@state_function.name}"
|
117
|
+
cql << "\n STYPE #{@state_type}"
|
118
|
+
cql << "\n FINALFUNC #{@final_function.name}" if @final_function
|
119
|
+
cql << "\n INITCOND #{@initial_state}"
|
120
|
+
cql << ';'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
# Represents a function argument
|
21
|
+
class Argument
|
22
|
+
# @return [String] column name
|
23
|
+
attr_reader :name
|
24
|
+
# @return [Cassandra::Type] column type
|
25
|
+
attr_reader :type
|
26
|
+
|
27
|
+
# @private
|
28
|
+
def initialize(name, type)
|
29
|
+
@name = name
|
30
|
+
@type = type
|
31
|
+
end
|
32
|
+
|
33
|
+
# @private
|
34
|
+
def eql?(other)
|
35
|
+
other.is_a?(Argument) && \
|
36
|
+
@name == other.name && \
|
37
|
+
@type == other.type
|
38
|
+
end
|
39
|
+
alias == eql?
|
40
|
+
|
41
|
+
# @private
|
42
|
+
def hash
|
43
|
+
@hash ||= begin
|
44
|
+
h = 17
|
45
|
+
h = 31 * h + @name.hash
|
46
|
+
h = 31 * h + @type.hash
|
47
|
+
h
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
# This file monkey-patches Module to have an attr_boolean method to make it easy
|
20
|
+
# for classes to define boolean instance variables with "foo?" reader methods.
|
21
|
+
# Inspired by http://stackoverflow.com/questions/4013591/attr-reader-with-question-mark-in-a-name
|
22
|
+
module Cassandra
|
23
|
+
module AttrBoolean
|
24
|
+
def attr_boolean(*names)
|
25
|
+
names.each do |name|
|
26
|
+
define_method(:"#{name}?") do
|
27
|
+
res = instance_variable_get(:"@#{name}")
|
28
|
+
!res.nil? && res != false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
module Auth
|
21
|
+
# An auth provider is a factory for {Cassandra::Auth::Authenticator authenticator}
|
22
|
+
# instances (or objects matching that interface). Its {#create_authenticator} will
|
23
|
+
# be called once for each connection that requires authentication.
|
24
|
+
#
|
25
|
+
# If the authentication requires keeping state, keep that in the
|
26
|
+
# authenticator instances, not in the auth provider.
|
27
|
+
#
|
28
|
+
# @note Creating an authenticator must absolutely not block, or the whole
|
29
|
+
# connection process will block.
|
30
|
+
#
|
31
|
+
# @abstract Auth providers given to {Cassandra.cluster} don't need to be
|
32
|
+
# subclasses of this class, but need to implement the same methods. This
|
33
|
+
# class exists only for documentation purposes.
|
34
|
+
#
|
35
|
+
# @see Cassandra::Auth::Providers
|
36
|
+
class Provider
|
37
|
+
# @!method create_authenticator(authentication_class, host)
|
38
|
+
#
|
39
|
+
# Create a new authenticator object. This method will be called once per
|
40
|
+
# connection that requires authentication. The auth provider can create
|
41
|
+
# different authenticators for different authentication classes, or return
|
42
|
+
# nil if it does not support the authentication class.
|
43
|
+
#
|
44
|
+
# @note This method must absolutely not block.
|
45
|
+
#
|
46
|
+
# @param authentication_class [String] the authentication class used by
|
47
|
+
# the server.
|
48
|
+
# @param host [Cassandra::Host] the node to whom we're authenticating.
|
49
|
+
#
|
50
|
+
# @return [Cassandra::Auth::Authenticator, nil] an object with an
|
51
|
+
# interface matching {Cassandra::Auth::Authenticator} or `nil` if the
|
52
|
+
# authentication class is not supported.
|
53
|
+
end
|
54
|
+
|
55
|
+
# An authenticator handles the authentication challenge/response cycles of
|
56
|
+
# a single connection. It can be stateful, but it must not for any reason
|
57
|
+
# block. If any of the method calls block, the whole connection process
|
58
|
+
# will be blocked.
|
59
|
+
#
|
60
|
+
# @abstract Authenticators created by auth providers don't need to be
|
61
|
+
# subclasses of this class, but need to implement the same methods. This
|
62
|
+
# class exists only for documentation purposes.
|
63
|
+
#
|
64
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v2.spec#L257-L273 Cassandra
|
65
|
+
# native protocol v2 SASL authentication
|
66
|
+
# @see Cassandra::Auth::Provider#create_authenticator
|
67
|
+
class Authenticator
|
68
|
+
# @!method initial_response
|
69
|
+
#
|
70
|
+
# This method must return the initial authentication token to be sent to
|
71
|
+
# the server.
|
72
|
+
#
|
73
|
+
# @note This method must absolutely not block.
|
74
|
+
#
|
75
|
+
# @return [String] the initial authentication token
|
76
|
+
|
77
|
+
# @!method challenge_response(token)
|
78
|
+
#
|
79
|
+
# If the authentication requires multiple challenge/response cycles this
|
80
|
+
# method will be called when a challenge is returned by the server. A
|
81
|
+
# response token must be created and will be sent back to the server.
|
82
|
+
#
|
83
|
+
# @note This method must absolutely not block.
|
84
|
+
#
|
85
|
+
# @param token [String] a challenge token sent by the server
|
86
|
+
# @return [String] the authentication token to send back to the server
|
87
|
+
|
88
|
+
# @!method authentication_successful(token)
|
89
|
+
#
|
90
|
+
# Called when the authentication is successful.
|
91
|
+
#
|
92
|
+
# @note This method must absolutely not block.
|
93
|
+
#
|
94
|
+
# @param token [String] a token sent by the server
|
95
|
+
# @return [void]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
require 'cassandra/auth/providers'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright DataStax, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#++
|
16
|
+
|
17
|
+
require 'cassandra/auth/providers/password'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
module Auth
|
21
|
+
module Providers
|
22
|
+
# Auth provider used for Cassandra's built in authentication.
|
23
|
+
#
|
24
|
+
# @note No need to instantiate this class manually, use `:username` and
|
25
|
+
# `:password` options when calling {Cassandra.cluster} and one will be
|
26
|
+
# created automatically for you.
|
27
|
+
class Password < Provider
|
28
|
+
# Authenticator used for Cassandra's built in authentication,
|
29
|
+
# see {Cassandra::Auth::Providers::Password}
|
30
|
+
# @private
|
31
|
+
class Authenticator
|
32
|
+
# @private
|
33
|
+
def initialize(username, password)
|
34
|
+
@username = username
|
35
|
+
@password = password
|
36
|
+
end
|
37
|
+
|
38
|
+
def initial_response
|
39
|
+
"\x00#{@username}\x00#{@password}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def challenge_response(token)
|
43
|
+
end
|
44
|
+
|
45
|
+
def authentication_successful(token)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param username [String] username to use for authentication to Cassandra
|
50
|
+
# @param password [String] password to use for authentication to Cassandra
|
51
|
+
def initialize(username, password)
|
52
|
+
@username = username
|
53
|
+
@password = password
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns a Password Authenticator
|
57
|
+
# @param authentication_class [String] ignored
|
58
|
+
# @return [Cassandra::Auth::Authenticator]
|
59
|
+
def create_authenticator(authentication_class)
|
60
|
+
Authenticator.new(@username, @password)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|