-
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.
feat: support gh refresh tokens (#69)
Depends on codecov/shared#27 Adds support for github app refresh tokens context: codecov/engineering-team#162
- Loading branch information
1 parent
eef11ba
commit a4b846e
Showing
7 changed files
with
81 additions
and
39 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
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@6a8a33248804a9c101d34f417efda7c11e4bbe63#egg=shared | ||
git+ssh://[email protected]/codecov/shared.git@f0174635ccaebc3463a5641b9ad640a46b5fd472#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@4f65b0040ab6bb3dba2190ce544ade9a0ea3e354 | ||
shared @ git+ssh://[email protected]/codecov/shared.git@f0174635ccaebc3463a5641b9ad640a46b5fd472 | ||
# 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
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