e3ffab
From 9adf96c47f37ee027cef03dc5bed49c2567ae75d Mon Sep 17 00:00:00 2001
e3ffab
From: Nathaniel McCallum <npmccallum@redhat.com>
e3ffab
Date: Thu, 6 Nov 2014 15:30:13 -0500
e3ffab
Subject: [PATCH] Enable QR code display by default in otptoken-add
e3ffab
e3ffab
This is possible because python-qrcode's output now fits in a standard
e3ffab
terminal. Also, update ipa-otp-import and otptoken-add-yubikey to
e3ffab
disable QR code output as it doesn't make sense in these contexts.
e3ffab
e3ffab
https://fedorahosted.org/freeipa/ticket/4703
e3ffab
e3ffab
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
e3ffab
---
e3ffab
 API.txt                                  | 3 ++-
e3ffab
 VERSION                                  | 4 ++--
e3ffab
 ipalib/plugins/otptoken.py               | 5 +++--
e3ffab
 ipalib/plugins/otptoken_yubikey.py       | 1 +
e3ffab
 ipaserver/install/ipa_otptoken_import.py | 2 +-
e3ffab
 5 files changed, 9 insertions(+), 6 deletions(-)
e3ffab
e3ffab
diff --git a/API.txt b/API.txt
e3ffab
index 0000491d7a76fd1d2d50208d314d1600839ce295..2a63f1e2349f0df69433fa7cb742e269cd42d79f 100644
e3ffab
--- a/API.txt
e3ffab
+++ b/API.txt
e3ffab
@@ -2592,7 +2592,7 @@ output: Entry('result', <type 'dict'>, Gettext('A dictionary representing an LDA
e3ffab
 output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), None)
e3ffab
 output: PrimaryKey('value', None, None)
e3ffab
 command: otptoken_add
e3ffab
-args: 1,22,3
e3ffab
+args: 1,23,3
e3ffab
 arg: Str('ipatokenuniqueid', attribute=True, cli_name='id', multivalue=False, primary_key=True, required=False)
e3ffab
 option: Str('addattr*', cli_name='addattr', exclude='webui')
e3ffab
 option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui')
e3ffab
@@ -2611,6 +2611,7 @@ option: Int('ipatokentotpclockoffset', attribute=True, autofill=True, cli_name='
e3ffab
 option: Int('ipatokentotptimestep', attribute=True, autofill=True, cli_name='interval', default=30, minvalue=5, multivalue=False, required=False)
e3ffab
 option: Str('ipatokenvendor', attribute=True, cli_name='vendor', multivalue=False, required=False)
e3ffab
 option: Flag('no_members', autofill=True, default=False, exclude='webui')
e3ffab
+option: Flag('no_qrcode', autofill=True, default=False)
e3ffab
 option: Flag('qrcode?', autofill=True, default=False)
e3ffab
 option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui')
e3ffab
 option: Str('setattr*', cli_name='setattr', exclude='webui')
e3ffab
diff --git a/VERSION b/VERSION
e3ffab
index 138648545c3cbe395303fa3cfa9dc99623b7e6c2..750b5058867ca5f073a083009c4aadeeb0240c35 100644
e3ffab
--- a/VERSION
e3ffab
+++ b/VERSION
e3ffab
@@ -90,5 +90,5 @@ IPA_DATA_VERSION=20100614120000
e3ffab
 #                                                      #
e3ffab
 ########################################################
e3ffab
 IPA_API_VERSION_MAJOR=2
e3ffab
-IPA_API_VERSION_MINOR=108
e3ffab
-# Last change: pvoborni - manage authorization of keytab operations
e3ffab
+IPA_API_VERSION_MINOR=109
e3ffab
+# Last change: npmccallum - display qrcode by default
e3ffab
diff --git a/ipalib/plugins/otptoken.py b/ipalib/plugins/otptoken.py
e3ffab
index f48feeee0502992f1b5fed4f342cace1c404624b..f0850854f98e84e44acdcef311225220ac0129a3 100644
e3ffab
--- a/ipalib/plugins/otptoken.py
e3ffab
+++ b/ipalib/plugins/otptoken.py
e3ffab
@@ -268,7 +268,8 @@ class otptoken_add(LDAPCreate):
e3ffab
     msg_summary = _('Added OTP token "%(value)s"')
e3ffab
 
e3ffab
     takes_options = LDAPCreate.takes_options + (
e3ffab
-        Flag('qrcode?', label=_('Display QR code')),
e3ffab
+        Flag('qrcode?', label=_('(deprecated)'), flags=('no_option')),
e3ffab
+        Flag('no_qrcode', label=_('Do not display QR code'), default=False),
e3ffab
     )
e3ffab
 
e3ffab
     has_output_params = LDAPCreate.has_output_params + (
e3ffab
@@ -348,7 +349,7 @@ class otptoken_add(LDAPCreate):
e3ffab
         rv = super(otptoken_add, self).output_for_cli(textui, output, *args, **options)
e3ffab
 
e3ffab
         # Print QR code to terminal if specified
e3ffab
-        if uri and options.get('qrcode', False):
e3ffab
+        if uri and not options.get('no_qrcode', False):
e3ffab
             print "\n"
e3ffab
             qr = qrcode.QRCode()
e3ffab
             qr.add_data(uri)
e3ffab
diff --git a/ipalib/plugins/otptoken_yubikey.py b/ipalib/plugins/otptoken_yubikey.py
e3ffab
index e70ddb6e42b5ea34d7ebecb252d6bbd73ac64d03..7095887ac7cdf5d4b7d0d30edc6cab0222246664 100644
e3ffab
--- a/ipalib/plugins/otptoken_yubikey.py
e3ffab
+++ b/ipalib/plugins/otptoken_yubikey.py
e3ffab
@@ -124,6 +124,7 @@ class otptoken_add_yubikey(Command):
e3ffab
                                                 ipatokenotpalgorithm=u'sha1',
e3ffab
                                                 ipatokenhotpcounter=0,
e3ffab
                                                 ipatokenotpkey=key,
e3ffab
+                                                no_qrcode=True,
e3ffab
                                                 **options)
e3ffab
 
e3ffab
         # Suppress values we don't want to return.
e3ffab
diff --git a/ipaserver/install/ipa_otptoken_import.py b/ipaserver/install/ipa_otptoken_import.py
e3ffab
index 31a6902014b8e3b2aafb3ba98a4190dc2059a3e7..b78aba93a2edc987450d921c87ea4f61b014b419 100644
e3ffab
--- a/ipaserver/install/ipa_otptoken_import.py
e3ffab
+++ b/ipaserver/install/ipa_otptoken_import.py
e3ffab
@@ -517,7 +517,7 @@ class OTPTokenImport(admintool.AdminTool):
e3ffab
             # Parse tokens
e3ffab
             for keypkg in self.doc.getKeyPackages():
e3ffab
                 try:
e3ffab
-                    api.Command.otptoken_add(keypkg.id, **keypkg.options)
e3ffab
+                    api.Command.otptoken_add(keypkg.id, no_qrcode=True, **keypkg.options)
e3ffab
                 except Exception as e:
e3ffab
                     self.log.warn("Error adding token: %s", e)
e3ffab
                 else:
e3ffab
-- 
e3ffab
2.1.0
e3ffab