-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #860 from uc-cdis/feat/visa_parse
(PXP-7167) Parse Visas
- Loading branch information
Showing
12 changed files
with
756 additions
and
122 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
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
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,14 @@ | ||
class DefaultVisa(object): | ||
""" | ||
Base class for representation of information in a GA4GH passport describing user, project, and ABAC | ||
information for access control | ||
""" | ||
|
||
def __init__( | ||
self, | ||
logger=None, | ||
): | ||
self.logger = logger | ||
|
||
def _parse_single_visa(self, user, visa): | ||
pass |
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,54 @@ | ||
import jwt | ||
import time | ||
|
||
from fence.sync.passport_sync.base_sync import DefaultVisa | ||
|
||
|
||
class RASVisa(DefaultVisa): | ||
""" | ||
Class representing RAS visas | ||
""" | ||
|
||
def _init__(self, logger): | ||
super(RASVisa, self).__init__( | ||
logger=logger, | ||
) | ||
|
||
def _parse_single_visa( | ||
self, user, encoded_visa, expires, parse_consent_code, db_session | ||
): | ||
decoded_visa = {} | ||
try: | ||
decoded_visa = jwt.decode(encoded_visa, verify=False) | ||
except Exception as e: | ||
self.logger.warning("Couldn't decode visa {}".format(e)) | ||
# Remove visas if its invalid or expired | ||
user.ga4gh_visas_v1 = [] | ||
db_session.commit() | ||
finally: | ||
ras_dbgap_permissions = decoded_visa.get("ras_dbgap_permissions", []) | ||
project = {} | ||
info = {} | ||
info["tags"] = {} | ||
|
||
if time.time() < expires: | ||
for permission in ras_dbgap_permissions: | ||
phsid = permission.get("phs_id", "") | ||
version = permission.get("version", "") | ||
participant_set = permission.get("participant_set", "") | ||
consent_group = permission.get("consent_group", "") | ||
full_phsid = phsid | ||
if parse_consent_code and consent_group: | ||
full_phsid += "." + consent_group | ||
privileges = {"read-storage", "read"} | ||
project[full_phsid] = privileges | ||
info["tags"] = {"dbgap_role": permission.get("role", "")} | ||
else: | ||
# Remove visas if its invalid or expired | ||
user.ga4gh_visas_v1 = [] | ||
db_session.commit() | ||
|
||
info["email"] = user.email or "" | ||
info["display_name"] = user.display_name or "" | ||
info["phone_number"] = user.phone_number or "" | ||
return project, info |
Oops, something went wrong.