
    h                     j    d dl Z d dlZd dlmZmZ d dlmZ  ej                  e      Z	 G d de      Z
y)    N)DictAny)CountermeasurePluginc                   @    e Zd ZdZdeeef   deeef   fdZdefdZy)RandomErrorCountermeasureu8   
    随机返回HTTP错误码的反制动作实现
    contextreturnc                     |j                  di       }|j                  dg d      }|st        j                  d       g d}t        j                  |      }t        j                  d|        d|iS )u  
        执行随机错误码返回动作。
        :param context: 包含 'config' 键的字典，'config' 中可包含 'error_codes' 列表。
                          默认值: [400, 401, 403, 404, 500, 502, 503]。
        :return: 包含执行结果的字典。
        configerror_codes)i  i  i  i  i  i  i  z6No error codes provided in config, using default list.z'Simulated returning random error code: error_code_applied)getloggerwarningrandomchoiceinfo)selfr   r   r   selected_errors        <D:\code\IVE\./countermeasures\random_error\countermeasure.pyexecutez!RandomErrorCountermeasure.execute   sh     Xr*jj0STNNST=K{3=n=MNO$n55    c                      y)Nz<Randomly returns an HTTP error code (40x/50x) to the client. )r   s    r   get_descriptionz)RandomErrorCountermeasure.get_description    s    Mr   N)	__name__
__module____qualname____doc__r   strr   r   r   r   r   r   r   r   	   s8    6tCH~ 6$sCx. 6$N Nr   r   )r   loggingtypingr   r   pluginsr   	getLoggerr   r   r   r   r   r   <module>r%      s4       ( 
		8	$N 4 Nr   