From 38df6e873b928e9131ba94b7195103adea857c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 19 May 2017 12:02:00 +0200 Subject: [PATCH] Extracted function to generate authentication tokens for service accounts. --- pillar/api/service.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pillar/api/service.py b/pillar/api/service.py index 3d176b7c..1637a113 100644 --- a/pillar/api/service.py +++ b/pillar/api/service.py @@ -221,10 +221,17 @@ def create_service_account(email: str, roles: typing.Iterable, service: dict, user.update(result) # Create an authentication token that won't expire for a long time. - token = local_auth.generate_and_store_token(user['_id'], days=36500, prefix=b'SRV') + token = generate_auth_token(user['_id']) return user, token +def generate_auth_token(service_account_id) -> dict: + """Generates an authentication token for a service account.""" + + token_info = local_auth.generate_and_store_token(service_account_id, days=36500, prefix=b'SRV') + return token_info + + def setup_app(app, api_prefix): app.register_api_blueprint(blueprint, url_prefix=api_prefix)