Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mekhanik evgenii/fix 525 3 #557

Merged
merged 6 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"prepare",
"util",
"networker",
"custom_error_page",
]

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
35 changes: 35 additions & 0 deletions helpers/custom_error_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Custom error page generator.

Tempesta administrator can specify files with page bodies for error responses
generated by Tempesta FW.
"""
from helpers import tf_cfg

__author__ = "Tempesta Technologies, Inc."
__copyright__ = "Copyright (C) 2023 Tempesta Technologies, Inc."
__license__ = "GPL2"


class CustomErrorPageGenerator(object):
def __init__(self, data, f_path=None, default=False):
workdir = tf_cfg.cfg.get("General", "workdir")
self.f_path = f_path if f_path else workdir + "/tempesta.html"
self.data = data
if default:
self.generate()

@staticmethod
def __write(path, data):
with open(path, "wt") as fdesc:
Vitaly-Skopets marked this conversation as resolved.
Show resolved Hide resolved
fdesc.write(data)

def generate(self):
self.__write(self.f_path, data)

def __str__(self):
assert self.data, "Stringify null custom error page object"
return self.data

def get_file_path(self):
return self.f_path
Loading