Skip to content

Commit

Permalink
PXD-2062 400 Error during SA deletion (#41)
Browse files Browse the repository at this point in the history
* * check for 400 error, see if SA was actually deleted, raise error otherwise

* using list comprehension like a cool kid

* cdislogging -> logging

* added logging

* trying to add cdislogging dependency

* including requirement

* removing from setup

* cirrus dependency links

* install_requires cdislogging

* dummy commit
  • Loading branch information
benJrohrer authored and zflamig committed Nov 7, 2018
1 parent 9dd57b0 commit 64d592f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 29 additions & 1 deletion cirrus/google_cloud/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
from cirrus.google_cloud.services import GoogleAdminService
from cirrus.google_cloud.utils import get_valid_service_account_id_for_user

from cdislogging import get_logger

logger = get_logger(__name__)

GOOGLE_IAM_API_URL = "https://iam.googleapis.com/v1/"
GOOGLE_CLOUD_RESOURCE_URL = "https://cloudresourcemanager.googleapis.com/v1/"
Expand Down Expand Up @@ -1058,7 +1061,7 @@ def add_member_to_group(self, member_email, group_id):
Add given member email to given group
Args:
member_email (str): email for member to add
member_email (str): email for member to add to group
group_id (str): Group email or unique ID
Returns:
Expand Down Expand Up @@ -1124,6 +1127,31 @@ def remove_member_from_group(self, member_email, group_id):
if err.resp.status == 404:
# not found, member isn't in group. This is fine
response = {}
elif err.resp.status == 400:
# Google's API erroneously returns 400 sometimes
# we check to see if the SA was actually deleted
logger.warning(
"When removing {} from group ({}), Google API "
"returned status 400".format(member_email, group_id)
)
member_emails = [
member.get("email", "")
for member in self.get_group_members(group_id)
]
if member_email in member_emails:
logger.warning(
"{} was not removed from group ({})".format(
member_email, group_id
)
)
raise
else:
# reaching this point, indicates the member was successfully removed
logger.info(
"Group ({}) members were checked and {} was "
"successfully removed".format(group_id, member_email)
)
response = {}
else:
raise

Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"google-api-python-client>=1.6.7",
"google-auth>=1.4.1",
"google-auth-httplib2>=0.0.3",
"cdislogging",
],
include_package_data=True,
packages=["cirrus", "cirrus.google_cloud"],
dependency_links=['http://github.com/uc-cdis/cdislogging/tarball/master#egg=cdislogging'],
)

0 comments on commit 64d592f

Please sign in to comment.