From d3bcd6ee05ee6a322d28d32810d20fcdec0b6fdd Mon Sep 17 00:00:00 2001 From: Elias Showk Date: Fri, 23 Feb 2018 17:11:12 +0100 Subject: [PATCH] authentic agent : refactored hobo_deploy command to get username/email/first_name/last_name from hobo.json and settings.ADMINS to create super-users (#21888) --- .../authentic2/management/commands/hobo_deploy.py | 30 ++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/hobo/agent/authentic2/management/commands/hobo_deploy.py b/hobo/agent/authentic2/management/commands/hobo_deploy.py index f0e6030..a1ad16e 100644 --- a/hobo/agent/authentic2/management/commands/hobo_deploy.py +++ b/hobo/agent/authentic2/management/commands/hobo_deploy.py @@ -38,25 +38,29 @@ class Command(hobo_deploy.Command): # Activate default translation activate(settings.LANGUAGE_CODE) - # create hobo users in authentic to bootstrap (don't update them, - # hobo is not a provisioning system) + # create hobo super-users in authentic to bootstrap for user_dict in hobo_environment.get('users'): + # create hobo users in authentic to bootstrap + # (don't update them, hobo is not a provisioning system) user, created = get_user_model().objects.get_or_create( + defaults=user_dict, username=user_dict.get('username')) if created: - for key, value in user_dict.items(): - setattr(user, key, value) - user.is_staff = True - user.is_superuser = True + # try: - admin_name, admin_email = settings.ADMINS[0] + username, email = settings.ADMINS[0] except (IndexError, ValueError): - admin_name, admin_email = ('Super Publik', 'admin@entrouvert.org') - if not user.email: - user.email = admin_email + # without username, we put default values + username = user_dict.get('username', 'admin') + email = user_dict.get('email', 'admin@entrouvert.org') + + # to comply with some SP if not user.first_name and not user.last_name: - # give a name as it's required by some SP - user.first_name = admin_name + user.first_name = username + if not user.email: + user.email = email + user.is_staff = True + user.is_superuser = True user.save() # create/update user attributes @@ -124,7 +128,7 @@ class Command(hobo_deploy.Command): metadata_response = requests.get( sp_url, verify=app_settings.A2_VERIFY_SSL, timeout=5) metadata_response.raise_for_status() - except requests.exceptions.RequestException, e: + except requests.exceptions.RequestException as e: self.stderr.write(self.style.WARNING( 'Error registering %s: %r\n' % (sp_url, e))) continue -- 2.16.1