-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a workaround around non-ascii and non-standard FQDNs (#790)
Add a wrapper around `socket.getfqdn()` which returns `invalid.hostname` in cases where hostname, or rather FQDN contains non-ascii and non-standard characters. This works around the issue that non-ascii characters can't be inserted into leapp database. For the standard for hostnames see `hostname(7)`. The current implementation doesn't check for length of hostname nor it's individual segments.
- Loading branch information
1 parent
649025b
commit 1cbb4b9
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import leapp.utils.workarounds.mp | ||
import leapp.utils.workarounds.fqdn | ||
|
||
|
||
def apply_workarounds(): | ||
leapp.utils.workarounds.mp.apply_workaround() | ||
leapp.utils.workarounds.fqdn.apply_workaround() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import re | ||
import socket | ||
|
||
|
||
def decorate_getfqdn(fn): | ||
def wrap(*args, **kwargs): | ||
result = fn(*args, **kwargs) | ||
# check whether FQDN conforms to standard, see HOSTNAME(7) | ||
pattern = r"^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$" | ||
if re.match(pattern, result, re.IGNORECASE): | ||
return result | ||
return 'invalid.hostname' | ||
|
||
return wrap | ||
|
||
|
||
def apply_workaround(): | ||
setattr(socket, 'getfqdn', decorate_getfqdn(socket.getfqdn)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters