From e5aae9ae1fb642c3ba40a67d017b14a537cd68de Mon Sep 17 00:00:00 2001 From: Robert Lin Date: Fri, 25 Sep 2020 09:21:24 +0800 Subject: [PATCH] interface: add more logging for drive permissions --- interface/gcp.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/interface/gcp.py b/interface/gcp.py index 5329100b..48c9c3e3 100644 --- a/interface/gcp.py +++ b/interface/gcp.py @@ -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. @@ -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 @@ -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):