Skip to content
Snippets Groups Projects
Verified Commit 3c36431c authored by Martin Weise's avatar Martin Weise
Browse files
parent 69bbdfbe
Branches
Tags
3 merge requests!422Fixed a library issue where the value could not be empty,!421Fixed a library issue where the value could not be empty,!419Fixed a library issue where the value could not be empty
Showing
with 702 additions and 587 deletions
...@@ -23,6 +23,7 @@ minio = "*" ...@@ -23,6 +23,7 @@ minio = "*"
pydantic = "*" pydantic = "*"
dbrepo = {path = "./lib/dbrepo-1.9.0.tar.gz"} dbrepo = {path = "./lib/dbrepo-1.9.0.tar.gz"}
opensearch-py = "*" opensearch-py = "*"
ecs_logging = "*"
[dev-packages] [dev-packages]
coverage = "*" coverage = "*"
......
This diff is collapsed.
...@@ -30,9 +30,8 @@ dictConfig({ ...@@ -30,9 +30,8 @@ dictConfig({
'simple': { 'simple': {
'format': '[%(asctime)s] [%(levelname)s] %(message)s', 'format': '[%(asctime)s] [%(levelname)s] %(message)s',
}, },
'ecs': { "ecs": {
'format': '{"@timestamp": "%(asctime)s", "log.level": "%(levelname)s", "log.logger": "%(module)s", "message": "%(message)s", "service_name": "analyse-service", "service_version": "1.9.0"}', "()": "ecs_logging.StdlibFormatter"
'datefmt': '%Y-%m-%dT%H:%M:%S'
}, },
}, },
'handlers': { 'handlers': {
......
No preview for this file type
No preview for this file type
...@@ -6,6 +6,8 @@ name = "pypi" ...@@ -6,6 +6,8 @@ name = "pypi"
[packages] [packages]
requests = "*" requests = "*"
mariadb = "*" mariadb = "*"
ecs_logging = "*"
dbrepo = {path = "./lib/dbrepo-1.9.0.tar.gz"}
[dev-packages] [dev-packages]
coverage = "*" coverage = "*"
......
import logging
import os import os
import mariadb import mariadb
from requests import post, get from requests import post, get
logging.addLevelName(level=logging.NOTSET, levelName='TRACE')
logging.basicConfig(level=logging.DEBUG)
from logging.config import dictConfig
# logging configuration
dictConfig({
'version': 1,
'formatters': {
'default': {
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
},
'simple': {
'format': '[%(asctime)s] [%(levelname)s] %(message)s',
},
"ecs": {
"()": "ecs_logging.StdlibFormatter"
},
},
'handlers': {
'wsgi': {
'class': 'logging.StreamHandler',
'stream': 'ext://flask.logging.wsgi_errors_stream',
'formatter': 'simple'
},
'file': {
'class': 'logging.handlers.TimedRotatingFileHandler',
'formatter': 'ecs',
'filename': '/var/log/app/service/auth/init.log',
'when': 'm',
'interval': 1,
'backupCount': 5,
'encoding': 'utf8'
},
},
'root': {
'level': 'DEBUG',
'handlers': ['wsgi', 'file']
}
})
def fetch_keycloak_master_access_token() -> str: def fetch_keycloak_master_access_token() -> str:
""" """
...@@ -22,7 +64,7 @@ def fetch_keycloak_master_access_token() -> str: ...@@ -22,7 +64,7 @@ def fetch_keycloak_master_access_token() -> str:
def fetch(username) -> (str, str): def fetch(username) -> (str, str):
print(f'Fetching user id of internal user with username: {username}') logging.debug(f'fetching user id of internal user with username: {username}')
endpoint = os.getenv('AUTH_SERVICE_ENDPOINT', 'http://localhost:8080') endpoint = os.getenv('AUTH_SERVICE_ENDPOINT', 'http://localhost:8080')
response = get(url=f'{endpoint}/admin/realms/dbrepo/users/?username={username}', headers=dict({ response = get(url=f'{endpoint}/admin/realms/dbrepo/users/?username={username}', headers=dict({
'Authorization': f'Bearer {fetch_keycloak_master_access_token()}' 'Authorization': f'Bearer {fetch_keycloak_master_access_token()}'
...@@ -31,7 +73,7 @@ def fetch(username) -> (str, str): ...@@ -31,7 +73,7 @@ def fetch(username) -> (str, str):
raise FileNotFoundError(f'Failed to obtain user') raise FileNotFoundError(f'Failed to obtain user')
ldap_user = response.json()[0] ldap_user = response.json()[0]
user_id = ldap_user["id"] user_id = ldap_user["id"]
print(f'Successfully fetched user id: {user_id}') logging.debug(f'obtained user id for username {username} from auth service: {user_id}')
if 'attributes' not in ldap_user or ldap_user['attributes'] is None: if 'attributes' not in ldap_user or ldap_user['attributes'] is None:
raise ModuleNotFoundError(f'Failed to obtain user attributes: {ldap_user}') raise ModuleNotFoundError(f'Failed to obtain user attributes: {ldap_user}')
ldap_user_attrs = ldap_user['attributes'] ldap_user_attrs = ldap_user['attributes']
...@@ -40,7 +82,6 @@ def fetch(username) -> (str, str): ...@@ -40,7 +82,6 @@ def fetch(username) -> (str, str):
if len(ldap_user_attrs['LDAP_ID']) != 1: if len(ldap_user_attrs['LDAP_ID']) != 1:
raise EnvironmentError(f'Failed to obtain ldap id: wrong length {len(ldap_user_attrs["LDAP_ID"])} != 1') raise EnvironmentError(f'Failed to obtain ldap id: wrong length {len(ldap_user_attrs["LDAP_ID"])} != 1')
ldap_user_id = ldap_user_attrs['LDAP_ID'][0] ldap_user_id = ldap_user_attrs['LDAP_ID'][0]
print(f'Successfully fetched ldap user id: {ldap_user_id}')
return (ldap_user_id, user_id) return (ldap_user_id, user_id)
...@@ -56,7 +97,7 @@ def save(user_id: str, keycloak_id: str, username: str) -> None: ...@@ -56,7 +97,7 @@ def save(user_id: str, keycloak_id: str, username: str) -> None:
(user_id, keycloak_id, username)) (user_id, keycloak_id, username))
conn.commit() conn.commit()
conn.close() conn.close()
print(f'Successfully inserted user: {username}') logging.info(f'Successfully inserted user: {username}')
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -17,6 +17,7 @@ gunicorn = "*" ...@@ -17,6 +17,7 @@ gunicorn = "*"
pydantic = "*" pydantic = "*"
flask_httpauth = "*" flask_httpauth = "*"
grafana-client = "*" grafana-client = "*"
ecs_logging = "*"
[dev-packages] [dev-packages]
coverage = "*" coverage = "*"
......
This diff is collapsed.
...@@ -31,9 +31,8 @@ dictConfig({ ...@@ -31,9 +31,8 @@ dictConfig({
'simple': { 'simple': {
'format': '[%(asctime)s] [%(levelname)s] %(message)s', 'format': '[%(asctime)s] [%(levelname)s] %(message)s',
}, },
'ecs': { "ecs": {
'format': '{"@timestamp": "%(asctime)s", "log.level": "%(levelname)s", "log.logger": "%(module)s", "message": "%(message)s", "service_name": "dashboard-service", "service_version": "1.9.0"}', "()": "ecs_logging.StdlibFormatter"
'datefmt': '%Y-%m-%dT%H:%M:%S'
}, },
}, },
'handlers': { 'handlers': {
...@@ -247,8 +246,18 @@ def update_dashboard(uid: str): ...@@ -247,8 +246,18 @@ def update_dashboard(uid: str):
code='error.database.malformed').model_dump_json(), 400, headers) code='error.database.malformed').model_dump_json(), 400, headers)
try: try:
dashboard_client().update(database) dashboard_client().update(database)
except DashboardNotFound as e: except DashboardNotFound:
return Response(ApiError(status='NOT_FOUND', message=f"Failed to update dashboard: not found", return Response(ApiError(status='NOT_FOUND', message=f"Failed to update dashboard: not found",
code="error.dashboard.missing").model_dump_json(), 404, headers) code="error.dashboard.missing").model_dump_json(), 404, headers)
dashboard_client().update_anonymous_read_access(uid, database.is_public, database.is_schema_public) dashboard_client().update_anonymous_read_access(uid, database.is_public, database.is_schema_public)
return Response(), 202, headers return Response(), 202, headers
@app.route("/api/dashboard/<string:uid>/access/<string:username>", methods=["PUT"], endpoint="update_dashboard_access")
@metrics.gauge(name='dbrepo_update_dashboard_access', description='Time needed to update dashboard access')
@swag_from("/app/ds-yml/update_dashboard_access.yml")
@auth.login_required(role=['system'])
def update_dashboard(uid: str, username: str):
logging.debug(f'endpoint update dashboard access, uid={uid}, username={username}')
# not implemented
return Response(), 202, headers
tags:
- dashboard-endpoint
summary: "Update dashboard access"
operationId: update_dashboard_access
description: "Updates a dashboard access in the Dashboard UI. Requires role `system`."
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- name: uid
in: path
required: true
schema:
type: string
format: uuid
- name: username
in: path
required: true
schema:
type: string
responses:
202:
description: Updated dashboard access successfully
content:
application/json:
schema:
type: object
security:
- bearerAuth: [ ]
- basicAuth: [ ]
...@@ -20,9 +20,8 @@ dictConfig({ ...@@ -20,9 +20,8 @@ dictConfig({
'simple': { 'simple': {
'format': '[%(asctime)s] [%(levelname)s] %(message)s', 'format': '[%(asctime)s] [%(levelname)s] %(message)s',
}, },
'ecs': { "ecs": {
'format': '{"@timestamp": "%(asctime)s", "log.level": "%(levelname)s", "log.logger": "%(module)s", "message": "%(message)s", "service_name": "dashboard-service-init", "service_version": "1.9.0"}', "()": "ecs_logging.StdlibFormatter"
'datefmt': '%Y-%m-%dT%H:%M:%S'
}, },
}, },
'handlers': { 'handlers': {
......
No preview for this file type
No preview for this file type
...@@ -19,6 +19,7 @@ rdflib = "*" ...@@ -19,6 +19,7 @@ rdflib = "*"
grafana-client = "*" grafana-client = "*"
dbrepo = {path = "./lib/dbrepo-1.9.0.tar.gz"} dbrepo = {path = "./lib/dbrepo-1.9.0.tar.gz"}
gunicorn = "*" gunicorn = "*"
ecs_logging = "*"
[dev-packages] [dev-packages]
coverage = "*" coverage = "*"
......
This diff is collapsed.
...@@ -31,9 +31,8 @@ dictConfig({ ...@@ -31,9 +31,8 @@ dictConfig({
'simple': { 'simple': {
'format': '[%(asctime)s] [%(levelname)s] %(message)s', 'format': '[%(asctime)s] [%(levelname)s] %(message)s',
}, },
'ecs': { "ecs": {
'format': '{"@timestamp": "%(asctime)s", "log.level": "%(levelname)s", "log.logger": "%(module)s", "message": "%(message)s", "service_name": "search-service", "service_version": "1.9.0"}', "()": "ecs_logging.StdlibFormatter"
'datefmt': '%Y-%m-%dT%H:%M:%S'
}, },
}, },
'handlers': { 'handlers': {
......
...@@ -21,9 +21,8 @@ dictConfig({ ...@@ -21,9 +21,8 @@ dictConfig({
'simple': { 'simple': {
'format': '[%(asctime)s] [%(levelname)s] %(message)s', 'format': '[%(asctime)s] [%(levelname)s] %(message)s',
}, },
'ecs': { "ecs": {
'format': '{"@timestamp": "%(asctime)s", "log.level": "%(levelname)s", "log.logger": "%(module)s", "message": "%(message)s", "service_name": "search-service-init", "service_version": "1.9.0"}', "()": "ecs_logging.StdlibFormatter"
'datefmt': '%Y-%m-%dT%H:%M:%S'
}, },
}, },
'handlers': { 'handlers': {
......
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment