Commit 047cd238 authored by Rob Carleski's avatar Rob Carleski 🇮🇸
Browse files

Fix sharing password files with groups in Google.

parent 571557fd
...@@ -16,6 +16,7 @@ from datetime import timedelta ...@@ -16,6 +16,7 @@ from datetime import timedelta
from secrets import choice from secrets import choice
from subprocess import check_output as cmd from subprocess import check_output as cmd
from subprocess import CalledProcessError from subprocess import CalledProcessError
from subprocess import STDOUT
devnull = open(os.devnull, 'w') devnull = open(os.devnull, 'w')
...@@ -371,6 +372,24 @@ The password for your requested shared account is: ...@@ -371,6 +372,24 @@ The password for your requested shared account is:
).groups()[0] ).groups()[0]
for owner in self.owners: for owner in self.owners:
try:
whatis = cmd([
self.config['google']['gam_command'],
'whatis',
owner
], stderr=STDOUT)
except CalledProcessError:
self.logger.warning(
'{} does not seem to exist in Google.'.format(owner),
extra={'entity': self.account}
)
continue
if b'is a user' in whatis:
entity_type = 'user'
elif b'is a group' in whatis:
entity_type = 'group'
try: try:
cmd([ cmd([
self.config['google']['gam_command'], self.config['google']['gam_command'],
...@@ -379,14 +398,14 @@ The password for your requested shared account is: ...@@ -379,14 +398,14 @@ The password for your requested shared account is:
'add', 'add',
'drivefileacl', 'drivefileacl',
file_id, file_id,
'user', entity_type,
owner, owner,
'role', 'role',
'reader' 'reader'
]) ], stderr=STDOUT)
except CalledProcessError: except CalledProcessError:
self.logger.warning( self.logger.warning(
'Error sharing password file with {}'.format(owner), 'Unable to share password with {}'.format(owner),
extra={'entity': self.account} extra={'entity': self.account}
) )
continue continue
......
...@@ -148,6 +148,24 @@ class SharedAccount(): ...@@ -148,6 +148,24 @@ class SharedAccount():
owners.append(owner) owners.append(owner)
for owner in owners: for owner in owners:
try:
whatis = cmd([
self.config['google']['gam_command'],
'whatis',
owner
], stderr=STDOUT)
except CalledProcessError:
self.logger.warning(
'{} does not seem to exist in Google.'.format(owner),
extra={'entity': self.account}
)
continue
if b'is a user' in whatis:
entity_type = 'user'
elif b'is a group' in whatis:
entity_type = 'group'
try: try:
cmd([ cmd([
self.config['google']['gam_command'], self.config['google']['gam_command'],
...@@ -156,7 +174,7 @@ class SharedAccount(): ...@@ -156,7 +174,7 @@ class SharedAccount():
'add', 'add',
'drivefileacl', 'drivefileacl',
self.file_id, self.file_id,
'user', entity_type,
owner, owner,
'role', 'role',
'reader' 'reader'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment