potiuk commented on code in PR #52581:
URL: https://github.com/apache/airflow/pull/52581#discussion_r2176640138
##########
airflow-core/src/airflow/utils/serve_logs.py:
##########
@@ -119,25 +101,64 @@ def validate_pre_signed_url():
get_docs_url("configurations-ref.html#secret-key"),
exc_info=True,
)
- abort(403)
+ raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
detail="Expired signature")
except InvalidIssuedAtError:
logger.warning(
- "The request was issues in the future. Make sure that all
components "
+ "The request was issued in the future. Make sure that all
components "
"in your system have synchronized clocks. "
"See more at %s",
get_docs_url("configurations-ref.html#secret-key"),
exc_info=True,
)
- abort(403)
+ raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
detail="Token issued in future")
except Exception:
logger.warning("Unknown error", exc_info=True)
- abort(403)
+ raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
detail="Authentication failed")
- @flask_app.route("/log/<path:filename>")
- def serve_logs_view(filename):
- return send_from_directory(log_directory, filename,
mimetype="application/json", as_attachment=False)
- return flask_app
+def create_app():
+ leeway = conf.getint("webserver", "log_request_clock_grace", fallback=30)
+ log_directory = os.path.expanduser(conf.get("logging", "BASE_LOG_FOLDER"))
+ log_config_class = conf.get("logging", "logging_config_class")
+ if log_config_class:
+ logger.info("Detected user-defined logging config. Attempting to load
%s", log_config_class)
+ try:
+ logging_config = import_string(log_config_class)
+ try:
+ base_log_folder =
logging_config["handlers"]["task"]["base_log_folder"]
+ except KeyError:
+ base_log_folder = None
+ if base_log_folder is not None:
+ log_directory = base_log_folder
+ logger.info(
+ "Successfully imported user-defined logging config.
FastAPI App will serve log from %s",
+ log_directory,
+ )
+ else:
+ logger.warning(
+ "User-defined logging config does not specify
'base_log_folder'. "
+ "FastAPI App will use default log directory %s",
+ base_log_folder,
+ )
+ except Exception as e:
+ raise ImportError(f"Unable to load {log_config_class} due to
error: {e}")
+
+ fastapi_app = FastAPI()
+ fastapi_app.state.signer = JWTValidator(
Review Comment:
Nice! TIL a bit more about fast_api by reviewing this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]