Is there a way disable link sharing permissions in bulk via the Google Drive API?

时间:2019-05-22 18:38:17

标签: python

I'm running a security audit and I've found that I have about 10,000 files in our G Suite that are all set to "Anyone can search" permissions via link sharing in Google Drive for our domain. I need to turn that to "off" instead. (see screenshot link). I have all of the file IDs thanks to the audit tool I found on the market place, but now it's time to actually do the work and change the link sharing.

Since I don't have enough rep to post images, I've got a link here. https://imgur.com/9wnNBJ9

I've looked at the API and it only seems to change the owner of the file from the testing tool available on the site. I know that I can use some of this to target the files successfully, it's just getting that link-share stuff disabled that's got me stuck. My code sample below is basically a copy/paste from the permissions API reference below.

(https://developers.google.com/drive/api/v3/reference/permissions/update)

from apiclient import errors
def insert_permission(service, file_id, value, perm_type, role):
  new_permission = {
      'value': value,
      'type': perm_type,
      'role': role
  }
  try:
    return service.permissions().insert(
        fileId=file_id, body=new_permission).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % error
  return None

I don't actually have any errors at this time. I'm pretty sure I'm just using the wrong part of the API to accomplish what I'm trying to do. It's just not changing the right thing.

0 个答案:

没有答案
相关问题