-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add on_token_refresh in owner.py
* Updates shared to a newer version * Adds a on_token_refresh callback if the torngit adapter comes from owner.py context codecov/engineering-team#162
- Loading branch information
1 parent
93ea61a
commit 2fc4026
Showing
5 changed files
with
45 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import logging | ||
from typing import Callable, Dict | ||
|
||
from shared.encryption.token import encode_token | ||
|
||
from database.models.core import Owner | ||
from services.encryption import encryptor | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def get_token_refresh_callback(owner: Owner) -> Callable[[Dict], None]: | ||
""" | ||
Produces a callback function that will encode and update the oauth token of a user. | ||
This callback is passed to the TorngitAdapter for the service. | ||
""" | ||
# Some tokens don't have to be refreshed (GH integration, default bots) | ||
# They don't belong to any owners. | ||
if owner is None: | ||
return None | ||
|
||
service = owner.service | ||
if service == "bitbucket" or service == "bitbucket_server": | ||
return None | ||
|
||
async def callback(new_token: Dict) -> None: | ||
log.info( | ||
"Saving new token after refresh", | ||
extra=dict(owner=owner.username, ownerid=owner.ownerid), | ||
) | ||
string_to_save = encode_token(new_token) | ||
oauth_token = encryptor.encode(string_to_save).decode() | ||
owner.oauth_token = oauth_token | ||
|
||
return callback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
git+ssh://[email protected]/codecov/shared.git@680951c4849074db131353b251581ee03029a72a#egg=shared | ||
git+ssh://[email protected]/codecov/shared.git@bbdf61a36ed253c8237f3aeec76b9bcf09cdd6a8#egg=shared | ||
git+ssh://[email protected]/codecov/[email protected]#egg=codecovopentelem | ||
boto3 | ||
celery | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,7 +251,7 @@ s3transfer==0.3.4 | |
# via boto3 | ||
sentry-sdk==1.19.1 | ||
# via -r requirements.in | ||
shared @ git+ssh://[email protected]/codecov/shared.git@680951c4849074db131353b251581ee03029a72a | ||
shared @ git+ssh://[email protected]/codecov/shared.git@bbdf61a36ed253c8237f3aeec76b9bcf09cdd6a8 | ||
# via -r requirements.in | ||
six==1.15.0 | ||
# via | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters