@target_validator 用于验证参数是否满足必要条件,must_specify_attrs为一个嵌套数组,该数组内允许str、 tuple两种数据类型,原数组内所有属性满足条件为且,若存在嵌套数组,则满足条件为或,如: ['domain', 'username'] 含义为target需要存在domain AND username ['domain', 'username', ('password', 'hashes')] 表示 target中需要存在 domain AND username AND (password OR hashes)
(target: Target, must_specify_attrs: list)
| 28 | |
| 29 | |
| 30 | def target_validator(target: Target, must_specify_attrs: list): |
| 31 | """ |
| 32 | @target_validator 用于验证参数是否满足必要条件,must_specify_attrs为一个嵌套数组,该数组内允许str、 |
| 33 | tuple两种数据类型,原数组内所有属性满足条件为且,若存在嵌套数组,则满足条件为或,如: |
| 34 | ['domain', 'username'] 含义为target需要存在domain AND username |
| 35 | ['domain', 'username', ('password', 'hashes')] 表示 |
| 36 | target中需要存在 domain AND username AND (password OR hashes) |
| 37 | """ |
| 38 | for must_specify_attr in must_specify_attrs: |
| 39 | try: |
| 40 | if isinstance(must_specify_attr, str): |
| 41 | attr = getattr(target, must_specify_attr) |
| 42 | if not attr: |
| 43 | logger.error(f'parameter {must_specify_attr} not specified.') |
| 44 | return False |
| 45 | if isinstance(must_specify_attr, tuple): |
| 46 | if not any([getattr(target, must_attr) for must_attr in must_specify_attr]): |
| 47 | logger.error(f'one of the following parameters must specified [{", ".join(must_specify_attr)}] .') |
| 48 | except AttributeError as e: |
| 49 | logger.error(f'get attribute error: {e}') |
| 50 | return False |
| 51 | |
| 52 | return True |
| 53 | |
| 54 | |
| 55 | def multi_run(fn, targets, max_worker=10): |