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
from secrets import choice
from subprocess import check_output as cmd
from subprocess import CalledProcessError
from subprocess import STDOUT
devnull = open(os.devnull, 'w')
......@@ -371,6 +372,24 @@ The password for your requested shared account is:
).groups()[0]
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:
cmd([
self.config['google']['gam_command'],
......@@ -379,14 +398,14 @@ The password for your requested shared account is:
'add',
'drivefileacl',
file_id,
'user',
entity_type,
owner,
'role',
'reader'
])
], stderr=STDOUT)
except CalledProcessError:
self.logger.warning(
'Error sharing password file with {}'.format(owner),
'Unable to share password with {}'.format(owner),
extra={'entity': self.account}
)
continue
......
......@@ -148,6 +148,24 @@ class SharedAccount():
owners.append(owner)
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:
cmd([
self.config['google']['gam_command'],
......@@ -156,7 +174,7 @@ class SharedAccount():
'add',
'drivefileacl',
self.file_id,
'user',
entity_type,
owner,
'role',
'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