gam update drivefileacl Fails Due to Bad Dict Instantiation

258 views
Skip to first unread message

Chris Buckley

unread,
Jun 10, 2014, 11:19:20 PM6/10/14
to google-ap...@googlegroups.com
Hi guys,

Apologies for posting this here instead of logging an issue on the Google Code page, but I'm having issues with it accepting my issue submission.

In GAM 3.2, calling the following command will fail:

gam user f...@example.com update drivefileacl y7fqhiurqh8q9 b...@example.com role writer

With the following stack trace:
Traceback (most recent call last):
  File "gam.py", line 7340, in <module>
  File "gam.py", line 1755, in updateDriveFileACL
NameError: global name 'perm_type' is not defined

GAM Version:
Dito GAM 3.2
Python 2.7.6 64-bit final
google-api-python-client 1.2
Windows-7-6.1.7601-SP1 AMD64

I've taken a look at the source, and the issue here is that when the body dict is instantiated in the updateDriveFileAcl function, the 'type' key is assigned the variable perm_type - this variable isn't defined anywhere in the code.

I've fixed the issue in the code (line 1755) by replacing the following line:

body = {u'type': perm_type}

with:

body = {}

This instantiates an empty dict (the original dict instantiation looks like it might have been copy/pasted in from the addDriveFileACL function above it?). I can't see how the 'type' key/value pair would be used in a permissions update, so this should be fine, although there may be a nicer way to fix the issue.

I've tested this with variety of ACL updates (writer, reader, etc) and the command listed at the top of this now works with no issues.

Also, it's not noted anywhere in the documentation that for an ownership transfer to be successful using the updateFileACL command, you need to pass "TransferOwnership True" as part of the command (otherwise it'll fail with a "You don't have permission to transfer ownership" error.) This could maybe be handled in the code by setting TransferOwnership to True implicitly if the new role passed is "owner."

Otherwise, the command winds up looking like:
gam user f...@example.com update drivefileacl y7fqhiurqh8q9 b...@example.com role owner transferownership true

Which seems a little redundant :)

Chris Buckley

unread,
Jun 10, 2014, 11:57:26 PM6/10/14
to google-ap...@googlegroups.com
Just a quick update - I was able to make the TransferOwnership work implicitly by adding the following if statement nested inside the elif statement for role (line 1761):

elif sys.argv[i].lower() == u'role':
  body
[u'role'] = sys.argv[i+1]
 
if body[u'role'] not in [u'reader', u'commenter', u'writer', u'owner']:
   
print u'ERROR: role must be reader, commenter, writer or owner, got %s' % body[u'role']
    sys
.exit(9)
 
if body[u'role'] == u'commenter':
    body
[u'role'] = u'reader'
    body
[u'additionalRoles'] = [u'commenter']
 
if body[u'role'] == u'owner':
    transferOwnership
= True
  i
+= 2


I was then able to remove the if statement that followed it that checks for the transferownership argument, and made several ownership transfers successfully.

I can't think of a use case where setting transferOwnership to false would be required, so I had no issues when removing that from the block. If there is a use case for that, then there'd be no reason to make this change (just to 

Stephen Gale

unread,
Sep 6, 2014, 12:07:17 AM9/6/14
to google-ap...@googlegroups.com
I'm having a similar issue with GAM  3.21
I can see where the changes you recommended above are in place already (Line 1763) but I get the same error.  I am attempting to change the permissions of a file within my domain with the command:
 gam user us...@example.com update drivefileacl 0b1wzEsxZtZ8TN3dXcTlvSUVZY2E other...@example.com role reader
and I get the error: 
Traceback (most recent call last):
  File "~/GAM/gam.py", line 7345, in <module>
    updateDriveFileACL(users)
  File "~/GAM/gam.py", line 1757, in updateDriveFileACL

    body = {u'type': perm_type}
NameError: global name 'perm_type' is not defined

When I change line  1757 which is "body = {u'type': perm_type}" to "body = {}" I end up with:
raceback (most recent call last):
  File "~/GAM/gam.py", line 7345, in <module>
    updateDriveFileACL(users)
  File "~/GAM/gam.py", line 1786, in updateDriveFileACL
    drive = buildGAPIServiceObject(u'drive', user)
  File "/home/stephen/Downloads/GAM/gam.py", line 573, in buildGAPIServiceObject
    SERVICE_ACCOUNT_EMAIL = json_data[u'web'][u'client_email']
KeyError: u'web'

Today is my first day working with GAM.  I'm sure that the other functionality works better than this aspect.  There's just soooo many aspects of Google Apps to manage, something is bound to not be at 100%.
Reply all
Reply to author
Forward
0 new messages