Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsmkn committed Jan 10, 2024
1 parent 7d46457 commit ca1ffcc
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions sagemaker_shim/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ class UserInfo(NamedTuple):
uid: int | None
gid: int | None
home: str | None
extra_groups: list[int]
groups: list[int]


def _get_user_info(id_or_name: str) -> UserInfo:
if id_or_name == "":
return UserInfo(uid=None, gid=None, home=None, extra_groups=[])
return UserInfo(uid=None, gid=None, home=None, groups=[])

try:
user = pwd.getpwnam(id_or_name)
Expand All @@ -176,13 +176,13 @@ def _get_user_info(id_or_name: str) -> UserInfo:
try:
user = pwd.getpwuid(uid)
except (KeyError, AttributeError):
return UserInfo(uid=uid, gid=None, home=None, extra_groups=[])
return UserInfo(uid=uid, gid=None, home=None, groups=[])

return UserInfo(
uid=user.pw_uid,
gid=user.pw_gid,
home=user.pw_dir,
extra_groups=_get_users_groups(user=user),
groups=_get_users_groups(user=user),
)


Expand Down Expand Up @@ -296,7 +296,7 @@ def extra_groups(self) -> list[int] | None:
).lower()
== "true"
):
return self.proc_user.extra_groups
return self.proc_user.groups
else:
return None

Expand Down Expand Up @@ -357,7 +357,7 @@ def proc_env(self) -> dict[str, str]:
@cached_property
def proc_user(self) -> UserInfo:
if self.user == "":
return UserInfo(uid=None, gid=None, home=None, extra_groups=[])
return UserInfo(uid=None, gid=None, home=None, groups=[])

match = re.fullmatch(
r"^(?P<user>[0-9a-zA-Z]*):?(?P<group>[0-9a-zA-Z]*)$", self.user
Expand All @@ -371,7 +371,7 @@ def proc_user(self) -> UserInfo:
uid=info.uid,
gid=info.gid if gid is None else gid,
home=info.home,
extra_groups=info.extra_groups,
groups=info.groups,
)
else:
raise RuntimeError(f"Invalid user '{self.user}'")
Expand Down

0 comments on commit ca1ffcc

Please sign in to comment.