Skip to content

Commit

Permalink
Enable authentication with smog!
Browse files Browse the repository at this point in the history
2 updates here:
 - if user entered a password, try to authenticate against "admin" db first then drop back to desired database.
 - if any admin operation fails (in the case of a non-admin user), keep going; don't assume we should throw an error here.
  • Loading branch information
akumpf committed Oct 29, 2012
1 parent bac561f commit 7b9f005
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions lib/services/admin.coffee
Expand Up @@ -5,26 +5,34 @@ module.exports = (cb, socket) ->
db = cb.socket.mongo.database
admin = db.admin

db.collectionNames (err, r) ->
return cb err.message if err?
out.collections = r
# authenticate against "admin" db first, then go back to original.
if db._dbconn.options.password
dbOrig = db._dbconn.databaseName
db._dbconn.databaseName = "admin"
db.open (err, r) ->
db._dbconn.databaseName = dbOrig
db.open (err, r) ->

admin.serverStatus (err, r) ->
return cb err.message if err?
out.serverStatus = r

admin.buildInfo (err, r) ->
return cb err.message if err?
out.buildInfo = r

admin.profilingLevel (err, r) ->
db.collectionNames (err, r) ->
return cb err.message if err?
out.profilingLevel = r

admin.profilingInfo (err, r) ->
return cb err.message if err?
out.profilingInfo = r

admin.replSetGetStatus (err, r) ->
out.replSetGetStatus = r unless err?
return cb null, out
out.collections = r

admin.serverStatus (err, r) ->
# return cb err.message if err?
out.serverStatus = r unless err?

admin.buildInfo (err, r) ->
# return cb err.message if err?
out.buildInfo = r unless err?

admin.profilingLevel (err, r) ->
# return cb err.message if err?
out.profilingLevel = r unless err?

admin.profilingInfo (err, r) ->
# return cb err.message if err?
out.profilingInfo = r unless err?

admin.replSetGetStatus (err, r) ->
out.replSetGetStatus = r unless err?
return cb null, out

0 comments on commit 7b9f005

Please sign in to comment.