Skip to content

Commit

Permalink
Improved error handling in github.py and added user to Dockerfile
Browse files Browse the repository at this point in the history
The error handling code in github.py has been updated to use a safer dictionary access method. The Dockerfile has also been refactored to create a new user and set its permissions, limiting potential security risks.
  • Loading branch information
dvershinin committed Mar 17, 2024
1 parent 4d3f8bf commit 1fa7b7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Use a lightweight base image with Python and pip installed
FROM python:3.9-alpine

RUN addgroup -S lastversion \
&& adduser -S lastversion -G lastversion

# Set the working directory to /app
WORKDIR /app

Expand All @@ -11,5 +14,7 @@ COPY setup.py README.md ./
# Install the application and its dependencies
RUN pip install -e .

USER lastversion

# Set the entrypoint to the command that runs your application
ENTRYPOINT ["lastversion"]
4 changes: 2 additions & 2 deletions src/lastversion/repo_holders/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def find_in_tags_via_graphql(self, ret, pre_ok, major):
log.info("query returned non 200 response code %s", r.status_code)
return ret
j = r.json()
if "errors" in j and j["errors"][0]["type"] == "NOT_FOUND":
if "errors" in j and j["errors"][0].get("type") == "NOT_FOUND":
raise BadProjectError(f"No such project found on GitHub: {self.repo}")
if not j["data"]["repository"]["tags"]["edges"]:
log.info("No tags in GraphQL response: %s", r.text)
Expand Down Expand Up @@ -478,7 +478,7 @@ def get_releases_feed_contents(self, rename_checked=False):
# authorization header may cause a false positive 200 response with an empty feed!
"Authorization": "",
}
r = self.get(
r = super().get(
f"https://{self.hostname}/{self.repo}/releases.atom", headers=headers
)
# API requests are varied by cookie, we don't want serializer for cache fail because of that
Expand Down

0 comments on commit 1fa7b7d

Please sign in to comment.