|
| 1 | +import satosa.micro_services.base |
| 2 | +from satosa.logging_util import satosa_logging |
| 3 | + |
| 4 | +from satosa.response import Response |
| 5 | + |
| 6 | +import logging |
| 7 | + |
| 8 | +logger = logging.getLogger(__name__) |
| 9 | + |
| 10 | +class PingFrontend(satosa.frontends.base.FrontendModule): |
| 11 | + """ |
| 12 | + SATOSA frontend that responds to a query with a simple |
| 13 | + 200 OK, intended to be used as a simple heartbeat monitor. |
| 14 | + """ |
| 15 | + logprefix = "PING:" |
| 16 | + |
| 17 | + def __init__(self, auth_req_callback_func, internal_attributes, config, base_url, name): |
| 18 | + super().__init__(auth_req_callback_func, internal_attributes, base_url, name) |
| 19 | + |
| 20 | + self.config = config |
| 21 | + |
| 22 | + def handle_authn_response(self, context, internal_resp, extra_id_token_claims=None): |
| 23 | + """ |
| 24 | + See super class method satosa.frontends.base.FrontendModule#handle_authn_response |
| 25 | + :type context: satosa.context.Context |
| 26 | + :type internal_response: satosa.internal_data.InternalResponse |
| 27 | + :rtype oic.utils.http_util.Response |
| 28 | + """ |
| 29 | + raise NotImplementedError() |
| 30 | + |
| 31 | + def handle_backend_error(self, exception): |
| 32 | + """ |
| 33 | + See super class satosa.frontends.base.FrontendModule |
| 34 | + :type exception: satosa.exception.SATOSAError |
| 35 | + :rtype: oic.utils.http_util.Response |
| 36 | + """ |
| 37 | + raise NotImplementedError() |
| 38 | + |
| 39 | + def register_endpoints(self, backend_names): |
| 40 | + """ |
| 41 | + See super class satosa.frontends.base.FrontendModule |
| 42 | + :type backend_names: list[str] |
| 43 | + :rtype: list[(str, ((satosa.context.Context, Any) -> satosa.response.Response, Any))] |
| 44 | + :raise ValueError: if more than one backend is configured |
| 45 | + """ |
| 46 | + url_map = [("^{}".format(self.name), self.ping_endpoint)] |
| 47 | + |
| 48 | + return url_map |
| 49 | + |
| 50 | + def ping_endpoint(self, context): |
| 51 | + """ |
| 52 | + """ |
| 53 | + logprefix = PingFrontend.logprefix |
| 54 | + satosa_logging(logger, logging.DEBUG, "{} ping returning 200 OK".format(logprefix), context.state) |
| 55 | + |
| 56 | + msg = " " |
| 57 | + |
| 58 | + return Response(msg) |
0 commit comments