Skip to content

Commit

Permalink
[SP-748] Fix get_team method in sdccli python lib (#239)
Browse files Browse the repository at this point in the history
* Use team endpoint to fetch team by name instead of in memory filtering

* Remove conditional memberships

* Fix linter
  • Loading branch information
luzeno authored May 5, 2023
1 parent 1995e4b commit a213f9a
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions sdcclient/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,28 @@ def get_teams(self, team_filter='', product_filter=''):
return [False, self.lasterr]
ret = [t for t in res.json()['teams'] if team_filter in t['name']]
if product_filter:
ret = [t for t in ret if product_filter in t['products']]
ret = [t for t in ret if product_filter in t['products']]
return [True, ret]

def get_team_by_id(self, id):
'''**Description**
Return the team with the specified team ID, if it is present.
**Arguments**
- **id**: the ID of the team to return
**Success Return Value**
The requested team.
**Example**
`examples/user_team_mgmt.py <https://github.com/draios/python-sdc-client/blob/master/examples/user_team_mgmt.py>`_
'''
res = self.http.get(self.url + '/api/teams/' + str(id), headers=self.hdrs, verify=self.ssl_verify)
if not self._checkResponse(res):
return [False, self.lasterr]

return [True, res.json()['team']]

def get_team(self, name):
'''**Description**
Return the team with the specified team name, if it is present.
Expand All @@ -731,13 +750,18 @@ def get_team(self, name):
**Example**
`examples/user_team_mgmt.py <https://github.com/draios/python-sdc-client/blob/master/examples/user_team_mgmt.py>`_
'''
ok, res = self.get_teams(name)
res = self.http.get(self.url + '/api/v2/teams/light/name/' + str(name), headers=self.hdrs, verify=self.ssl_verify)
if not self._checkResponse(res):
return [False, self.lasterr]

light_team = res.json()['team']

ok, team_with_memberships = self.get_team_by_id(light_team['id'])

if not ok:
return ok, res
for team in res:
if team['name'] == name:
return [True, team]
return [False, 'Could not find team']
return [False, self.lasterr]

return [True, team_with_memberships]

def get_team_ids(self, teams):
res = self.http.get(self.url + '/api/teams', headers=self.hdrs, verify=self.ssl_verify)
Expand Down

0 comments on commit a213f9a

Please sign in to comment.