Merged in master (pull request #22)

fix(wsgi+config): fault environment setup
This commit is contained in:
Tiara Rodney 2022-04-03 02:34:58 +00:00
commit 24c6602ec5
3 changed files with 15 additions and 6 deletions

View file

@ -1,6 +1,6 @@
[metadata] [metadata]
name = httpaste-victorykit name = httpaste-victorykit
version = 1.0.5-alpha version = 1.0.6-alpha
author = Tiara Rodney author = Tiara Rodney
author_email = t.rodney@victoryk.it author_email = t.rodney@victoryk.it
description = a versatile HTTP pastebin description = a versatile HTTP pastebin

View file

@ -143,6 +143,7 @@ from inspect import isclass
from configparser import ConfigParser from configparser import ConfigParser
from ast import literal_eval from ast import literal_eval
from io import StringIO from io import StringIO
from os import environ
from connexion import FlaskApp from connexion import FlaskApp
from connexion.resolver import RestyResolver from connexion.resolver import RestyResolver
@ -158,7 +159,7 @@ from httpaste.helper.http import (
UnauthorizedError) UnauthorizedError)
CONFIGPATH_ENVIRON = 'HTTPASTE_CONFIG' CONFIGPATH_ENVIRON = 'HTTPASTE_CONFIGPATH'
def get_sanitized_config_charset(charset: str): def get_sanitized_config_charset(charset: str):
@ -198,17 +199,17 @@ class ServerConfig:
bind_address = None bind_address = None
def get_config_path(environ: str = CONFIGPATH_ENVIRON): def get_config_path(var_name: str = CONFIGPATH_ENVIRON):
""" """
""" """
try: try:
return os.environ[environ] return environ[var_name]
except KeyError as e: except KeyError as e:
raise ConfigError( raise ConfigError(
'environment variable \'{environ}\' not set.') from e f'environment variable \'{var_name}\' not set.') from e
def load_config(path: str) -> Tuple[Config, ServerConfig]: def load_config(path: str) -> Tuple[Config, ServerConfig]:
@ -322,6 +323,14 @@ def get_flask_app(
with application.app.app_context(): with application.app.app_context():
application.app.httpaste = config application.app.httpaste = config
#add header for browsers to present a sign-in prompt
@application.app.after_request
def rewrite_forbidden_request(response):
if response.status_code in [401]:
response.headers['WWW-Authenticate'] = 'Basic realm="private"'
return response
return application return application

View file

@ -3,6 +3,6 @@
""" """
from httpaste import load_config, get_flask_app, get_config_path from httpaste import load_config, get_flask_app, get_config_path
config, server_config = load_config(get_config_path) config, server_config = load_config(get_config_path())
application = get_flask_app(config, server_config) application = get_flask_app(config, server_config)