Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing issue with mongodb autoconfig authentication on reconnects

Change-Id: I7d8d2fdbc98db81cf6f3068fe0229d225d7d32d0
  • Loading branch information...
commit 1b566bc207b008c12083337724d33f73cdef8d55 1 parent 84a478d
Thomas Risberg authored
View
2  auto-reconfiguration/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- cf-autoconfig (0.0.2)
+ cf-autoconfig (0.0.3)
cf-runtime (= 0.0.1)
GEM
View
27 auto-reconfiguration/lib/cfautoconfig/document/mongodb.rb
@@ -7,6 +7,8 @@ module Mongo
def self.included( base )
base.send( :alias_method, :original_initialize, :initialize)
base.send( :alias_method, :initialize, :initialize_with_cf )
+ base.send( :alias_method, :original_apply_saved_authentication, :apply_saved_authentication)
+ base.send( :alias_method, :apply_saved_authentication, :apply_saved_authentication_with_cf )
base.send( :alias_method, :original_db, :db)
base.send( :alias_method, :db, :db_with_cf )
base.send( :alias_method, :original_shortcut, :[])
@@ -19,20 +21,24 @@ def initialize_with_cf(host = nil, port = nil, opts = {})
@service_props = CFRuntime::CloudApp.service_props('mongodb')
puts "Auto-reconfiguring MongoDB"
@auto_config = true
- mongo_host = @service_props[:host]
- mongo_port = @service_props[:port]
- original_initialize mongo_host, mongo_port, opts
+ original_initialize @service_props[:host], @service_props[:port], opts
+ add_auth(@service_props[:db], @service_props[:username], @service_props[:password])
else
puts "Found #{service_names.length} mongo services. Skipping auto-reconfiguration."
@auto_config = false
original_initialize host, port, opts
end
end
-
- def db_with_cf(db_name, opts = {})
+
+ def apply_saved_authentication_with_cf(opts = {})
+ add_auth(@service_props[:db], @service_props[:username], @service_props[:password])
+ original_apply_saved_authentication opts
+ end
+
+ def db_with_cf(db_name, opts = {})
if @auto_config && db_name != 'admin'
+ add_auth(@service_props[:db], @service_props[:username], @service_props[:password])
db = original_db @service_props[:db], opts
- authenticate_with_cf(db)
else
original_db db_name, opts
end
@@ -40,18 +46,11 @@ def db_with_cf(db_name, opts = {})
def shortcut_with_cf(db_name)
if @auto_config && db_name != 'admin'
+ add_auth(@service_props[:db], @service_props[:username], @service_props[:password])
db = original_shortcut(@service_props[:db])
- authenticate_with_cf(db)
else
db = original_shortcut(db_name)
end
end
-
- def authenticate_with_cf(db)
- mongo_username = @service_props[:username]
- mongo_password = @service_props[:password]
- db.authenticate mongo_username, mongo_password
- db
- end
end
end
View
2  auto-reconfiguration/lib/cfautoconfig/document/mongodb_configurer.rb
@@ -14,6 +14,8 @@ class Connection
if method_defined?(:initialize_with_cf)
undef_method :initialize_with_cf
alias :initialize :original_initialize
+ undef_method :apply_saved_authentication_with_cf
+ alias :apply_saved_authentication :original_apply_saved_authentication
undef_method :db_with_cf
alias :db :original_db
undef_method :shortcut_with_cf
View
2  auto-reconfiguration/lib/cfautoconfig/version.rb
@@ -1,3 +1,3 @@
module AutoReconfiguration
- VERSION = '0.0.2'
+ VERSION = '0.0.3'
end
View
35 auto-reconfiguration/spec/unit/document/mongo_configurer_spec.rb
@@ -24,8 +24,9 @@ def validate_db_name(db_name)
db_name
end
end
- class DB
- def authenticate(username, password, save_auth=true)
+ class Connection
+ def add_auth(database, username, password)
+ database.should == 'db'
username.should == '8d93ae0a'
password.should == '7cf3c0e3'
true
@@ -44,8 +45,9 @@ def validate_db_name(db_name)
db_name
end
end
- class DB
- def authenticate(username, password, save_auth=true)
+ class Connection
+ def add_auth(database, username, password)
+ database.should == 'db'
username.should == '8d93ae0a'
password.should == '7cf3c0e3'
true
@@ -64,9 +66,11 @@ def validate_db_name(db_name)
db_name
end
end
- class DB
- def authenticate(username, password, save_auth=true)
- raise(Mongo::AuthenticationError, "Authenticate should not have been called!")
+ class Connection
+ def add_auth(database, username, password)
+ if (database == 'admin')
+ raise(Mongo::AuthenticationError, "Authenticate should not have been called!")
+ end
end
end
end
@@ -82,9 +86,11 @@ def validate_db_name(db_name)
db_name
end
end
- class DB
- def authenticate(username, password, save_auth=true)
- raise(Mongo::AuthenticationError, "Authenticate should not have been called!")
+ class Connection
+ def add_auth(database, username, password)
+ if (database == 'admin')
+ raise(Mongo::AuthenticationError, "Authenticate should not have been called!")
+ end
end
end
end
@@ -118,11 +124,6 @@ def validate_db_name(db_name)
db_name
end
end
- class DB
- def authenticate(username, password, save_auth=true)
- raise(Mongo::AuthenticationError, "Authenticate should not have been called!")
- end
- end
end
mongo = Mongo::Connection.new('127.0.0.1', 27017, {:connect => false})
db = mongo.db('test')
@@ -142,8 +143,8 @@ def validate_db_name(db_name)
db_name
end
end
- class DB
- def authenticate(username, password, save_auth=true)
+ class Connection
+ def add_auth(database, username, password)
raise(Mongo::AuthenticationError, "Authenticate should not have been called!")
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.