Added bearer token

This commit is contained in:
Yarninator 2025-11-26 15:45:29 +01:00
parent d755775f43
commit f0fe08e0b7
4 changed files with 19 additions and 5 deletions

1
.gitignore vendored
View file

@ -161,5 +161,6 @@ cython_debug/
#.idea/
secrets/auth.yaml
secrets/bearer.yaml
db/database.db
.vscode/

View file

@ -1,7 +1,8 @@
import os
ROOT_PATH = project_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
SECRETS_FILE_PATH = ROOT_PATH + '/secrets/auth.yaml'
AUTH_FILE_PATH = ROOT_PATH + '/secrets/auth.yaml'
BEARER_FILE_PATH = ROOT_PATH + '/secrets/bearer.yaml'
DATABASE_FILE_PATH = ROOT_PATH + '/db/database.db'
DATABASE_FILE_PROJECT_PATH = f"/db/database.db"

View file

@ -6,20 +6,29 @@ from src.config import definitions
username: str = None
password: str = None
bearer_token: str = None
def load_username_password_from_secrets():
def load_secrets():
global username
global password
global bearer_token
with open(definitions.SECRETS_FILE_PATH, 'r') as auth_file:
with open(definitions.AUTH_FILE_PATH, 'r') as auth_file:
auth_object = yaml.safe_load(auth_file)
username = auth_object['username']
password = auth_object['password']
with open(definitions.BEARER_FILE_PATH, 'r') as bearer_file:
token_object = yaml.safe_load(bearer_file)
bearer_token = token_object['token']
def get_username_password():
return username, password
def get_bearer_token():
return bearer_token
load_username_password_from_secrets()
load_secrets()

View file

@ -17,7 +17,8 @@ from src.config import definitions
authenticated_session: requests.Session = requests.Session()
authenticated_session.headers.update({
"Cache-Control": "no-cache"
"Cache-Control": "no-cache",
"Authorization": "Bearer {}".format(auth_manager.bearer_token)
})
def url_to_xml_object(url: HttpUrl) -> ET.Element:
@ -35,6 +36,8 @@ def url_to_xml_object(url: HttpUrl) -> ET.Element:
time.sleep(10)
r = authenticated_session.get(url)
print(url, ':', r.text)
assert r.status_code == 200, "Got {} status code".format(r.status_code)
root = ET.fromstring(r.content)
return root