Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions temboardagent/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def hostname(self, hostname=None):
raise Exception("Unsupported OS.")
if not check_fqdn(hostname):
raise ValueError("Invalid FQDN: %s" % (hostname))
if '.' not in hostname:
logger.warning("Hostname %s is not a FQDN.", hostname)
return hostname

def uname(self):
Expand Down
15 changes: 8 additions & 7 deletions temboardagent/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,15 @@ def which(prog, search_path=None):
def check_fqdn(name):
"""
Check if a hostname is fully qualified, it must only contain
letters, - and have dots.
letters, - .
We now allow hostname without dot.
"""
# StackOverflow #11809631
if re.match(r'(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]' # noqa W605
r'{2,63}\.?$)', name):
return True
else:
return False
return re.match(
r"(?=^.{4,253}$)" # check length between 4 and 253
r"(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-))"
r"(\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*$)",
name,
)


def now():
Expand Down