A ternary method to enable calling either of the methods based on the configuration for the MFA. When MFA is enabled and has a valid supported auth methods, 'execute_if_enabled' method is executed, otherwise - 'execute_if_disabled' method is executed. Args: execute
(execute_if_enabled, execute_if_disabled)
| 135 | |
| 136 | |
| 137 | def mfa_enabled(execute_if_enabled, execute_if_disabled) -> None: |
| 138 | """ |
| 139 | A ternary method to enable calling either of the methods based on the |
| 140 | configuration for the MFA. |
| 141 | |
| 142 | When MFA is enabled and has a valid supported auth methods, |
| 143 | 'execute_if_enabled' method is executed, otherwise - |
| 144 | 'execute_if_disabled' method is executed. |
| 145 | |
| 146 | Args: |
| 147 | execute_if_enabled (Callable[[], None]): Method to executed when MFA |
| 148 | is enabled. |
| 149 | execute_if_disabled (Callable[[], None]): Method to be executed when |
| 150 | MFA is disabled. |
| 151 | |
| 152 | Returns: |
| 153 | None: Expecting the methods to return None as it will not be consumed. |
| 154 | |
| 155 | NOTE: Removed the typing anotation as it was giving errors. |
| 156 | """ |
| 157 | |
| 158 | is_server_mode = getattr(config, 'SERVER_MODE', False) |
| 159 | enabled = getattr(config, "MFA_ENABLED", False) |
| 160 | supported_methods = getattr(config, "MFA_SUPPORTED_METHODS", []) |
| 161 | |
| 162 | if is_server_mode is True and enabled is True and \ |
| 163 | isinstance(supported_methods, list): |
| 164 | supported_methods, _ = segregate_valid_and_invalid_mfa_methods( |
| 165 | supported_methods |
| 166 | ) |
| 167 | |
| 168 | if len(supported_methods) > 0: |
| 169 | return execute_if_enabled() |
| 170 | |
| 171 | return execute_if_disabled() |
| 172 | |
| 173 | |
| 174 | def mfa_user_force_registration_required(register, not_register) -> None: |