-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrevokeAccess
executable file
·78 lines (58 loc) · 2.55 KB
/
revokeAccess
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
from __future__ import print_function
from tkinter import *
from tkinter.messagebox import showinfo
from random import *
# This program revokes a specific user's access specified by their email address and the document ID.
from cloudperm import *
import pprint
try:
import argparse
parser = argparse.ArgumentParser(parents=[cloudperm_argparser])
parser.add_argument('revokeaccount', type=str, help='Account to revoke the permissions for the provided Document IDs')
parser.add_argument('documents', metavar='DocumentID', type=str, nargs='+', help='Google Document IDs')
args = parser.parse_args()
except ImportError:
args = None
def main():
"""
Loop through the list of provided document IDs and revoke
the access for the provided Google Drive account.
"""
pp = pprint.PrettyPrinter(indent=4)
credentials = get_credentials(args)
http = credentials.authorize(httplib2.Http())
service = discovery.build('drive', 'v2', http=http)
parser = SafeConfigParser()
parser.read("DriveConfig.INI")
# fileids = "["+ email +"]";
fileids = []
accountToRevoke = args.revokeaccount
if (len(args.documents) > 0):
for fileid in args.documents:
fileids.append(fileid)
else:
for section in parser.sections(): # Fix this later.
for name,value in parser.items(section):
if name == "url":
fileids.append(value)
for fileid in fileids:
title = retrieve_document_title(service, fileid);
perm_list = retrieve_permissions(service, fileid)
accountrevoked = False;
for entry in perm_list:
if type(entry) is dict:
if 'emailAddress' in entry:
if entry['emailAddress'] == accountToRevoke:
permIdToRevoke = entry['id']
revoke_response = revoke_document_role(service, fileid, permIdToRevoke);
pp = pprint.PrettyPrinter(indent=8,depth=6)
if revoke_response:
pp.pprint(revoke_response);
else: # An empty response to
accountrevoked = True;
print("Revoked access for " + accountToRevoke + " from document '" + title.encode('utf-8') + "'");
if not accountrevoked:
print("WARNING: access was not revoked for " + accountToRevoke + " on file '" + title.encode('utf-8') + "'");
if __name__ == '__main__':
main()