mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-10-24 14:17:41 -05:00
Refactor the role/attribute member reporting code
The `config` object now hosts a generic method for updating the config entry for desired server role configuration (if not empty). The duplicated code in dns/trust/vaultconfig commands was replaced by a call to a common method. https://pagure.io/freeipa/issue/6937 Reviewed-By: Jan Cholasta <jcholast@redhat.com> Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
This commit is contained in:
1 parent
bddb90f38a
commit
cac7e49daa
4 files changed
+27
-41
No files matched your search
@@ -267,15 +267,21 @@ class config(LDAPObject):
|
|||||||
def get_dn(self, *keys, **kwargs):
|
def get_dn(self, *keys, **kwargs):
|
||||||
return DN(('cn', 'ipaconfig'), ('cn', 'etc'), api.env.basedn)
|
return DN(('cn', 'ipaconfig'), ('cn', 'etc'), api.env.basedn)
|
||||||
|
|
||||||
def show_servroles_attributes(self, entry_attrs, **options):
|
def update_entry_with_role_config(self, role_name, entry_attrs):
|
||||||
|
backend = self.api.Backend.serverroles
|
||||||
|
|
||||||
|
role_config = backend.config_retrieve(role_name)
|
||||||
|
for key, value in role_config.items():
|
||||||
|
if value:
|
||||||
|
entry_attrs.update({key: value})
|
||||||
|
|
||||||
|
|
||||||
|
def show_servroles_attributes(self, entry_attrs, *roles, **options):
|
||||||
if options.get('raw', False):
|
if options.get('raw', False):
|
||||||
return
|
return
|
||||||
|
|
||||||
backend = self.api.Backend.serverroles
|
for role in roles:
|
||||||
|
self.update_entry_with_role_config(role, entry_attrs)
|
||||||
for role in ("CA server", "IPA master", "NTP server"):
|
|
||||||
config = backend.config_retrieve(role)
|
|
||||||
entry_attrs.update(config)
|
|
||||||
|
|
||||||
def gather_trusted_domains(self):
|
def gather_trusted_domains(self):
|
||||||
"""
|
"""
|
||||||
@@ -525,7 +531,8 @@ class config_mod(LDAPUpdate):
|
|||||||
keys, options, exc, call_func, *call_args, **call_kwargs)
|
keys, options, exc, call_func, *call_args, **call_kwargs)
|
||||||
|
|
||||||
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
||||||
self.obj.show_servroles_attributes(entry_attrs, **options)
|
self.obj.show_servroles_attributes(
|
||||||
|
entry_attrs, "CA server", "IPA master", "NTP server", **options)
|
||||||
return dn
|
return dn
|
||||||
|
|
||||||
|
|
||||||
@@ -534,5 +541,6 @@ class config_show(LDAPRetrieve):
|
|||||||
__doc__ = _('Show the current configuration.')
|
__doc__ = _('Show the current configuration.')
|
||||||
|
|
||||||
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
||||||
self.obj.show_servroles_attributes(entry_attrs, **options)
|
self.obj.show_servroles_attributes(
|
||||||
|
entry_attrs, "CA server", "IPA master", "NTP server", **options)
|
||||||
return dn
|
return dn
|
||||||
@@ -4184,16 +4184,6 @@ class dnsconfig(LDAPObject):
|
|||||||
if is_config_empty:
|
if is_config_empty:
|
||||||
result['summary'] = unicode(_('Global DNS configuration is empty'))
|
result['summary'] = unicode(_('Global DNS configuration is empty'))
|
||||||
|
|
||||||
def show_servroles_attributes(self, entry_attrs, **options):
|
|
||||||
if options.get('raw', False):
|
|
||||||
return
|
|
||||||
|
|
||||||
backend = self.api.Backend.serverroles
|
|
||||||
entry_attrs.update(
|
|
||||||
backend.config_retrieve("DNS server")
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@register()
|
@register()
|
||||||
class dnsconfig_mod(LDAPUpdate):
|
class dnsconfig_mod(LDAPUpdate):
|
||||||
__doc__ = _('Modify global DNS configuration.')
|
__doc__ = _('Modify global DNS configuration.')
|
||||||
@@ -4247,7 +4237,8 @@ class dnsconfig_mod(LDAPUpdate):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
||||||
self.obj.show_servroles_attributes(entry_attrs, **options)
|
self.api.Object.config.show_servroles_attributes(
|
||||||
|
entry_attrs, "DNS server", **options)
|
||||||
return dn
|
return dn
|
||||||
|
|
||||||
|
|
||||||
@@ -4261,7 +4252,8 @@ class dnsconfig_show(LDAPRetrieve):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
||||||
self.obj.show_servroles_attributes(entry_attrs, **options)
|
self.api.Object.config.show_servroles_attributes(
|
||||||
|
entry_attrs, "DNS server", **options)
|
||||||
return dn
|
return dn
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1278,22 +1278,6 @@ class trustconfig(LDAPObject):
|
|||||||
|
|
||||||
entry_attrs['ipantfallbackprimarygroup'] = [groupdn[0][0].value]
|
entry_attrs['ipantfallbackprimarygroup'] = [groupdn[0][0].value]
|
||||||
|
|
||||||
def show_servroles(self, entry_attrs, **options):
|
|
||||||
if options.get('raw', False):
|
|
||||||
return
|
|
||||||
|
|
||||||
backend = self.api.Backend.serverroles
|
|
||||||
|
|
||||||
adtrust_agents = backend.config_retrieve(
|
|
||||||
"AD trust agent"
|
|
||||||
)
|
|
||||||
adtrust_controllers = backend.config_retrieve(
|
|
||||||
"AD trust controller"
|
|
||||||
)
|
|
||||||
|
|
||||||
entry_attrs.update(adtrust_agents)
|
|
||||||
entry_attrs.update(adtrust_controllers)
|
|
||||||
|
|
||||||
|
|
||||||
@register()
|
@register()
|
||||||
class trustconfig_mod(LDAPUpdate):
|
class trustconfig_mod(LDAPUpdate):
|
||||||
@@ -1314,7 +1298,8 @@ class trustconfig_mod(LDAPUpdate):
|
|||||||
|
|
||||||
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
||||||
self.obj._convert_groupdn(entry_attrs, options)
|
self.obj._convert_groupdn(entry_attrs, options)
|
||||||
self.obj.show_servroles(entry_attrs, **options)
|
self.api.Object.config.show_servroles_attributes(
|
||||||
|
entry_attrs, "AD trust agent", "AD trust controller", **options)
|
||||||
return dn
|
return dn
|
||||||
|
|
||||||
|
|
||||||
@@ -1333,7 +1318,8 @@ class trustconfig_show(LDAPRetrieve):
|
|||||||
|
|
||||||
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
||||||
self.obj._convert_groupdn(entry_attrs, options)
|
self.obj._convert_groupdn(entry_attrs, options)
|
||||||
self.obj.show_servroles(entry_attrs, **options)
|
self.api.Object.config.show_servroles_attributes(
|
||||||
|
entry_attrs, "AD trust agent", "AD trust controller", **options)
|
||||||
|
|
||||||
return dn
|
return dn
|
||||||
|
|
||||||
|
|||||||
@@ -997,9 +997,9 @@ class vaultconfig_show(Retrieve):
|
|||||||
with self.api.Backend.kra.get_client() as kra_client:
|
with self.api.Backend.kra.get_client() as kra_client:
|
||||||
transport_cert = kra_client.system_certs.get_transport_cert()
|
transport_cert = kra_client.system_certs.get_transport_cert()
|
||||||
config = {'transport_cert': transport_cert.binary}
|
config = {'transport_cert': transport_cert.binary}
|
||||||
config.update(
|
|
||||||
self.api.Backend.serverroles.config_retrieve("KRA server")
|
self.api.Object.config.show_servroles_attributes(
|
||||||
)
|
config, "KRA server", **options)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'result': config,
|
'result': config,
|
||||||
|
|||||||
Reference in new issue
Block a user