Skip to content

Commit

Permalink
Added DB username/password.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeMonkeySteve authored and ches committed Jan 5, 2011
1 parent ed6d49b commit b34d0c9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/rack/gridfs.rb
Expand Up @@ -18,12 +18,12 @@ def initialize(app, options = {})
}.merge(options)

@app = app
@hostname = options[:hostname]
@port = options[:port]
@database = options[:database]
@prefix = options[:prefix]
@db = nil

@hostname, @port, @database, @username, @password =
options.values_at(:hostname, :port, :database, :username, :password)

connect!
end

Expand All @@ -44,14 +44,14 @@ def gridfs_request(id)
end

private

def connect!
Timeout::timeout(5) do
@db = Mongo::Connection.new(hostname).db(database)
def connect!
Timeout::timeout(5) do
@db = Mongo::Connection.new(hostname, port).db(database)
@db.authenticate(@username, @password) if @username
end
rescue Exception => e
raise Rack::GridFSConnectionError, "Unable to connect to the MongoDB server (#{e.to_s})"
end
rescue Exception => e
raise Rack::GridFSConnectionError, "Unable to connect to the MongoDB server (#{e.to_s})"
end

end

Expand Down

0 comments on commit b34d0c9

Please sign in to comment.