pointsecio.handlers

This module defines error handlers, operations that produce proper response problems.

Module Contents

Classes

AuthErrorHandler

Wraps an error with authentication.

ResolverErrorHandler

Handler for responding to ResolverError.

PointsecHandler

Handler instances dispatch logging events to specific destinations.

Attributes

logger

RESOLVER_ERROR_ENDPOINT_RANDOM_DIGITS

pointsecio.handlers.logger
pointsecio.handlers.RESOLVER_ERROR_ENDPOINT_RANDOM_DIGITS = 6
class pointsecio.handlers.AuthErrorHandler(api, exception, security, security_definitions)

Bases: pointsecio.operations.secure.SecureOperation

Wraps an error with authentication.

This class uses the exception instance to produce the proper response problem in case the request is authenticated.

Parameters
  • exception (werkzeug.exceptions.HTTPException) – the exception to be wrapped with authentication

  • security (list) – list of security rules the application uses by default

  • security_definitions (dict) – Security Definitions Object

property function(self)

Configured error auth handler.

handle(self, *args, **kwargs)

Actual handler for the execution after authentication.

property api(self)
property security(self)
property security_schemes(self)
property security_decorator(self)

Gets the security decorator for operation

From Swagger Specification:

Security Definitions Object

A declaration of the security schemes available to be used in the specification.

This does not enforce the security schemes on the operations and only serves to provide the relevant details for each scheme.

Operation Object -> security

A declaration of which security schemes are applied for this operation. The list of values describes alternative security schemes that can be used (that is, there is a logical OR between the security requirements). This definition overrides any declared top-level security. To remove a top-level security declaration, an empty array can be used.

Security Requirement Object

Lists the required security schemes to execute this operation. The object can have multiple security schemes declared in it which are all required (that is, there is a logical AND between the schemes).

The name used for each property MUST correspond to a security scheme declared in the Security Definitions.

Return type

types.FunctionType

get_mimetype(self)
class pointsecio.handlers.ResolverErrorHandler(api, status_code, exception, security, security_definitions)

Bases: pointsecio.operations.secure.SecureOperation

Handler for responding to ResolverError.

Parameters
  • security (list) – list of security rules the application uses by default

  • security_definitions (dict) –

    Security Definitions Object

property function(self)
handle(self, *args, **kwargs)
property operation_id(self)
property randomize_endpoint(self)
get_path_parameter_types(self)
property api(self)
property security(self)
property security_schemes(self)
property security_decorator(self)

Gets the security decorator for operation

From Swagger Specification:

Security Definitions Object

A declaration of the security schemes available to be used in the specification.

This does not enforce the security schemes on the operations and only serves to provide the relevant details for each scheme.

Operation Object -> security

A declaration of which security schemes are applied for this operation. The list of values describes alternative security schemes that can be used (that is, there is a logical OR between the security requirements). This definition overrides any declared top-level security. To remove a top-level security declaration, an empty array can be used.

Security Requirement Object

Lists the required security schemes to execute this operation. The object can have multiple security schemes declared in it which are all required (that is, there is a logical AND between the schemes).

The name used for each property MUST correspond to a security scheme declared in the Security Definitions.

Return type

types.FunctionType

get_mimetype(self)
class pointsecio.handlers.PointsecHandler(token, pointsec_type='python', logs_drain_timeout=3, url='https://27rznp5fh5.execute-api.eu-west-2.amazonaws.com/dev/mock', debug=False, backup_logs=True, network_timeout=10.0, retries_no=4, retry_timeout=2)

Bases: logging.Handler

Handler instances dispatch logging events to specific destinations.

The base handler class. Acts as a placeholder which defines the Handler interface. Handlers can optionally use Formatter instances to format records as desired. By default, no formatter is specified; in this case, the ‘raw’ message as determined by record.message is logged.

Initializes the instance - basically setting the formatter to None and the filter list to empty.

name
__del__(self)
extra_fields(self, message)
flush(self)

Ensure all logging output has been flushed.

This version does nothing and is intended to be implemented by subclasses.

format(self, record)

Format the specified record.

If a formatter is set, use it. Otherwise, use the default formatter for the module.

format_exception(self, exc_info)
format_message(self, message)
emit(self, record)

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

get_name(self)
set_name(self, name)
createLock(self)

Acquire a thread lock for serializing access to the underlying I/O.

acquire(self)

Acquire the I/O thread lock.

release(self)

Release the I/O thread lock.

setLevel(self, level)

Set the logging level of this handler. level must be an int or a str.

handle(self, record)

Conditionally emit the specified logging record.

Emission depends on filters which may have been added to the handler. Wrap the actual emission of the record with acquisition/release of the I/O thread lock. Returns whether the filter passed the record for emission.

setFormatter(self, fmt)

Set the formatter for this handler.

close(self)

Tidy up any resources used by the handler.

This version removes the handler from an internal map of handlers, _handlers, which is used for handler lookup by name. Subclasses should ensure that this gets called from overridden close() methods.

handleError(self, record)

Handle errors which occur during an emit() call.

This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The record which was being processed is passed in to this method.

__repr__(self)

Return repr(self).

addFilter(self, filter)

Add the specified filter to this handler.

removeFilter(self, filter)

Remove the specified filter from this handler.

filter(self, record)

Determine if a record is loggable by consulting all the filters.

The default is to allow the record to be logged; any filter can veto this and the record is then dropped. Returns a zero value if a record is to be dropped, else non-zero.

Changed in version 3.2: Allow filters to be just callables.