Skip to content

Commit 7352be3

Browse files
committed
* Plumb through node host to authentication provider, as some authentication providers need that info.
1 parent df74ca2 commit 7352be3

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

lib/cassandra/auth.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module Auth
3434
#
3535
# @see Cassandra::Auth::Providers
3636
class Provider
37-
# @!method create_authenticator(authentication_class, protocol_version)
37+
# @!method create_authenticator(authentication_class, host)
3838
#
3939
# Create a new authenticator object. This method will be called once per
4040
# connection that requires authentication. The auth provider can create
@@ -45,6 +45,8 @@ class Provider
4545
#
4646
# @param authentication_class [String] the authentication class used by
4747
# the server.
48+
# @param host [Cassandra::Host] the node to whom we're authenticating.
49+
#
4850
# @return [Cassandra::Auth::Authenticator, nil] an object with an
4951
# interface matching {Cassandra::Auth::Authenticator} or `nil` if the
5052
# authentication class is not supported.

lib/cassandra/cluster/connector.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def do_connect(host)
154154
supported_cql_versions.first :
155155
'3.1.0'
156156

157-
startup_connection(connection, cql_version, compression)
157+
startup_connection(host, connection, cql_version, compression)
158158
end
159159
f.fallback do |error|
160160
case error
@@ -200,7 +200,7 @@ def do_connect(host)
200200
end
201201
end
202202

203-
def startup_connection(connection, cql_version, compression)
203+
def startup_connection(host, connection, cql_version, compression)
204204
connection.send_request(Protocol::StartupRequest.new(cql_version, compression),
205205
@execution_options.timeout).flat_map do |r|
206206
case r
@@ -213,12 +213,9 @@ def startup_connection(connection, cql_version, compression)
213213
Ione::Future.failed(cannot_authenticate_error)
214214
end
215215
else
216-
authenticator = @connection_options.create_authenticator(
217-
r.authentication_class)
216+
authenticator = @connection_options.create_authenticator(r.authentication_class, host)
218217
if authenticator
219-
challenge_response_cycle(connection,
220-
authenticator,
221-
authenticator.initial_response)
218+
challenge_response_cycle(connection, authenticator, authenticator.initial_response)
222219
else
223220
Ione::Future.failed(cannot_authenticate_error)
224221
end

lib/cassandra/cluster/options.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,17 @@ def compression
8080
@compressor && @compressor.algorithm
8181
end
8282

83-
def create_authenticator(authentication_class)
84-
@auth_provider && @auth_provider.create_authenticator(authentication_class)
83+
def create_authenticator(authentication_class, host)
84+
if @auth_provider
85+
# Auth providers should take an auth-class and host, but they used to not, so for backward compatibility
86+
# we figure out if this provider does, and if so send both args, otherwise just send the auth-class.
87+
88+
if @auth_provider.method(:create_authenticator).arity == 1
89+
@auth_provider.create_authenticator(authentication_class)
90+
else
91+
@auth_provider.create_authenticator(authentication_class, host)
92+
end
93+
end
8594
end
8695

8796
def connections_per_local_node

0 commit comments

Comments
 (0)