mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-01 19:31:10 +00:00
Set line length to 120 characters (#2599)
This commit is contained in:
+11
-37
@@ -34,9 +34,7 @@ from github.Requester import Requester, WithRequester
|
||||
|
||||
# For App authentication, time remaining before token expiration to request a new one
|
||||
ACCESS_TOKEN_REFRESH_THRESHOLD_SECONDS = 20
|
||||
TOKEN_REFRESH_THRESHOLD_TIMEDELTA = timedelta(
|
||||
seconds=ACCESS_TOKEN_REFRESH_THRESHOLD_SECONDS
|
||||
)
|
||||
TOKEN_REFRESH_THRESHOLD_TIMEDELTA = timedelta(seconds=ACCESS_TOKEN_REFRESH_THRESHOLD_SECONDS)
|
||||
|
||||
|
||||
class Auth(abc.ABC):
|
||||
@@ -91,11 +89,7 @@ class Login(Auth):
|
||||
|
||||
@property
|
||||
def token(self) -> str:
|
||||
return (
|
||||
base64.b64encode(f"{self.login}:{self.password}".encode())
|
||||
.decode("utf-8")
|
||||
.replace("\n", "")
|
||||
)
|
||||
return base64.b64encode(f"{self.login}:{self.password}".encode()).decode("utf-8").replace("\n", "")
|
||||
|
||||
|
||||
class Token(Auth):
|
||||
@@ -192,9 +186,7 @@ class AppAuth(JWT):
|
||||
"""
|
||||
if expiration is not None:
|
||||
assert isinstance(expiration, int), expiration
|
||||
assert (
|
||||
Consts.MIN_JWT_EXPIRY <= expiration <= Consts.MAX_JWT_EXPIRY
|
||||
), expiration
|
||||
assert Consts.MIN_JWT_EXPIRY <= expiration <= Consts.MAX_JWT_EXPIRY, expiration
|
||||
|
||||
now = int(time.time())
|
||||
payload = {
|
||||
@@ -202,9 +194,7 @@ class AppAuth(JWT):
|
||||
"exp": now + (expiration if expiration is not None else self._jwt_expiry),
|
||||
"iss": self._app_id,
|
||||
}
|
||||
encrypted = jwt.encode(
|
||||
payload, key=self.private_key, algorithm=self._jwt_algorithm
|
||||
)
|
||||
encrypted = jwt.encode(payload, key=self.private_key, algorithm=self._jwt_algorithm)
|
||||
|
||||
if isinstance(encrypted, bytes):
|
||||
return encrypted.decode("utf-8")
|
||||
@@ -251,9 +241,7 @@ class AppInstallationAuth(Auth, WithRequester["AppInstallationAuth"]):
|
||||
|
||||
assert isinstance(app_auth, AppAuth), app_auth
|
||||
assert isinstance(installation_id, int), installation_id
|
||||
assert token_permissions is None or isinstance(
|
||||
token_permissions, dict
|
||||
), token_permissions
|
||||
assert token_permissions is None or isinstance(token_permissions, dict), token_permissions
|
||||
|
||||
self._app_auth = app_auth
|
||||
self._installation_id = installation_id
|
||||
@@ -303,16 +291,11 @@ class AppInstallationAuth(Auth, WithRequester["AppInstallationAuth"]):
|
||||
@property
|
||||
def _is_expired(self) -> bool:
|
||||
assert self.__installation_authorization is not None
|
||||
token_expires_at = (
|
||||
self.__installation_authorization.expires_at
|
||||
- TOKEN_REFRESH_THRESHOLD_TIMEDELTA
|
||||
)
|
||||
token_expires_at = self.__installation_authorization.expires_at - TOKEN_REFRESH_THRESHOLD_TIMEDELTA
|
||||
return token_expires_at < datetime.now(timezone.utc)
|
||||
|
||||
def _get_installation_authorization(self) -> InstallationAuthorization:
|
||||
assert (
|
||||
self.__integration is not None
|
||||
), "Method withRequester(Requester) must be called first"
|
||||
assert self.__integration is not None, "Method withRequester(Requester) must be called first"
|
||||
return self.__integration.get_access_token(
|
||||
self._installation_id,
|
||||
permissions=self._token_permissions,
|
||||
@@ -413,22 +396,13 @@ class AppUserAuth(Auth, WithRequester["AppUserAuth"]):
|
||||
|
||||
@property
|
||||
def _is_expired(self) -> bool:
|
||||
return self._expires_at is not None and self._expires_at < datetime.now(
|
||||
timezone.utc
|
||||
)
|
||||
return self._expires_at is not None and self._expires_at < datetime.now(timezone.utc)
|
||||
|
||||
def _refresh(self):
|
||||
if self._refresh_token is None:
|
||||
raise RuntimeError(
|
||||
"Cannot refresh expired token because no refresh token has been provided"
|
||||
)
|
||||
if (
|
||||
self._refresh_expires_at is not None
|
||||
and self._refresh_expires_at < datetime.now(timezone.utc)
|
||||
):
|
||||
raise RuntimeError(
|
||||
"Cannot refresh expired token because refresh token also expired"
|
||||
)
|
||||
raise RuntimeError("Cannot refresh expired token because no refresh token has been provided")
|
||||
if self._refresh_expires_at is not None and self._refresh_expires_at < datetime.now(timezone.utc):
|
||||
raise RuntimeError("Cannot refresh expired token because refresh token also expired")
|
||||
|
||||
# refresh token
|
||||
token = self.__app.refresh_access_token(self._refresh_token)
|
||||
|
||||
Reference in New Issue
Block a user