Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse hostname from /proc/sys/kernel/hostname #704

Merged
merged 3 commits into from
Dec 6, 2024
Merged

Conversation

CinisSec
Copy link
Contributor

Adds the /proc/sys/kernel/hostname path to the paths mentioned in issue 606

@CinisSec CinisSec marked this pull request as ready for review May 13, 2024 19:49
@Miauwkeru Miauwkeru linked an issue May 14, 2024 that may be closed by this pull request
@Miauwkeru
Copy link
Contributor

Could you change the title of the PR and your commit message according to our commit style guidelines?

https://docs.dissect.tools/en/latest/contributing/style-guide.html#commit-message-style-and-formatting

@@ -149,7 +149,7 @@ def _parse_hostname_string(self, paths: Optional[list[str]] = None) -> Optional[
paths (list): list of paths
"""
redhat_legacy_path = "/etc/sysconfig/network"
paths = paths or ["/etc/hostname", "/etc/HOSTNAME", redhat_legacy_path]
paths = paths or ["/etc/hostname", "/etc/HOSTNAME", "/proc/sys/kernel/hostname", redhat_legacy_path]
Copy link
Contributor

@Paradoxis Paradoxis May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always want to add the file, or only when a user doesn't specify their own paths? If we always want to include the file you're better off cloning the paths, and merging these four hostname paths together:

If the list order doesn't matter you can combine the two and cast it to a set to make the values unique:

paths = set(paths + ["/etc/hostname", "/etc/HOSTNAME", "/proc/sys/kernel/hostname", redhat_legacy_path])

If the list order does matter, just create a copy and add each unique item to it:

paths = paths.copy()  # ensures that we don't modify the existing list in-place
for path in ["/etc/hostname", "/etc/HOSTNAME", "/proc/sys/kernel/hostname", redhat_legacy_path]:
    if path not in paths:
        paths.append(path)

@Horofic Horofic changed the title adding "/proc/sys/kernel/hostname" to paths in _parse_hostname_string Parse hostname from /proc/sys/kernel/hostname Oct 30, 2024
@Horofic Horofic self-requested a review December 6, 2024 12:15
Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.70%. Comparing base (79aa5dd) to head (6e5428a).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #704   +/-   ##
=======================================
  Coverage   77.70%   77.70%           
=======================================
  Files         326      326           
  Lines       28481    28481           
=======================================
  Hits        22131    22131           
  Misses       6350     6350           
Flag Coverage Δ
unittests 77.70% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Horofic Horofic merged commit 63e52e1 into fox-it:main Dec 6, 2024
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parse hostname from /proc/sys/kernel/hostname for Unix
4 participants