From 881641e2b4e68c51e174118ec66c55192bd040c7 Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Thu, 7 Apr 2022 19:53:11 +0000 Subject: [PATCH] gapi_drive --- src/gam/gapi/drive/__init__.py | 8 ++++++++ src/gam/gapi/drive/drives.py | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/gam/gapi/drive/__init__.py create mode 100644 src/gam/gapi/drive/drives.py diff --git a/src/gam/gapi/drive/__init__.py b/src/gam/gapi/drive/__init__.py new file mode 100644 index 00000000..eacbaa87 --- /dev/null +++ b/src/gam/gapi/drive/__init__.py @@ -0,0 +1,8 @@ +import gam + + +def build(user=None): + if not user: + user = gam._get_admin_email() + userEmail = gam.convertUIDtoEmailAddress(user) + return (userEmail, gam.buildGAPIServiceObject('drive3', userEmail)) diff --git a/src/gam/gapi/drive/drives.py b/src/gam/gapi/drive/drives.py new file mode 100644 index 00000000..7260f3f3 --- /dev/null +++ b/src/gam/gapi/drive/drives.py @@ -0,0 +1,26 @@ +"""Methods related to Drive API Shared Drives""" +import sys + + +import gam +from gam.var import GC_CUSTOMER_ID, GC_Values, MY_CUSTOMER, SORTORDER_CHOICES_MAP +from gam import controlflow +from gam import display +from gam import gapi +from gam.gapi import errors as gapi_errors +from gam.gapi import drive as gapi_drive + +def drive_name_to_id(name, drive=None): + if not drive: + _, drive = gapi_drive.build() + q = f"name = '{name}'" + sds = gapi.get_all_pages(drive.drives(), + 'list', + 'drives', + q=q, + useDomainAdminAccess=True) + if len(sds) == 0: + controlflow.system_error_exit(f'Could not find shared drive named "{name}"') + elif len(sds) > 1: + controlflow.system_error_exit(f'Got more than one shared drive named "{name}"') + return sds[0]['id']