Exception: Mongo::Auth::Unauthorized
- Inherits:
-
Error::AuthError
- Object
- RuntimeError
- Error::AuthError
- Mongo::Auth::Unauthorized
- Defined in:
- build/ruby-driver-v2.17/lib/mongo/auth.rb
Overview
Raised when a user is not authorized on a database.
Instance Attribute Summary
Attributes included from Error::Notable
Instance Method Summary collapse
-
#initialize(user, used_mechanism: nil, message: nil, server: nil) ⇒ Unauthorized
constructor
Instantiate the new error.
Methods included from Error::Notable
Constructor Details
#initialize(user, used_mechanism: nil, message: nil, server: nil) ⇒ Unauthorized
Instantiate the new error.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'build/ruby-driver-v2.17/lib/mongo/auth.rb', line 144 def initialize(user, used_mechanism: nil, message: nil, server: nil ) configured_bits = [] used_bits = [ "auth source: #{user.auth_source}", ] if user.mechanism configured_bits << "mechanism: #{user.mechanism}" end if used_mechanism used_bits << "used mechanism: #{used_mechanism}" end if server used_bits << "used server: #{server.address} (#{server.status})" end used_user = if user.mechanism == :mongodb_x509 'Client certificate' else "User #{user.name}" end if configured_bits.empty? configured_bits = '' else configured_bits = " (#{configured_bits.join(', ')})" end used_bits = " (#{used_bits.join(', ')})" msg = "#{used_user}#{configured_bits} is not authorized to access #{user.database}#{used_bits}" if msg += ': ' + end super(msg) end |