-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathGetTypeWithLinkDriveACLs.py
More file actions
executable file
·51 lines (44 loc) · 2.19 KB
/
GetTypeWithLinkDriveACLs.py
File metadata and controls
executable file
·51 lines (44 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
"""
# Purpose: For a Google Drive User(s), show all drive file ACls for files shared with the desired type and withLink values
# Note: This script can use basic GAM: https://github.com/jay0lee/GAM or advanced GAM: https://github.com/taers232c/GAMADV-X
# Usage:
# 1: Get ACLS for all files, if you don't want all users, replace all users with your user selection in the command below
# $ Basic: gam all users print filelist id title permissions > filelistperms.csv
# $ Advanced: gam config auto_batch_min 1 redirect csv ./filelistperms.csv multiprocess all users print filelist id title permissions
# 2: From that list of ACLs, output a CSV file with headers "Owner,driveFileId,driveFileTitle,permissionId,role"
# that lists the driveFileIds and permissionIds for all ACls with the desired type and withLink values
# $ python GetTypeWithLinkDriveACLs.py filelistperms.csv typewwithlink.csv
"""
import csv
import re
import sys
desiredType = 'anyone' # anyone or domain
desiredWithLink = 'True' # 'True' or 'False'
id_n_type = re.compile(r"permissions.(\d+).type")
if (len(sys.argv) > 2) and (sys.argv[2] != '-'):
outputFile = open(sys.argv[2], 'wb')
else:
outputFile = sys.stdout
outputCSV = csv.DictWriter(outputFile, ['Owner', 'driveFileId', 'driveFileTitle', 'permissionId', 'role'], lineterminator='\n')
outputCSV.writeheader()
if (len(sys.argv) > 1) and (sys.argv[1] != '-'):
inputFile = open(sys.argv[1], 'rb')
else:
inputFile = sys.stdin
for row in csv.DictReader(inputFile):
for k, v in row.iteritems():
mg = id_n_type.match(k)
if mg:
perm_group = mg.group(1)
if ((row['permissions.{0}.type'.format(perm_group)] == desiredType)
and (row['permissions.{0}.withLink'.format(perm_group)] == desiredWithLink)):
outputCSV.writerow({'Owner': row['Owner'],
'driveFileId': row['id'],
'driveFileTitle': row['title'],
'permissionId': 'id:{0}'.format(row['permissions.{0}.id'.format(perm_group)]),
'role': row['permissions.{0}.role'.format(perm_group)]})
if inputFile != sys.stdin:
inputFile.close()
if outputFile != sys.stdout:
outputFile.close()