Previous topic

securitylib.throttling.client — Throttling client functions

Next topic

securitylib.throttling.server — Throttling server functions

This Page

securitylib.throttling.common — Throttling common functions

class securitylib.throttling.common.CountersStorage(storage_client, config=None)

This class represents the storage used to store counters and can be used to configure storage parameters.

Parameters:
  • storage_client (object) –

    Object used to actually access the storage.

    At a minimum, the storage should have two methods, get(key) and set(key, value), where both key and value are strings.

    A typical example is an memcache.Client instance.

  • config (dict) –

    A dictionary containing storage parameters (dictionary keys are the parameter name and dictionary values are the parameter value). Allows defining the format of the storage keys, and the expiration times for each type of counter.

    You can ommit all dictionary keys except for the authenticator_key parameter, the missing keys will be taken from the default configuration.

    Structure:
    Key Type Description
    keys_prefix string Prefix for all storage keys.
    counter_keys_formats dictionary with string values Formats for each type of counter.
    total_format string Total format of the storage keys, including the prefix, the context and the specific counter key.
    expiration_times dictionary with integer values Expiration time for each type of counter, in seconds.
    authenticator_key string Authenticator key as generated by generate_authenticator_key().

    Default configuration:

    {
        'keys_prefix': '',
        'counter_keys_formats': {
            'ip': 'ip:{ip}',
            'user': 'user:{user}',
            'pwd': 'pwd:{pwd}',
            'ip_user': 'ip_user:{ip}{user}',
            'ip_pwd': 'ip_pwd:{ip}{pwd}',
        },
        'total_format': '{keys_prefix}:{ctx}:{counter_key}',
        'expiration_times': {
            'ip': 3600,
            'user': 3 * 3600,
            'pwd': 3 * 3600,
            'ip_user': 3 * 3600,
            'ip_pwd': 3 * 3600,
        },
    }
    
class securitylib.throttling.common.SessionStorage(storage_client, config=None)

This class represents the storage used to store the throttling session and can be used to configure storage parameters.

Parameters:
  • storage_client (object) –

    Object used to actually access the storage.

    At a minimum, the storage should have two methods, get(key) and set(key, value), where both key and value are strings.

    A typical example is an memcache.Client instance.

  • config (dict) –

    A dictionary containing storage parameters (dictionary keys are the parameter name and dictionary values are the parameter value). Allows defining the format of the storage key, and its expiration time.

    You can ommit the whole dictionary or some of its keys as the values for the missing keys will be taken from the default configuration.

    Structure:
    Key Type Description
    key_prefix string Prefix for all storage keys.
    session_key_format string Format of the storage key.
    total_format string Total format of the storage key, including the prefix and the session storage key.
    expiration_time integer Expiration time for the session, in seconds.

    Default configuration:

    {
        'key_prefix': '',
        'session_key_format': 'throttling_session:{session_id}',
        'total_format': '{key_prefix}:{session_key}',
        'expiration_time': 3600 * 24 * 30,  # one month
    }