diff options
Diffstat (limited to 'ipalib/plugins/otptoken.py')
-rw-r--r-- | ipalib/plugins/otptoken.py | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/ipalib/plugins/otptoken.py b/ipalib/plugins/otptoken.py index 2bd3d3af5..fda05ce0b 100644 --- a/ipalib/plugins/otptoken.py +++ b/ipalib/plugins/otptoken.py @@ -17,13 +17,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -from __future__ import print_function -import sys - from .baseldap import LDAPObject, LDAPAddMember, LDAPRemoveMember from .baseldap import LDAPCreate, LDAPDelete, LDAPUpdate, LDAPSearch, LDAPRetrieve from ipalib import api, Int, Str, Bool, DateTime, Flag, Bytes, IntEnum, StrEnum, _, ngettext -from ipalib.messages import add_message, ResultFormattingError from ipalib.plugable import Registry from ipalib.errors import ( PasswordMismatch, @@ -32,16 +28,12 @@ from ipalib.errors import ( ValidationError) from ipalib.request import context from ipapython.dn import DN -from ipapython.version import API_VERSION import base64 -import locale import uuid -import qrcode import os import six -from six import StringIO from six.moves import urllib if six.PY3: @@ -361,75 +353,6 @@ class otptoken_add(LDAPCreate): _convert_owner(self.api.Object.user, entry_attrs, options) return super(otptoken_add, self).post_callback(ldap, dn, entry_attrs, *keys, **options) - def _get_qrcode(self, output, uri, version): - # Print QR code to terminal if specified - qr_output = StringIO() - qr = qrcode.QRCode() - qr.add_data(uri) - qr.make() - qr.print_ascii(out=qr_output, tty=False) - - encoding = getattr(sys.stdout, 'encoding', None) - if encoding is None: - encoding = locale.getpreferredencoding(False) - - try: - qr_code = qr_output.getvalue().decode(encoding) - except UnicodeError: - add_message( - version, - output, - message=ResultFormattingError( - message=_("Unable to display QR code using the configured " - "output encoding. Please use the token URI to " - "configure you OTP device") - ) - ) - return None - - if sys.stdout.isatty(): - output_width = self.api.Backend.textui.get_tty_width() - qr_code_width = len(qr_code.splitlines()[0]) - if qr_code_width > output_width: - add_message( - version, - output, - message=ResultFormattingError( - message=_( - "QR code width is greater than that of the output " - "tty. Please resize your terminal.") - ) - ) - - return qr - - def output_for_cli(self, textui, output, *args, **options): - # copy-pasted from ipalib/Frontend.__do_call() - # because option handling is broken on client-side - if 'version' in options: - pass - elif self.api.env.skip_version_check: - options['version'] = u'2.0' - else: - options['version'] = API_VERSION - - uri = output['result'].get('uri', None) - - if uri is not None and not options.get('no_qrcode', False): - qr = self._get_qrcode(output, uri, options['version']) - else: - qr = None - - rv = super(otptoken_add, self).output_for_cli( - textui, output, *args, **options) - - if qr is not None: - print("\n") - qr.print_ascii(tty=sys.stdout.isatty()) - print("\n") - - return rv - @register() class otptoken_del(LDAPDelete): |