Class: AuthMongo

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo-proxy/auth.rb

Constant Summary collapse

@@admin_cmd_whitelist =
[
  { 'ismaster' => 1 },
  { 'isMaster' => 1 },
  { 'listDatabases' => 1},
  {
    'replSetGetStatus' => 1,
    'forShell' => 1
  }
]

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ AuthMongo

Returns a new instance of AuthMongo.



14
15
16
17
18
19
# File 'lib/mongo-proxy/auth.rb', line 14

def initialize(config = nil)
  @config = config
  @log = @config[:logger]
  @request_id = 20
  @last_error = {}
end

Instance Method Details

#wire_auth(conn, msg) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mongo-proxy/auth.rb', line 21

def wire_auth(conn, msg)
  return nil unless msg

  authed, response = auth(conn, msg)

  if !authed
    @last_error[conn] = true
  else
    @last_error[conn] = false
  end

  if response
    return WireMongo::build_reply(response, get_request_id, msg[:header][:requestID])
  else
    return authed
  end
end