Skip to content

Commit

Permalink
Use group name directly instead of querying id first
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiefMaster committed Dec 3, 2024
1 parent ff71120 commit cd4f8fe
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 32 deletions.
21 changes: 1 addition & 20 deletions flask_multipass_cern.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,6 @@ def get_members(self):
raise

with api_session:
group_data = self.provider._get_group_data(name)
if group_data is None:
return
gid = group_data['id']

params = {
'limit': 5000,
'field': [
Expand All @@ -183,7 +178,7 @@ def get_members(self):
],
}
try:
results = self.provider._fetch_all(api_session, f'/api/v1.0/Group/{gid}/memberidentities/precomputed',
results = self.provider._fetch_all(api_session, f'/api/v1.0/Group/{name}/memberidentities/precomputed',
params)[0]
except RequestException:
self.provider.logger.warning('Refreshing members failed for group %s', name)
Expand Down Expand Up @@ -552,20 +547,6 @@ def _fetch_all(self, api_session, endpoint, params, limit=None):
results = results[:limit]
return results, total

@memoize_request
def _get_group_data(self, name):
params = {
'filter': [f'groupIdentifier:eq:{name}'],
'field': ['id', 'groupIdentifier'],
}
with self._get_api_session() as api_session:
resp = api_session.get(f'{self.authz_api_base}/api/v1.0/Group', params=params)
resp.raise_for_status()
data = resp.json()
if len(data['data']) != 1:
return None
return data['data'][0]

def _get_identity_data(self, identifier):
params = {
'field': [
Expand Down
12 changes: 0 additions & 12 deletions tests/test_request_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ def test_get_identity_data_retry(provider):
assert len(httpretty.latest_requests()) == HTTP_RETRY_COUNT + 1


@pytest.mark.usefixtures('httpretty_enabled', 'mock_get_api_session')
def test_get_group_data_retry(provider):
authz_api = provider.settings.get('authz_api')
test_uri = f'{authz_api}/api/v1.0/Group'
httpretty.register_uri(httpretty.GET, test_uri, status=503)

try:
provider._get_group_data('mygroup')
except requests.exceptions.RequestException:
assert len(httpretty.latest_requests()) == HTTP_RETRY_COUNT + 1


@pytest.mark.usefixtures('httpretty_enabled', 'mock_get_api_session')
def test_fetch_all_retry(provider):
authz_api_base = provider.settings.get('authz_api')
Expand Down

0 comments on commit cd4f8fe

Please sign in to comment.