magneticow: add --noauth argument to disable basic-auth

fixes #125
This commit is contained in:
Martin Weinelt 2017-07-19 20:47:52 +02:00
parent 5ee325f8f5
commit 2ad6415586
2 changed files with 12 additions and 4 deletions

View File

@ -71,8 +71,15 @@ def parse_args() -> argparse.Namespace:
"--port", action="store", type=int, required=True, "--port", action="store", type=int, required=True,
help="the port number magneticow web server should listen on" help="the port number magneticow web server should listen on"
) )
parser.add_argument(
"--user", action="append", nargs=2, metavar=("USERNAME", "PASSWORD"), type=str, required=True, auth_group = parser.add_mutually_exclusive_group(required=True)
auth_group.add_argument(
"--no-auth", dest='noauth', action="store_true", default=False,
help="make the web interface available without authentication"
)
auth_group.add_argument(
"--user", action="append", nargs=2, metavar=("USERNAME", "PASSWORD"), type=str,
help="the pair(s) of username and password for basic HTTP authentication" help="the pair(s) of username and password for basic HTTP authentication"
) )

View File

@ -45,6 +45,7 @@ def requires_auth(f):
@functools.wraps(f) @functools.wraps(f)
def decorated(*args, **kwargs): def decorated(*args, **kwargs):
auth = flask.request.authorization auth = flask.request.authorization
if not flask.current_app.arguments.noauth:
if not auth or not is_authorized(auth.username, auth.password): if not auth or not is_authorized(auth.username, auth.password):
return authenticate() return authenticate()
return f(*args, **kwargs) return f(*args, **kwargs)