URL: https://github.com/freeipa/freeipa/pull/1001 Author: flo-renaud Title: #1001: Fix ipa config-mod --ca-renewal-master Action: opened
PR body: """ commit bddb90f38a3505a2768862d2f814c5e749a7dcde added the support for multivalued server attributes (for pkinit_server_server), but this introduced an API change where the setter and getter of ServerAttribute are expecting list of values. When a SingleValuedServerAttribute is used, we need to convert one elem into a list containing this elem and vice-versa, so that the ipa config-mod and ipa config_show APIs are not modified. https://pagure.io/freeipa/issue/7120 """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/1001/head:pr1001 git checkout pr1001
From 709e131b79f8548c39cbe8f573afe89817deb3a6 Mon Sep 17 00:00:00 2001 From: Florence Blanc-Renaud <f...@redhat.com> Date: Wed, 23 Aug 2017 16:31:18 +0200 Subject: [PATCH] Fix ipa config-mod --ca-renewal-master commit bddb90f38a3505a2768862d2f814c5e749a7dcde added the support for multivalued server attributes (for pkinit_server_server), but this introduced an API change where the setter and getter of ServerAttribute are expecting list of values. When a SingleValuedServerAttribute is used, we need to convert one elem into a list containing this elem and vice-versa, so that the ipa config-mod and ipa config_show APIs are not modified. https://pagure.io/freeipa/issue/7120 --- ipaserver/plugins/serverroles.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ipaserver/plugins/serverroles.py b/ipaserver/plugins/serverroles.py index b41fb45d16..0abf48ae52 100644 --- a/ipaserver/plugins/serverroles.py +++ b/ipaserver/plugins/serverroles.py @@ -46,6 +46,7 @@ from ipalib.backend import Backend from ipalib.plugable import Registry from ipaserver.servroles import (attribute_instances, ENABLED, role_instances) +from ipaserver.servroles import SingleValuedServerAttribute if six.PY3: @@ -142,6 +143,10 @@ def config_retrieve(self, servrole): attr_value = attr.get(self.api) if attr_value: + # attr can be a SingleValuedServerAttribute + # in this case, the API expects a value, not a list of values + if isinstance(attr, SingleValuedServerAttribute): + attr_value = attr_value[0] result.update({name: attr_value}) return result @@ -149,6 +154,13 @@ def config_retrieve(self, servrole): def config_update(self, **attrs_values): for attr, value in attrs_values.items(): try: + # when the attribute is single valued, it will be stored + # in a SingleValuedServerAttribute. The set method expects + # a list containing a single value. + # We need to convert value to a list containing value + if isinstance(self.attributes[attr], + SingleValuedServerAttribute): + value = [value] self.attributes[attr].set(self.api, value) except KeyError: raise errors.NotFound(
_______________________________________________ FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org