Skip to content

Commit

Permalink
AUTH: Fix RPC calls and object format
Browse files Browse the repository at this point in the history
  • Loading branch information
icot committed Jul 17, 2018
1 parent 0fe2a51 commit 2745b44
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions apiato/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ def get(self, *args):
user_egroups = set(body.get("groups"))
except KeyError, ValueError:
raise tornado.web.HTTPError(BAD_REQUEST)

resources = {}

# Computing group intersection
logging.debug('User egroups %s' % user_egroups)

# Verifying Admin role
if config.get('auth', 'admin_group') in list(user_egroups):
resources["admin"] = True
else:
resources["admin"] = False

logging.debug("Requesting system egroups" + composed_url)
response = requests.get(composed_url)
Expand All @@ -72,48 +74,50 @@ def get(self, *args):
else:
logging.error("Error fetching list of system recognized egroups: " + response.text)
raise tornado.web.HTTPError(response.status_code)

intersect = user_egroups.intersection(system_egroups)
if bool(intersect):
resources["groups"] = list(intersect)

# Fetching list of owned instances
logging.debug('Username: %s' % (username) )
logging.debug("Requesting user owned instances: " + config.get('postgrest', 'user_instances_url'))
rbody = {'owner': username , 'groups': resources.get('groups')}

rbody = {'owner': username,
'groups': resources.get('groups'),
'admin': resources.get('admin')}

response = requests.post(config.get('postgrest','user_instances_url'),
json=rbody,
headers={'Prefer': 'return=representation'}
)
json=rbody,
headers={'Prefer': 'return=representation'}
)
if response.ok:
data = response.json()
logging.debug("User instances response: " + json.dumps(data))
resources["instances"] = data[0].get("get_user_instances")
else:
logging.debug(response)
logging.info("No instances directly owned by user")

resources["instances"] = None

# Fetching list of owned clusters
logging.debug('Username: %s' % (username) )
logging.debug("Requesting user owned clusters: " + config.get('postgrest', 'user_clusters_url'))
rbody = {'owner': username , 'groups': resources.get('groups')}
response = requests.post(config.get('postgrest','user_clusters_url'),
json=rbody,
headers={'Prefer': 'return=representation'}
)
response = requests.post(config.get('postgrest', 'user_clusters_url'),
json=rbody,
headers={'Prefer': 'return=representation'}
)
if response.ok:
data = response.json()
logging.debug("User clusters response: " + json.dumps(data))
resources["clusters"] = data[0].get("get_user_clusters")
else:
logging.debug(response)
logging.info("No instances directly owned by user")
resources["clusters"] = None

if bool(resources):
self.write(json.dumps(resources))
self.set_status(OK)
else:
raise tornado.web.HTTPError(NOT_FOUND)



0 comments on commit 2745b44

Please sign in to comment.