Merge pull request #126 from mweinelt/magneticow-noauth

magneticow: add --noauth argument to disable basic-auth
This commit is contained in:
Bora M. Alper 2017-07-21 21:45:22 +03:00 committed by GitHub
commit 3a7de3daaf
2 changed files with 12 additions and 4 deletions

View File

@ -75,8 +75,15 @@ def parse_args() -> argparse.Namespace:
"--port", action="store", type=int, required=True,
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"
)

View File

@ -45,8 +45,9 @@ def requires_auth(f):
@functools.wraps(f)
def decorated(*args, **kwargs):
auth = flask.request.authorization
if not auth or not is_authorized(auth.username, auth.password):
return authenticate()
if not flask.current_app.arguments.noauth:
if not auth or not is_authorized(auth.username, auth.password):
return authenticate()
return f(*args, **kwargs)
return decorated
# END OF THE 3RD PARTY COPYRIGHTED CONTENT