Fix BigAnimal API v2 compatibility issue for checking the cluster creation permission.

This commit is contained in:
Khushboo Vashi 2022-12-21 18:22:05 +05:30 committed by GitHub
parent 046b56bab1
commit 5d9bcde50d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -250,14 +250,22 @@ class BigAnimalProvider():
"""
_url = "{0}/{1}".format(
self.BASE_URL,
'permissions')
'user-info')
resp = requests.get(_url, headers=self._get_headers())
if resp.status_code != 200:
return False
if resp.status_code == 200 and resp.content:
content = json.loads(resp.content)
if 'data' in content and 'create:clusters' in content[
'data']:
if 'data' in content:
# BigAnimal introduced Project feature in v3,
# so all the existing clusters moved to the default Project.
# For now, we can get the Proj Id by replacing 'org' to 'prj'
# in organization ID: org_1234 -> prj_1234
proj_Id = content['data']['organizationId'].replace('org',
'prj')
for permission in content['data']['scopedPermissions']:
if proj_Id == permission['scope'] and\
'create:clusters' in permission['permissions']:
return True
return False