diff --git a/lib/mongoid/shell/properties/host.rb b/lib/mongoid/shell/properties/host.rb index 9a54d21..83c6040 100644 --- a/lib/mongoid/shell/properties/host.rb +++ b/lib/mongoid/shell/properties/host.rb @@ -10,7 +10,7 @@ def host @host || begin node = session.cluster.nodes.first raise Mongoid::Shell::Errors::SessionNotConnectedError unless node - node.address == "localhost:27017" ? nil : node.address + node.address.original == "localhost:27017" ? nil : node.address.original end end diff --git a/lib/mongoid/shell/properties/password.rb b/lib/mongoid/shell/properties/password.rb index 0e86df3..0956215 100644 --- a/lib/mongoid/shell/properties/password.rb +++ b/lib/mongoid/shell/properties/password.rb @@ -8,11 +8,18 @@ module Password # current password def password @password || begin - return nil unless session.context.cluster.auth && session.context.cluster.auth.first - session.context.cluster.auth.first[1][1] + node = session.cluster.nodes.first + raise Mongoid::Shell::Errors::SessionNotConnectedError unless node + return nil unless node.credentials.has_key? db || node.credentials[db].empty? + node.credentials[db][1] end end + private + def db + @db || session.send(:current_database).name + end + end end end diff --git a/lib/mongoid/shell/properties/primary.rb b/lib/mongoid/shell/properties/primary.rb index e212167..4779c23 100644 --- a/lib/mongoid/shell/properties/primary.rb +++ b/lib/mongoid/shell/properties/primary.rb @@ -11,7 +11,7 @@ def primary raise Mongoid::Shell::Errors::SessionNotConnectedError unless session.cluster.nodes.any? node = session.cluster.nodes.find(&:primary?) raise Mongoid::Shell::Errors::MissingPrimaryNodeError unless node - node.address == "localhost:27017" ? nil : node.address + node.address.original == "localhost:27017" ? nil : node.address.original end end diff --git a/lib/mongoid/shell/properties/username.rb b/lib/mongoid/shell/properties/username.rb index aabe868..ba552e2 100644 --- a/lib/mongoid/shell/properties/username.rb +++ b/lib/mongoid/shell/properties/username.rb @@ -8,11 +8,18 @@ module Username # current username def username @username || begin - return nil unless session.context.cluster.auth && session.context.cluster.auth.first - session.context.cluster.auth.first[1][0] + node = session.cluster.nodes.first + raise Mongoid::Shell::Errors::SessionNotConnectedError unless node + return nil unless node.credentials.has_key? db || node.credentials[db].empty? + node.credentials[db][0] end end + private + def db + @db || session.send(:current_database).name + end + end end end diff --git a/mongoid-shell.gemspec b/mongoid-shell.gemspec index af2fed2..96d5f00 100644 --- a/mongoid-shell.gemspec +++ b/mongoid-shell.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.homepage = "http://github.com/dblock/mongoid-shell" s.licenses = [ "MIT" ] s.summary = "Derive shell commands from Mongoid configuration options." - s.add_dependency "mongoid", ">= 3.0.0" + s.add_dependency "mongoid", ">= 4.0.0.alpha1" s.add_dependency "i18n" end