Skip to content

Commit

Permalink
Merge pull request #906 from isb-cgc/isb-cgc-prod-sp
Browse files Browse the repository at this point in the history
Sprint 36: API v4
  • Loading branch information
s-paquette committed Aug 23, 2019
2 parents a0bdc01 + 9b753f6 commit f41b092
Show file tree
Hide file tree
Showing 6 changed files with 489 additions and 459 deletions.
4 changes: 2 additions & 2 deletions accounts/sa_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def register_service_account(user_email, user_id, gcp_id, user_sa, datasets, is_
except (TokenFailure, InternalTokenError, RefreshTokenExpired, DCFCommFailure) as e:
raise e
except Exception as e:
logger.error("[ERROR] Exception while registering ServiceAccount")
logger.error("[ERROR] Exception while registering ServiceAccount {} for project {}:".format(user_sa,gcp_id))
logger.exception(e)
raise e

Expand Down Expand Up @@ -624,7 +624,7 @@ def _register_service_account_dcf(user_email, user_id, gcp_id, user_sa, datasets
#

except (TokenFailure, InternalTokenError, RefreshTokenExpired, DCFCommFailure) as e:
logger.error("[ERROR] Exception while registering ServiceAccount")
logger.error("[ERROR] Exception while registering ServiceAccount {} for project {}:".format(user_sa,gcp_id))
logger.exception(e)
raise e

Expand Down
23 changes: 18 additions & 5 deletions accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,21 +299,34 @@ def unreg_gcp(user, gcp_id):


def get_user_gcps(user, gcp_id=None):
gcps = []
gcp_list = None
gcps = None

try:
if gcp_id:
gcp_list = GoogleProject.objects.filter(user=user, active=1)
else:
gcp_list = GoogleProject.objects.filter(user=user, active=1, project_id=gcp_id)
else:
gcp_list = GoogleProject.objects.filter(user=user, active=1)

gcps = []
for gcp in gcp_list:
gcps.append({'gcp_id': gcp.project_id, 'gcp_name': gcp.project_name, 'users': [x.email for x in gcp.users_set.all()]})
gcps.append({'gcp_id': gcp.project_id, 'gcp_name': gcp.project_name, 'users': [x.email for x in gcp.user.all()]})

except Exception as e:
logger.error("[ERROR] While fetching the GCP project list for user {}:")
logger.exception(e)

return gcps

def api_gcp_delete(user, gcp_id):
response = {}
status = 200

try:
gcp = GoogleProject.objects.get(project_id=gcp_id, active=1)
response, status = unreg_gcp(user, gcp.id)
except ObjectDoesNotExist:
response['message'] = "An active Google Cloud Platform project with ID {} was not found.".format(gcp_id)
status = 404

return response, status

Loading

0 comments on commit f41b092

Please sign in to comment.