Commit 3c9e0825 authored by Manuel's avatar Manuel

[BusinessLogic] security updates + new endpoint

- extracted routes into seperate yaml file to avoid code duplication
- created additional security definition for local mode which accepts all tokens
- added endpoint to add a schema with mappings included
parent 8bd0f389
securityDefinitions:
JwtRegular:
type: apiKey
name: Authorization
in: header
x-apikeyInfoFunc: "security.security_util.verifyAll"
JwtAdmin:
type: apiKey
name: Authorization
in: header
x-apikeyInfoFunc: "security.security_util.verifyAll"
...@@ -88,6 +88,9 @@ def _verify(token:str, roles:List[str]=[]): ...@@ -88,6 +88,9 @@ def _verify(token:str, roles:List[str]=[]):
return None return None
def verifyAll(token, required_scopes):
return {}
def verifyTokenRegular(token, required_scopes): def verifyTokenRegular(token, required_scopes):
return _verify(token) return _verify(token)
......
...@@ -131,16 +131,14 @@ def add_by_schema(): ...@@ -131,16 +131,14 @@ def add_by_schema():
columns = [(c.replace("/", "_"), c) for c in columns] columns = [(c.replace("/", "_"), c) for c in columns]
columns.append(("UniqueID", "Customer+Postcode+Timestamp")) columns.append(("UniqueID", "Customer+Postcode+Timestamp"))
# url = f"https://{nc.BUSINESS_LOGIC_HOSTNAME}:{nc.BUSINESS_LOGIC_REST_PORT}/api/use-cases/{use_case}/schema/mapping" url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/schema"
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/schema/mapping"
for internal, external in columns: response = requests.post(
response = requests.put(
url, url,
verify=False, verify=False,
proxies = { "http":None, "https":None }, proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"}, headers = { "Authorization": f"Bearer {jwt}"},
json = { "internal":internal,"external":external } json = columns
) )
if response.status_code == 200: if response.status_code == 200:
......
...@@ -50,7 +50,7 @@ class SchemaRepository(MongoRepositoryBase): ...@@ -50,7 +50,7 @@ class SchemaRepository(MongoRepositoryBase):
def delete_for_use_case(self, use_case: str): def delete_for_use_case(self, use_case: str):
collection = self._database[self._schema_collection] collection = self._database[self._schema_collection]
collection.delete_one({"use_case": use_case}) collection.delete_many({"use_case": use_case})
def delete_all(self): def delete_all(self):
collection = self._database[self._schema_collection] collection = self._database[self._schema_collection]
......
#global imports #global imports
from db.entities.schema import Schema
from db.entities.layer_adapter import LayerAdapter from db.entities.layer_adapter import LayerAdapter
from db.schema_repository import SchemaRepository from db.schema_repository import SchemaRepository
from db.use_case_repository import UseCaseRepository from db.use_case_repository import UseCaseRepository
...@@ -13,6 +14,22 @@ schema_repository = SchemaRepository() ...@@ -13,6 +14,22 @@ schema_repository = SchemaRepository()
def all(): def all():
return [schema.to_serializable_dict() for schema in schema_repository.all()] return [schema.to_serializable_dict() for schema in schema_repository.all()]
def add_complete(use_case: str):
data = request.json
if "mappings" not in data:
return Response(status=400, response="Missing fields. Required fields: (mappings).")
reference = schema_repository.get_for_use_case(use_case)
if reference != None and len(reference.mappings) > 0:
return Response(status=400, response="Schema already exists.")
schema_repository.delete_for_use_case(use_case)
data["use_case"] = use_case
schema_repository.add(Schema.from_serializable_dict(data))
return Response(status=200)
def get_for_use_case(use_case:str): def get_for_use_case(use_case:str):
use_case_repository.put(use_case) use_case_repository.put(use_case)
schema = schema_repository.get_for_use_case(use_case) schema = schema_repository.get_for_use_case(use_case)
...@@ -23,11 +40,6 @@ def get_for_use_case(use_case:str): ...@@ -23,11 +40,6 @@ def get_for_use_case(use_case:str):
return Response(status=404, response=f"Schema {use_case} does not exist") return Response(status=404, response=f"Schema {use_case} does not exist")
def delete_for_use_case(use_case:str): def delete_for_use_case(use_case:str):
schema = schema_repository.get_for_use_case(use_case)
if schema == None:
return Response(status=404, response=f"Schema {use_case} does not exist")
schema_repository.delete_for_use_case(use_case) schema_repository.delete_for_use_case(use_case)
return Response(status=200) return Response(status=200)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment