From 8f0b278dd43aba88b154a7c1ee6435518f7a2dff Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sat, 4 Sep 2021 23:29:39 +0000 Subject: [PATCH] Rename auth functions to wiki auth functions --- apiserver/apiserver/api/serializers.py | 6 +++--- apiserver/apiserver/api/utils_auth.py | 11 +++++------ apiserver/apiserver/secrets.py.example | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index 0cc8702..57b7dc4 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -564,7 +564,7 @@ class MyPasswordChangeSerializer(PasswordChangeSerializer): ) if utils_auth.is_configured(): - if utils_auth.set_password(data) != 200: + if utils_auth.set_wiki_password(data) != 200: msg = 'Problem connecting to Auth server: set.' utils.alert_tanner(msg) logger.info(msg) @@ -605,7 +605,7 @@ class MyPasswordResetConfirmSerializer(PasswordResetConfirmSerializer): ) if utils_auth.is_configured(): - if utils_auth.set_password(data) != 200: + if utils_auth.set_wiki_password(data) != 200: msg = 'Problem connecting to Auth server: set.' utils.alert_tanner(msg) logger.info(msg) @@ -657,6 +657,6 @@ class SpaceportAuthSerializer(LoginSerializer): if result: data = self.context['request'].data - utils_auth.set_password(data) + utils_auth.set_wiki_password(data) return result diff --git a/apiserver/apiserver/api/utils_auth.py b/apiserver/apiserver/api/utils_auth.py index 9e3f52c..6a6f1a2 100644 --- a/apiserver/apiserver/api/utils_auth.py +++ b/apiserver/apiserver/api/utils_auth.py @@ -6,23 +6,22 @@ import requests from apiserver import secrets from apiserver.api import utils -def is_configured(): - return bool(secrets.AUTH_API_URL and secrets.AUTH_API_KEY) +def wiki_is_configured(): + return bool(secrets.WIKI_AUTH_API_URL and secrets.AUTH_API_KEY) -def auth_api(route, data): +def auth_api(url, data): try: headers = {'Authorization': 'Token ' + secrets.AUTH_API_KEY} - url = secrets.AUTH_API_URL + route r = requests.post(url, data=data, headers=headers, timeout=3) return r.status_code except BaseException as e: logger.error('Auth {} - {} - {}'.format(url, e.__class__.__name__, str(e))) return None -def set_password(data): +def set_wiki_password(data): auth_data = dict( username=data['username'], password=data['password'], ) - return auth_api('set-password', auth_data) + return auth_api(secrets.WIKI_AUTH_API_URL + 'set-wiki-password', auth_data) diff --git a/apiserver/apiserver/secrets.py.example b/apiserver/apiserver/secrets.py.example index 5360a63..1cf694e 100644 --- a/apiserver/apiserver/secrets.py.example +++ b/apiserver/apiserver/secrets.py.example @@ -40,10 +40,10 @@ LDAP_API_URL = '' # spaceport/ldapserver/secrets.py LDAP_API_KEY = '' -# Auth API url +# Wiki Auth API url # should contain the IP and port of the script and machine connected over VPN # with trailing slash -AUTH_API_URL = '' +WIKI_AUTH_API_URL = '' # Auth API key # should be equal to the auth token value set in