Skip to content

Commit

Permalink
interface: add more logging for drive permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed Sep 25, 2020
1 parent 154031c commit eeb42dd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions interface/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def set_drive_permissions(self, scope, drive_id, emails: List[str]):
In all cases of API errors, we log and continue, to try and get close
to the desired state of permissions.
"""
logging.info(f"Preparing to update permissions for {drive_id} "
+ f"({scope}) for {len(emails)} emails")

# List existing permissions - we use this to avoid duplicate
# permissions, and to delete ones that should not longer exist.
Expand All @@ -41,9 +43,11 @@ def set_drive_permissions(self, scope, drive_id, emails: List[str]):
except Exception as e:
logging.error("Failed to load permissions for drive item"
+ f"({scope}, {drive_id}): {e}")
logging.info(f"Found {len(existing)} permissions for {scope}")

# Ensure the folder is shared with everyone as required.
# See http://googleapis.github.io/google-api-python-client/docs/dyn/drive_v3.permissions.html#create # noqa
created_shares = 0
for email in emails:
if email in existing:
continue
Expand All @@ -56,19 +60,24 @@ def set_drive_permissions(self, scope, drive_id, emails: List[str]):
emailMessage=default_share_msg,
sendNotificationEmail=True,
supportsAllDrives=True)
created_shares += 1
except Exception as e:
logging.error("Failed to share drive item"
+ f"({scope}, {drive_id}) with {email}: {e}")
logging.info(f"Created {created_shares} permissions for {scope}")

# Delete old permissions
# See http://googleapis.github.io/google-api-python-client/docs/dyn/drive_v3.permissions.html#delete # noqa
deleted_shares = 0
for p in to_delete:
try:
self.drive.permissions().delete(p,
supportsAllDrives=True)
deleted_shares += 1
except Exception as e:
logging.error(f"Failed to delete permission {p} for drive item"
+ f" ({scope}, {drive_id}): {e}")
logging.info(f"Deleted {deleted_shares} permissions for {scope}")


def new_create_permission_body(scope, email):
Expand Down

0 comments on commit eeb42dd

Please sign in to comment.