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

Bug: app auth cache keys missing app_id #95

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Changes from 1 commit
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
12 changes: 7 additions & 5 deletions githubkit/auth/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
permissions: Union[Unset, "AppPermissionsType"] = UNSET
cache: "BaseCache" = DEFAULT_CACHE

JWT_CACHE_KEY = "githubkit:auth:app:jwt"
JWT_CACHE_KEY = "githubkit:auth:app:jwt:{app_id}"
yanyongyu marked this conversation as resolved.
Show resolved Hide resolved
INSTALLATION_CACHE_KEY = (
"githubkit:auth:app:installation:"
"{installation_id}:{permissions}:{repositories}:{repository_ids}"
Expand Down Expand Up @@ -74,15 +74,17 @@
)

def get_jwt(self) -> str:
if not (token := self.cache.get(self.JWT_CACHE_KEY)):
cache_key = self.JWT_CACHE_KEY.format("app_id", self.app_id)
yanyongyu marked this conversation as resolved.
Show resolved Hide resolved
if not (token := self.cache.get(cache_key)):

Check warning on line 78 in githubkit/auth/app.py

View check run for this annotation

Codecov / codecov/patch

githubkit/auth/app.py#L77-L78

Added lines #L77 - L78 were not covered by tests
token = self._create_jwt()
self.cache.set(self.JWT_CACHE_KEY, token, timedelta(minutes=8))
self.cache.set(cache_key, token, timedelta(minutes=8))

Check warning on line 80 in githubkit/auth/app.py

View check run for this annotation

Codecov / codecov/patch

githubkit/auth/app.py#L80

Added line #L80 was not covered by tests
return token

async def aget_jwt(self) -> str:
if not (token := await self.cache.aget(self.JWT_CACHE_KEY)):
cache_key = self.JWT_CACHE_KEY.format("app_id", self.app_id)
yanyongyu marked this conversation as resolved.
Show resolved Hide resolved
if not (token := await self.cache.aget(cache_key)):

Check warning on line 85 in githubkit/auth/app.py

View check run for this annotation

Codecov / codecov/patch

githubkit/auth/app.py#L84-L85

Added lines #L84 - L85 were not covered by tests
token = self._create_jwt()
await self.cache.aset(self.JWT_CACHE_KEY, token, timedelta(minutes=8))
await self.cache.aset(cache_key, token, timedelta(minutes=8))

Check warning on line 87 in githubkit/auth/app.py

View check run for this annotation

Codecov / codecov/patch

githubkit/auth/app.py#L87

Added line #L87 was not covered by tests
return token

def _build_installation_auth_request(self) -> httpx.Request:
Expand Down
Loading