Skip to content

Commit

Permalink
Merge pull request #46 from FinnStutzenstein/authEndpoint
Browse files Browse the repository at this point in the history
Get endpoint fom env variables
  • Loading branch information
FinnStutzenstein committed Nov 9, 2020
2 parents 39a4148 + b5b66a4 commit a094223
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
5 changes: 2 additions & 3 deletions auth/libraries/pip-auth/authlib/auth_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ class AuthHandler:
A function to print debug-messages can optionally be passed.
"""

def __init__(self, auth_path: str, debug_fn: Any = print) -> None:
self.auth_url = auth_path
def __init__(self, debug_fn: Any = print) -> None:
self.debug_fn = debug_fn
self.http_handler = HttpHandler(auth_path)
self.http_handler = HttpHandler(debug_fn)
self.validator = Validator(self.http_handler, debug_fn)
self.hashing_handler = HashingHandler()

Expand Down
1 change: 0 additions & 1 deletion auth/libraries/pip-auth/authlib/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
AUTH_TEST_URL = "http://localhost:9004"
AUTHENTICATION_HEADER = "Authentication"
REFRESH_ID = "refreshId"
USER_ID = "userId"
Expand Down
17 changes: 11 additions & 6 deletions auth/libraries/pip-auth/authlib/http_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
from typing import Optional, Tuple, Dict, Any, Callable

from .exceptions import AuthenticateException

import os

class HttpHandler:
auth_url = ""
def __init__(self, debug_fn: Any=print) -> None:
self.auth_endpoint = self.get_endpoint(debug_fn)

def __init__(self, auth_url: str) -> None:
self.auth_url = auth_url
def get_endpoint(self, debug_fn: Any=print) -> str:
host = os.environ.get("AUTH_HOST", "localhost")
port = int(os.environ.get("AUTH_PORT", 9004))
endpoint = f"http://{host}:{port}"
debug_fn(f"Auth endpoint: {endpoint}")
return endpoint

def send_request(self, path: str, headers=None, payload=None) -> requests.Response:
response = None
try:
url = f"{self.auth_url}/system/auth{self.format_url(path)}"
url = f"{self.auth_endpoint}/system/auth{self.format_url(path)}"
response = requests.post(url, data=payload, headers=headers)
except requests.exceptions.ConnectionError as e:
raise AuthenticateException(
Expand All @@ -26,7 +31,7 @@ def send_internal_request(
) -> requests.Response:
response = None
try:
url = f"{self.auth_url}/internal/auth{self.format_url(path)}"
url = f"{self.auth_endpoint}/internal/auth{self.format_url(path)}"
response = requests.post(url, headers=headers, cookies=cookies)
except requests.exceptions.ConnectionError as e:
raise AuthenticateException(
Expand Down
3 changes: 1 addition & 2 deletions auth/libraries/pip-auth/authlib/test/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
import requests

from ..auth_handler import AuthHandler
from ..constants import AUTH_TEST_URL
from .fake_request import FakeRequest


class BaseTestEnvironment(unittest.TestCase):
auth_handler = AuthHandler(AUTH_TEST_URL)
auth_handler = AuthHandler()
fake_request = FakeRequest()

def get_invalid_access_token(self):
Expand Down
5 changes: 2 additions & 3 deletions auth/libraries/pip-auth/authlib/test/fake_request.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import requests

from ..http_handler import HttpHandler
from ..constants import AUTH_TEST_URL

credentials = {"username": "admin", "password": "admin"}


class FakeRequest:
http_handler = HttpHandler(AUTH_TEST_URL)
http_handler = HttpHandler()

def test_connection(self):
return requests.get(f"{AUTH_TEST_URL}/system/auth/")
return requests.get(f"{self.http_handler.auth_endpoint}/system/auth/")

def login(self):
return self.http_handler.send_request("login", payload=credentials)
2 changes: 1 addition & 1 deletion auth/libraries/pip-auth/authlib/test/test_hashing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ..auth_handler import AuthHandler
from .base import BaseTestEnvironment
from ..constants import AUTH_TEST_URL, HASHED_LENGTH
from ..constants import HASHED_LENGTH


class TestHashing(BaseTestEnvironment):
Expand Down

0 comments on commit a094223

Please sign in to comment.