From 4a243536b3200caff80f9f8317892e3b38888edf Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Wed, 13 Apr 2016 15:50:57 +0200 Subject: [PATCH] otptoken_yubikey: fix otptoken_add_yubikey arguments Copy args, options and output of otptoken_add_yubikey from otptoken_add. https://fedorahosted.org/freeipa/ticket/4739 Reviewed-By: David Kupka --- API.txt | 11 ++++- VERSION | 4 +- ipalib/plugins/otptoken_yubikey.py | 66 +++++++++++++++--------------- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/API.txt b/API.txt index 2d02ecd8c..c61d7dfc4 100644 --- a/API.txt +++ b/API.txt @@ -2973,17 +2973,24 @@ output: Output('completed', type=[]) output: Output('failed', type=[]) output: Entry('result') command: otptoken_add_yubikey -args: 1,8,1 +args: 1,13,3 arg: Str('ipatokenuniqueid?', cli_name='id') +option: Str('addattr*', cli_name='addattr') +option: Flag('all', autofill=True, cli_name='all', default=False) option: Str('description?', cli_name='desc') option: Bool('ipatokendisabled?', cli_name='disabled') option: DateTime('ipatokennotafter?', cli_name='not_after') option: DateTime('ipatokennotbefore?', cli_name='not_before') option: IntEnum('ipatokenotpdigits?', autofill=True, cli_name='digits', default=6, values=[6, 8]) option: Str('ipatokenowner?', cli_name='owner') +option: Flag('no_members', autofill=True, default=False) +option: Flag('raw', autofill=True, cli_name='raw', default=False) +option: Str('setattr*', cli_name='setattr') option: IntEnum('slot?', cli_name='slot', values=[1, 2]) option: Str('version?') -output: Output('result') +output: Entry('result') +output: Output('summary', type=[, ]) +output: PrimaryKey('value') command: otptoken_del args: 1,2,3 arg: Str('ipatokenuniqueid+', cli_name='id') diff --git a/VERSION b/VERSION index 17b335280..d5c54c710 100644 --- a/VERSION +++ b/VERSION @@ -90,5 +90,5 @@ IPA_DATA_VERSION=20100614120000 # # ######################################################## IPA_API_VERSION_MAJOR=2 -IPA_API_VERSION_MINOR=167 -# Last change: dns: do not rely on server data structures in code called on client +IPA_API_VERSION_MINOR=168 +# Last change: otptoken_yubikey: fix otptoken_add_yubikey arguments diff --git a/ipalib/plugins/otptoken_yubikey.py b/ipalib/plugins/otptoken_yubikey.py index 0cbda1b2e..207d0a6e9 100644 --- a/ipalib/plugins/otptoken_yubikey.py +++ b/ipalib/plugins/otptoken_yubikey.py @@ -17,17 +17,16 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from ipalib import _, Str, IntEnum -from ipalib.errors import NotFound -from ipalib.plugable import Registry -from ipalib.frontend import Command -from ipalib.plugins.otptoken import otptoken - import os +import six import usb.core import yubico -import six + +from ipalib import _, IntEnum +from ipalib.errors import NotFound +from ipalib.frontend import Command +from ipalib.plugable import Registry if six.PY3: unicode = str @@ -55,35 +54,40 @@ topic = ('otp', _('One time password commands')) class otptoken_add_yubikey(Command): __doc__ = _('Add a new YubiKey OTP token.') - takes_args = ( - Str('ipatokenuniqueid?', - cli_name='id', - label=_('Unique ID'), - primary_key=True, - ), - ) - - takes_options = Command.takes_options + ( + takes_options = ( IntEnum('slot?', cli_name='slot', label=_('YubiKey slot'), values=(1, 2), ), - ) + tuple(x for x in otptoken.takes_params if x.name in ( - 'description', - 'ipatokenowner', - 'ipatokendisabled', - 'ipatokennotbefore', - 'ipatokennotafter', - 'ipatokenotpdigits' - )) + ) - has_output_params = Command.has_output_params + \ - tuple(x for x in otptoken.takes_params if x.name in ( - 'ipatokenvendor', - 'ipatokenmodel', - 'ipatokenserial', - )) + def get_args(self): + for arg in self.api.Command.otptoken_add.args(): + yield arg + for arg in super(otptoken_add_yubikey, self).get_args(): + yield arg + + def get_options(self): + for option in self.api.Command.otptoken_add.options(): + if option.name not in ('type', + 'ipatokenvendor', + 'ipatokenmodel', + 'ipatokenserial', + 'ipatokenotpalgorithm', + 'ipatokenhotpcounter', + 'ipatokenotpkey', + 'ipatokentotpclockoffset', + 'ipatokentotptimestep', + 'no_qrcode', + 'qrcode', + 'version'): + yield option + for option in super(otptoken_add_yubikey, self).get_options(): + yield option + + def _iter_output(self): + return self.api.Command.otptoken_add.output() def forward(self, *args, **kwargs): # Open the YubiKey @@ -145,6 +149,4 @@ class otptoken_add_yubikey(Command): # Return which slot was used for writing. answer.get('result', {})['slot'] = kwargs['slot'] - del answer['value'] # Why does this cause an error if omitted? - del answer['summary'] # Why does this cause an error if omitted? return answer