lib/mongoid/shell/properties/password.rb in mongoid-shell-0.2.0 vs lib/mongoid/shell/properties/password.rb in mongoid-shell-0.3.0
- old
+ new
@@ -1,19 +1,24 @@
module Mongoid
module Shell
module Properties
module Password
-
attr_accessor :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]
+ if Mongoid::Shell.mongoid3?
+ return nil unless session.context.cluster.auth && session.context.cluster.auth.first
+ session.context.cluster.auth.first[1][1]
+ else
+ node = session.cluster.nodes.first
+ raise Mongoid::Shell::Errors::SessionNotConnectedError unless node
+ return nil if !node.credentials.key?(db) || node.credentials[db].empty?
+ node.credentials[db][1]
+ end
end
end
-
end
end
end
end