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]=[]):
return None
def verifyAll(token, required_scopes):
return {}
def verifyTokenRegular(token, required_scopes):
return _verify(token)
......
......@@ -131,23 +131,21 @@ def add_by_schema():
columns = [(c.replace("/", "_"), c) for c in columns]
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/mapping"
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/schema"
for internal, external in columns:
response = requests.put(
response = requests.post(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
json = { "internal":internal,"external":external }
json = columns
)
if response.status_code == 200:
print(f"Response: {response.status_code}")
else:
print(f"Response: {response.status_code}: {response.text}")
if response.status_code == 200:
print(f"Response: {response.status_code}")
else:
print(f"Response: {response.status_code}: {response.text}")
if __name__ == "__main__":
add_by_schema()
add_by_layers()
\ No newline at end of file
......@@ -50,7 +50,7 @@ class SchemaRepository(MongoRepositoryBase):
def delete_for_use_case(self, use_case: str):
collection = self._database[self._schema_collection]
collection.delete_one({"use_case": use_case})
collection.delete_many({"use_case": use_case})
def delete_all(self):
collection = self._database[self._schema_collection]
......
#global imports
from db.entities.schema import Schema
from db.entities.layer_adapter import LayerAdapter
from db.schema_repository import SchemaRepository
from db.use_case_repository import UseCaseRepository
......@@ -13,6 +14,22 @@ schema_repository = SchemaRepository()
def 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):
use_case_repository.put(use_case)
schema = schema_repository.get_for_use_case(use_case)
......@@ -23,11 +40,6 @@ def get_for_use_case(use_case:str):
return Response(status=404, response=f"Schema {use_case} does not exist")
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)
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