From 50d62f17b84c167e09222d0e8a06b97f8fbb1190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 18 May 2017 15:38:12 +0200 Subject: [PATCH] Allow specification of full name when creating service account --- pillar/api/service.py | 7 +++++-- pillar/cli.py | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pillar/api/service.py b/pillar/api/service.py index 26eedf9b..3d176b7c 100644 --- a/pillar/api/service.py +++ b/pillar/api/service.py @@ -186,12 +186,15 @@ def manage_user_group_membership(db_user, role, action): return user_groups -def create_service_account(email: str, roles: typing.Iterable, service: dict): +def create_service_account(email: str, roles: typing.Iterable, service: dict, + *, full_name: str=None): """Creates a service account with the given roles + the role 'service'. :param email: optional email address associated with the account. :param roles: iterable of role names :param service: dict of the 'service' key in the user. + :param full_name: Full name of the service account. If None, will be set to + something reasonable. :return: tuple (user doc, token doc) """ @@ -207,7 +210,7 @@ def create_service_account(email: str, roles: typing.Iterable, service: dict): 'roles': roles, 'settings': {'email_communications': 0}, 'auth': [], - 'full_name': f'SRV-{user_id}', + 'full_name': full_name or f'SRV-{user_id}', 'service': service} if email: user['email'] = email diff --git a/pillar/cli.py b/pillar/cli.py index e8efbcfa..9714f1b5 100644 --- a/pillar/cli.py +++ b/pillar/cli.py @@ -311,14 +311,16 @@ def badger(action, user_email, role): log.info('Status : %i', status) -def create_service_account(email, service_roles, service_definition): +def create_service_account(email, service_roles, service_definition, + *, full_name: str=None): from pillar.api import service from pillar.api.utils import dumps account, token = service.create_service_account( email, service_roles, - service_definition + service_definition, + full_name=full_name, ) print('Service account information:')