diff options
author | nico <nico@magicbroccoli.de> | 2020-11-24 23:37:00 +0100 |
---|---|---|
committer | nico <nico@magicbroccoli.de> | 2020-11-24 23:37:00 +0100 |
commit | ac0ea074d5684ac4f22b7787ce3b95f77f25e3e6 (patch) | |
tree | ee6969d1e59bc56c4d6d40792f461c7eefdd41bf /calls.py | |
parent | c19557a320c0e9cf882abef185f30c8d97fd7c5e (diff) |
fix: nodename quotation issue
* update nodename method to not use regex anymore
* update readme with 2 new columns for the exit code table
We used quite the broad regex to parse the nodename from the status
string. But we relied on a single quote to mark the starting point.
It seems some distributions don't have this starting quote,
therefore breaking the api.
Diffstat (limited to 'calls.py')
-rw-r--r-- | calls.py | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -14,16 +14,26 @@ class EjabberdApiCalls(EjabberdApi): @property def nodename(self): if self._login is not None: - node_str = re.compile("The node '(.*)'") status = self.cmd("status", {}) + # "The node ejabberd@localhost is started with status: startedejabberd 20.07 is running in that node" - # matches try: - tmp = node_str.findall(status)[0] - # raise SystemExit code 17 if no status message is received - except TypeError: + tmp = status.split()[2] + + except AttributeError: + # emtpy response or None obj raise SystemExit(17) + except IndexError: + # status string differs from what we expect + log.warning("status string is different then expected") + tmp = "ejabberd@status-string-split-error" + pass + + # strip double quotations + if tmp.startswith("'"): + tmp = tmp.strip("'") + log.debug(f"fetched node string: {tmp}") return tmp |