Commit 4dd7a1fc authored by Rob Carleski's avatar Rob Carleski 🇮🇸
Browse files

Minor enhancements

* Autogenerate password if one isn't provided

* Add canned text to password file

* Add full_name as alias to mcommunity group
parent ea3e3ad4
......@@ -7,9 +7,13 @@ import logging.handlers
import mcommunity
import os
import re
import string
import yaml
from boxsdk.object.collaboration import CollaborationRole
from datetime import datetime
from datetime import timedelta
from secrets import choice
from subprocess import check_output as cmd
from subprocess import CalledProcessError
......@@ -263,6 +267,11 @@ https://documentation.its.umich.edu/node/339/
exit(2)
try:
self.logger.info(
'Adding Mcommunity group alias',
extra={'entity': self.account}
)
client.update_group_aliases(self.full_name)
self.logger.info(
'Updating Mcommunity group membership',
extra={'entity': self.account}
......@@ -318,9 +327,19 @@ https://documentation.its.umich.edu/node/339/
self.config['general']['data_dir'],
self.account
)
exp_time = datetime.today() + timedelta(days=10)
with open(passFilePath, 'w') as passwordFile:
passwordFile.write(self.password)
passwordFile.write('''
For security, this file will expire automatically on {}. Please store
this password somewhere safe. ITS has best practice recommendations for
doing so at the following URL:
https://safecomputing.umich.edu/protect-yourself/manage-your-passwords
The password for your requested shared account is:
{}
'''.format(exp_time.strftime('%Y-%m-%d'), self.password))
upload_output = cmd([
self.config['google']['gam_command'],
......@@ -361,7 +380,10 @@ https://documentation.its.umich.edu/node/339/
def create_extra_attr(self):
try:
self.full_name = self.first_name + self.last_name
self.full_name = '{} {}'.format(
self.first_name,
self.last_name
)
except TypeError:
split = re.split(r'[\-\_\.\s]+', self.account)
self.first_name = ' '.join(split[:len(split)//2]).title()
......@@ -409,7 +431,6 @@ def main():
'--password',
'-p',
help='The password to use for the account',
required=True
)
parser.add_argument(
'--owners',
......@@ -474,6 +495,10 @@ def main():
ch.setFormatter(formatter)
logger.addHandler(ch)
if not args.password:
pool = string.ascii_letters + string.digits + '!@#$%&*'
args.password = ''.join(choice(pool) for i in range(12))
sa = SharedAccount(vars(args), config)
sa.set_up_mcommunity_group()
sa.set_kerberos_password()
......
......@@ -87,13 +87,3 @@ def test_upload_and_share_password():
]
}
sa.upload_and_share_password()
def test_create_extra_attr():
for delim in ['.', '-', '_', ' ']:
sa.first_name = None
sa.last_name = None
sa.account = delim.join(['test', 'shared', 'account'])
sa.create_extra_attr()
assert ' ' not in sa.account
assert sa.full_name == 'Test Shared Account'
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