Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
make pyqrcode and onetimepass optional, check imps
Browse files Browse the repository at this point in the history
  • Loading branch information
TillerBurr committed May 30, 2019
1 parent 4a766a1 commit 4f909eb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
47 changes: 37 additions & 10 deletions flask_security/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,21 +611,48 @@ def _register_i18n():

# configuration mismatch check
if cv('TWO_FACTOR', app=app) is True and\
len(cv('TWO_FACTOR_ENABLED_METHODS', app=app)) < 1:
len(cv('TWO_FACTOR_ENABLED_METHODS',
app=app)) < 1: # pragma: no cover

raise ValueError()

flag = False
try:
import importlib.util as import_util
flag = import_util.find_spec('twilio')
except:
pass
config_value = cv('TWO_FACTOR', app=app)
if config_value: # pragma: no cover
self.check_two_factor_modules('onetimepass',
'TWO_FACTOR', config_value)
self.check_two_factor_modules('pyqrcode',
'TWO_FACTOR', config_value)

if not flag and cv('TWO_FACTOR_SMS_SERVICE', app=app)\
== 'Twilio':
raise ValueError()
config_value = cv('TWO_FACTOR_SMS_SERVICE', app=app)

if config_value == 'Twilio': # pragma: no cover
self.check_two_factor_modules('twilio',
'TWO_FACTOR_SMS_SERVICE',
config_value)

return state

def check_two_factor_modules(self, module,
config_name,
config_value): # pragma: no cover
PY3 = sys.version_info[0] == 3
if PY3:
from importlib.util import find_spec
module_exists = find_spec(module)

else:
import imp
try:
imp.find_module(module)
module_exists = True
except ImportError:
module_exists = False

if not module_exists:
raise ValueError('{} is required for {} = {}'
.format(module, config_name, config_value))

return module_exists
return state

def render_template(self, *args, **kwargs):
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
'isort>=4.2.2',
'mock>=1.3.0',
'mongoengine>=0.12.0',
'onetimepass>=1.0.1',
'pony>=0.7.4',
'pydocstyle>=1.0.0',
'pytest-cache>=1.0',
'pytest-cov>=2.4.0',
'pytest-flakes>=1.0.1',
'pytest-pep8>=1.0.6',
'pytest>=3.3.0',
'pyqrcode>=1.2',
'sqlalchemy>=1.1.0',

]
Expand Down

1 comment on commit 4f909eb

@jwag956
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And remove from install_requires!

couple other things:

  1. would you be willing to do this on the branch in my fork so I don't have to cherry-pick etc? Turns out my fork has fixes to make unit tests much faster and easy to do from your local machine so you don't have to keep pushing.

  2. On that branch we can continue some conversations about how to wrap this up. I am most concerned as I mentioned with things that would require breaking changes to fix - improvements can wait. Even testing - I am really only concerned with drop in coverage for existing code - we can add tests to @2fa later.

Please sign in to comment.