ironic_inspector.common.auth_basic module¶
-
class
ironic_inspector.common.auth_basic.
BasicAuthMiddleware
(app, auth_file)[source]¶ Bases:
object
Middleware which performs HTTP basic authentication on requests
-
ironic_inspector.common.auth_basic.
auth_entry
(entry, password)[source]¶ Compare a password with a single user auth file entry
- Param
entry: Line from auth user file to use for authentication
- Param
password: Password encoded as bytes
- Returns
A dictionary of WSGI environment values to append to the request
- Raises
Unauthorized, if the entry doesn’t match supplied password or if the entry is crypted with a method other than bcrypt
-
ironic_inspector.common.auth_basic.
authenticate
(auth_file, username, password)[source]¶ Finds username and password match in Apache style user auth file
The user auth file format is expected to comply with Apache documentation[1] however the bcrypt password digest is the only digest format supported.
[1] https://httpd.apache.org/docs/current/misc/password_encryptions.html
- Param
auth_file: Path to user auth file
- Param
username: Username to authenticate
- Param
password: Password encoded as bytes
- Returns
A dictionary of WSGI environment values to append to the request
- Raises
Unauthorized, if no file entries match supplied username/password
-
ironic_inspector.common.auth_basic.
parse_entry
(entry)[source]¶ Extrace the username and crypted password from a user auth file entry
- Param
entry: Line from auth user file to use for authentication
- Returns
a tuple of username and crypted password
- Raises
ConfigInvalid if the password is not in the supported bcrypt format
-
ironic_inspector.common.auth_basic.
parse_header
(env)[source]¶ Parse WSGI environment for Authorization header of type Basic
- Param
env: WSGI environment to get header from
- Returns
Token portion of the header value
- Raises
Unauthorized, if header is missing or if the type is not Basic
-
ironic_inspector.common.auth_basic.
parse_token
(token)[source]¶ Parse the token portion of the Authentication header value
- Param
token: Token value from basic authorization header
- Returns
tuple of username, password
- Raises
Unauthorized, if username and password could not be parsed for any reason
Raise an Unauthorized exception to prompt for basic authentication
- Param
message: Optional message for esception
- Raises
Unauthorized with WWW-Authenticate header set