From aa64ef03a04b6e2509924a9f968724232123be3a Mon Sep 17 00:00:00 2001 From: Florence Blanc-Renaud Date: May 03 2018 14:39:58 +0000 Subject: authselect migration: use stable interface to query current config The code currently parses the output of "authselect current" in order to extract the current profile and options. Example: $ authselect current Profile ID: sssd Enabled features: - with-mkhomedir It is easier to use the output of "authselect current --raw". Example: $ authselect current --raw sssd with-mkhomedir Related to https://pagure.io/freeipa/issue/7377 Reviewed-By: Christian Heimes --- diff --git a/ipaplatform/redhat/authconfig.py b/ipaplatform/redhat/authconfig.py index 2c7bd0a..2646454 100644 --- a/ipaplatform/redhat/authconfig.py +++ b/ipaplatform/redhat/authconfig.py @@ -22,7 +22,6 @@ from __future__ import absolute_import import logging import six import abc -import re from ipaplatform.paths import paths from ipapython import ipautil @@ -77,7 +76,7 @@ class RedHatAuthSelect(RedHatAuthToolBase): def _get_authselect_current_output(self): try: current = ipautil.run( - [paths.AUTHSELECT, "current"], env={"LC_ALL": "C.UTF8"}) + [paths.AUTHSELECT, "current", "--raw"]) except ipautil.CalledProcessError: logger.debug("Current configuration not managed by authselect") return None @@ -95,19 +94,12 @@ class RedHatAuthSelect(RedHatAuthToolBase): if output_text is None: return None - cfg_params = re.findall( - r"\s*Profile ID:\s*(\S+)\s*\n\s*Enabled features:\s*(.*)", - output_text, - re.DOTALL - ) - - profile = cfg_params[0][0] - - if not profile: + output_text = output_text.strip() + if not output_text: return None - - features = re.findall(r"-\s*(\S+)", cfg_params[0][1], re.DOTALL) - + output_items = output_text.split(' ') + profile = output_items[0] + features = output_items[1:] return profile, features def configure(self, sssd, mkhomedir, statestore):