Fix GitHub InstallationToken renewal.

Signed-off-by: magic_rb <richard@brezak.sk>
This commit is contained in:
magic_rb 2024-06-12 18:26:40 +02:00 committed by Jörg Thalheim
parent c92a655055
commit 16d4308d29

View file

@ -41,7 +41,9 @@ class InstallationToken(RepoToken):
token = InstallationToken._create_installation_access_token( token = InstallationToken._create_installation_access_token(
jwt_token, installation_id jwt_token, installation_id
).json()["token"] ).json()["token"]
expiration = datetime.now(tz=UTC) + InstallationToken.GITHUB_TOKEN_LIFETIME expiration = (
datetime.now(tz=UTC) + InstallationToken.GITHUB_TOKEN_LIFETIME * 0.8
)
return token, expiration return token, expiration
@ -72,7 +74,7 @@ class InstallationToken(RepoToken):
return f"%(secret:github-token-{self.installation_id})" return f"%(secret:github-token-{self.installation_id})"
def verify(self) -> None: def verify(self) -> None:
if datetime.now(tz=UTC) - self.expiration > self.GITHUB_TOKEN_LIFETIME * 0.8: if datetime.now(tz=UTC) > self.expiration:
self.token, self.expiration = InstallationToken._generate_token( self.token, self.expiration = InstallationToken._generate_token(
self.jwt_token, self.installation_id self.jwt_token, self.installation_id
) )