Skip to content

Commit

Permalink
Merge pull request #1005 from uc-cdis/feat/passport-improve-sync-perf…
Browse files Browse the repository at this point in the history
…ormance

(PXP-9480): Improve sync_single_user_visas performance
  • Loading branch information
johnfrancismccann committed Feb 15, 2022
2 parents 0d55ee8 + da70723 commit fe59398
Show file tree
Hide file tree
Showing 12 changed files with 344 additions and 201 deletions.
2 changes: 1 addition & 1 deletion fence/blueprints/data/indexd.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_signed_url_for_file(
if ga4gh_passports:
# users_from_passports = {"username": Fence.User}
users_from_passports = sync_gen3_users_authz_from_ga4gh_passports(
ga4gh_passports, authz_policy_prefix="GA4GH.DRS", db_session=db_session
ga4gh_passports, db_session=db_session
)

# add the user details to `flask.g.audit_data` first, so they are
Expand Down
1 change: 0 additions & 1 deletion fence/blueprints/login/ras.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def post_login(self, user=None, token_result=None, id_from_idp=None):
# now sync authz updates
users_from_passports = fence.resources.ga4gh.passports.sync_gen3_users_authz_from_ga4gh_passports(
[passport],
authz_policy_prefix="POST.LOGIN",
pkey_cache=PKEY_CACHE,
db_session=current_session,
)
Expand Down
1 change: 0 additions & 1 deletion fence/job/visa_update_cronjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ async def updater(self, name, updater_queue, db_session):
client.update_user_authorization(
user,
pkey_cache=self.pkey_cache,
authz_policy_prefix="TOKEN.POLLING",
db_session=db_session,
)
else:
Expand Down
7 changes: 2 additions & 5 deletions fence/resources/ga4gh/passports.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

def sync_gen3_users_authz_from_ga4gh_passports(
passports,
authz_policy_prefix,
pkey_cache=None,
db_session=None,
):
Expand Down Expand Up @@ -151,7 +150,6 @@ def sync_gen3_users_authz_from_ga4gh_passports(
gen3_user=gen3_user,
ga4gh_visas=ga4gh_visas,
expiration=min_visa_expiration,
policy_prefix=authz_policy_prefix,
db_session=db_session,
)
users_from_current_passport.append(gen3_user)
Expand Down Expand Up @@ -368,7 +366,7 @@ def get_or_create_gen3_user_from_iss_sub(issuer, subject_id, db_session=None):


def _sync_validated_visa_authorization(
gen3_user, ga4gh_visas, expiration, policy_prefix, db_session=None
gen3_user, ga4gh_visas, expiration, db_session=None
):
"""
Wrapper around UserSyncer.sync_single_user_visas method, which parses
Expand All @@ -391,7 +389,7 @@ def _sync_validated_visa_authorization(
"""
db_session = db_session or current_session
default_args = fence.scripting.fence_create.get_default_init_syncer_inputs(
authz_provider=policy_prefix
authz_provider="GA4GH"
)
syncer = fence.scripting.fence_create.init_syncer(**default_args)

Expand All @@ -400,7 +398,6 @@ def _sync_validated_visa_authorization(
ga4gh_visas,
db_session,
expires=expiration,
policy_prefix=policy_prefix,
)

# after syncing authorization, persist the visas that were parsed successfully.
Expand Down
5 changes: 1 addition & 4 deletions fence/resources/openid/ras_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ def map_iss_sub_pair_to_user(
return iss_sub_pair_to_user.user.username

@backoff.on_exception(backoff.expo, Exception, **DEFAULT_BACKOFF_SETTINGS)
def update_user_authorization(
self, user, pkey_cache, authz_policy_prefix, db_session=current_session
):
def update_user_authorization(self, user, pkey_cache, db_session=current_session):
"""
Updates user's RAS refresh token and uses the new access token to retrieve new visas from
RAS's /userinfo endpoint and update access
Expand All @@ -310,7 +308,6 @@ def update_user_authorization(
users_from_passports = (
fence.resources.ga4gh.passports.sync_gen3_users_authz_from_ga4gh_passports(
[passport],
authz_policy_prefix=authz_policy_prefix,
pkey_cache=pkey_cache,
db_session=db_session,
)
Expand Down
Loading

0 comments on commit fe59398

Please sign in to comment.