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,23 +131,21 @@ def add_by_schema(): ...@@ -131,23 +131,21 @@ 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:
print(f"Response: {response.status_code}") print(f"Response: {response.status_code}")
else: else:
print(f"Response: {response.status_code}: {response.text}") print(f"Response: {response.status_code}: {response.text}")
if __name__ == "__main__": if __name__ == "__main__":
add_by_schema() add_by_schema()
add_by_layers() add_by_layers()
\ No newline at end of file
paths:
/use-cases:
get:
security:
- JwtRegular: []
operationId: "routes.use_case.all"
tags:
- "Use-Cases"
summary: "Retrieves all Use-Cases"
description: "Retrieves all Use-Cases"
responses:
'200':
description: "Successful Request"
delete:
security:
- JwtAdmin: []
operationId: "routes.use_case.delete_all"
tags:
- "Use-Cases"
summary: "Delete all Use-Cases"
description: "Delete all Use-Cases"
responses:
'200':
description: "Successful Request"
/schemas:
get:
security:
- JwtRegular: []
operationId: "routes.schema.all"
tags:
- "Schemas"
summary: "Get all Use-Cases"
description: "Get all Use-Cases"
responses:
'200':
description: "Successful Request"
/use-cases/{use_case}/schema:
post:
security:
- JwtRegular: []
operationId: "routes.schema.add_complete"
tags:
- "Schemas"
summary: "Add a new schema with mappings to the DB"
description: "Add a new schema with mappings to the DB"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Schema belongs to"
required: true
type: "string"
- name: "Object"
in: "body"
required: true
schema:
type: "object"
properties:
mappings:
type: array
items:
type: object
additionalProperties:
type: string
example:
name: name
dough: dough//type
responses:
'200':
description: "Successful Request"
'400':
description: "Schema already exists or missing field in request"
get:
security:
- JwtRegular: []
operationId: "routes.schema.get_for_use_case"
tags:
- "Schemas"
summary: "Get the Schema assigned to the Use-Case"
description: "Get the Schema assigned to the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Schema belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Schema does not exist"
delete:
security:
- JwtAdmin: []
operationId: "routes.schema.delete_for_use_case"
tags:
- "Schemas"
summary: "Delete the Schema assigned to the Use-Case"
description: "Delete the Schema assigned to the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Schema belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
/use-cases/{use_case}/schema/mapping:
put:
security:
- JwtRegular: []
operationId: "routes.schema.add_mapping"
tags:
- "Schemas"
summary: "Adds an attribute mapping to the Schema of the Use-Case"
description: "Adds an attribute mapping to the each Layer of the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Schema belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/Mapping'
responses:
'200':
description: "Successful Request"
/layers:
get:
security:
- JwtRegular: []
operationId: "routes.layer.all"
tags:
- "Layers"
summary: "Retrieve all Layers from the DB"
description: "Retrieve all Layers from the DB"
responses:
'200':
description: "Successful Request"
delete:
security:
- JwtAdmin: []
operationId: "routes.layer.delete_all_layers"
tags:
- "Layers"
summary: "Delete all Layers from the DB"
description: "Delete all Layers from the DB"
responses:
'200':
description: "Successful Request"
post:
security:
- JwtRegular: []
operationId: "routes.layer.add_complete"
tags:
- "Layers"
summary: "Adds a complete Layer (including its properties) to the DB"
description: "Adds a complete Layer (including its properties) to the DB"
parameters:
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/Layer'
responses:
'200':
description: "Successful Request"
'400':
description: "Bad structure in request body or Layer already exists"
/use-cases/{use_case}/layers:
get:
security:
- JwtRegular: []
operationId: "routes.layer.get_all_for_use_case"
tags:
- "Layers"
summary: "Retrieves all layers belonging to the given Use-Case"
description: "Retrieves all layers belonging to the given Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Use-Case does not exist"
/use-cases/{use_case}/layers/{name}:
get:
security:
- JwtRegular: []
operationId: "routes.layer.one"
tags:
- "Layers"
summary: "Retrieve one Layer from the DB"
description: "Retrieve one Layer from the DB"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the Layer"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
post:
security:
- JwtRegular: []
operationId: "routes.layer.add_empty"
tags:
- "Layers"
summary: "Adds an empty Layer to the DB"
description: "Adds an empty Layer to the DB"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the new Layer"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'400':
description: "Layer already exists"
delete:
security:
- JwtRegular: []
operationId: "routes.layer.delete_one"
tags:
- "Layers"
summary: "Delete one Layer from the DB"
description: "Delete one Layer from the DB"
parameters:
- name: "name"
in: "path"
description: "Name of the layer to delete"
required: true
type: "string"
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
/use-cases/{use_case}/cluster-mapping/layers/{name}:
put:
security:
- JwtRegular: []
operationId: "routes.layer.add_cluster_mapping"
tags:
- "Layers"
summary: "Selects a property of the Layer as cluster property"
description: "Selects a property of the Layer as cluster property"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the layer (must exist)"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
attribute:
type: string
example: "end_time"
description: "Internal name of the attribute"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing or attribute does not exist in the Layer"
delete:
security:
- JwtRegular: []
operationId: "routes.layer.delete_cluster_mapping"
tags:
- "Layers"
summary: "Deletes a cluster-attribute mapping from the selected layer"
description: "Deletes a cluster-attribute mapping from the selected layer"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the layer (must exist)"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
attribute:
type: string
example: "end_time"
description: "Internal name of the attribute"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing or attribute does not exist in the Layer"
/use-cases/{use_case}/layers/mapping:
put:
security:
- JwtRegular: []
operationId: "routes.layer.add_mapping_for_all"
tags:
- "Layers"
summary: "Adds an attribute mapping to the each Layer of the Use-Case"
description: "Adds an attribute mapping to the each Layer of the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
delete:
security:
- JwtAdmin: []
operationId: "routes.layer.delete_mapping_for_all"
tags:
- "Layers"
summary: "Deletes an attribute mapping for all Layers of the Use-Case"
description: "Deletes an attribute mapping for all Layers of the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
/use-cases/{use_case}/layers/{name}/mapping:
put:
security:
- JwtRegular: []
operationId: "routes.layer.add_mapping"
tags:
- "Layers"
summary: "Adds an attribute mapping to the selected Layer"
description: "Adds an attribute mapping to the selected Layer"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the Layer (must exist)"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing"
delete:
security:
- JwtAdmin: []
operationId: "routes.layer.delete_mapping"
tags:
- "Layers"
summary: "Deletes an attribute mapping from the selected Layer"
description: "Deletes an attribute mapping from the selected Layer"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the Layer (must exist)"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing"
definitions:
LayerMapping:
type: "object"
required:
- internal
properties:
internal:
type: string
example: "end_time"
Mapping:
type: "object"
required:
- internal
- external
properties:
internal:
type: string
example: "end_time"
external:
type: string
example: "arrival_unix_timestamp_utc"
Layer:
type: "object"
required:
- name
- use_case
- cluster_properties
- properties
properties:
name:
type: string
example: "layer1"
use_case:
type: string
example: "car-sharing"
cluster_properties:
type: array
items:
type: string
example: "internal_property_1"
properties:
type: array
items:
type: string
example: "internal_property_1"
\ No newline at end of file
...@@ -4,10 +4,6 @@ info: ...@@ -4,10 +4,6 @@ info:
description: This is the documentation for the business logic microservice. description: This is the documentation for the business logic microservice.
version: "1.0.0" version: "1.0.0"
# Import security definitions from seperate file
securityDefinitions:
$ref: '../security/security.yml#securityDefinitions'
consumes: consumes:
- "application/json" - "application/json"
produces: produces:
...@@ -15,469 +11,9 @@ produces: ...@@ -15,469 +11,9 @@ produces:
basePath: "/api" basePath: "/api"
paths: # Import security definitions from seperate file
/use-cases: securityDefinitions:
get: $ref: '../security/security.yml#securityDefinitions'
security:
- JwtRegular: []
operationId: "routes.use_case.all"
tags:
- "Use-Cases"
summary: "Retrieves all Use-Cases"
description: "Retrieves all Use-Cases"
responses:
'200':
description: "Successful Request"
delete:
operationId: "routes.use_case.delete_all"
tags:
- "Use-Cases"
summary: "Delete all Use-Cases"
description: "Delete all Use-Cases"
responses:
'200':
description: "Successful Request"
/schemas:
get:
security:
- JwtRegular: []
operationId: "routes.schema.all"
tags:
- "Schemas"
summary: "Get all Use-Cases"
description: "Get all Use-Cases"
responses:
'200':
description: "Successful Request"
/use-cases/{use_case}/schema:
get:
security:
- JwtRegular: []
operationId: "routes.schema.get_for_use_case"
tags:
- "Schemas"
summary: "Get the Schema assigned to the Use-Case"
description: "Get the Schema assigned to the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Schema belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Schema does not exist"
delete:
security:
- JwtRegular: []
operationId: "routes.schema.delete_for_use_case"
tags:
- "Schemas"
summary: "Delete the Schema assigned to the Use-Case"
description: "Delete the Schema assigned to the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Schema belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Schema does not exist"
/use-cases/{use_case}/schema/mapping:
put:
security:
- JwtRegular: []
operationId: "routes.schema.add_mapping"
tags:
- "Schemas"
summary: "Adds an attribute mapping to the Schema of the Use-Case"
description: "Adds an attribute mapping to the each Layer of the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Schema belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/Mapping'
responses:
'200':
description: "Successful Request"
/layers:
get:
security:
- JwtRegular: []
operationId: "routes.layer.all"
tags:
- "Layers"
summary: "Retrieve all Layers from the DB"
description: "Retrieve all Layers from the DB"
responses:
'200':
description: "Successful Request"
delete:
security:
- JwtRegular: []
operationId: "routes.layer.delete_all_layers"
tags:
- "Layers"
summary: "Delete all Layers from the DB"
description: "Delete all Layers from the DB"
responses:
'200':
description: "Successful Request"
post:
security:
- JwtRegular: []
operationId: "routes.layer.add_complete"
tags:
- "Layers"
summary: "Adds a complete Layer (including its properties) to the DB"
description: "Adds a complete Layer (including its properties) to the DB"
parameters:
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/Layer'
responses:
'200':
description: "Successful Request"
'400':
description: "Bad structure in request body or Layer already exists"
/use-cases/{use_case}/layers:
get:
security:
- JwtRegular: []
operationId: "routes.layer.get_all_for_use_case"
tags:
- "Layers"
summary: "Retrieves all layers belonging to the given Use-Case"
description: "Retrieves all layers belonging to the given Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Use-Case does not exist"
/use-cases/{use_case}/layers/{name}:
get:
security:
- JwtRegular: []
operationId: "routes.layer.one"
tags:
- "Layers"
summary: "Retrieve one Layer from the DB"
description: "Retrieve one Layer from the DB"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the Layer"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
post:
security:
- JwtRegular: []
operationId: "routes.layer.add_empty"
tags:
- "Layers"
summary: "Adds an empty Layer to the DB"
description: "Adds an empty Layer to the DB"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the new Layer"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'400':
description: "Layer already exists"
delete:
security:
- JwtRegular: []
operationId: "routes.layer.delete_one"
tags:
- "Layers"
summary: "Delete one Layer from the DB"
description: "Delete one Layer from the DB"
parameters:
- name: "name"
in: "path"
description: "Name of the layer to delete"
required: true
type: "string"
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
/use-cases/{use_case}/cluster-mapping/layers/{name}:
put:
security:
- JwtRegular: []
operationId: "routes.layer.add_cluster_mapping"
tags:
- "Layers"
summary: "Selects a property of the Layer as cluster property"
description: "Selects a property of the Layer as cluster property"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the layer (must exist)"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
attribute:
type: string
example: "end_time"
description: "Internal name of the attribute"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing or attribute does not exist in the Layer"
delete:
security:
- JwtRegular: []
operationId: "routes.layer.delete_cluster_mapping"
tags:
- "Layers"
summary: "Deletes a cluster-attribute mapping from the selected layer"
description: "Deletes a cluster-attribute mapping from the selected layer"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the layer (must exist)"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
attribute:
type: string
example: "end_time"
description: "Internal name of the attribute"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing or attribute does not exist in the Layer"
/use-cases/{use_case}/layers/mapping:
put:
security:
- JwtRegular: []
operationId: "routes.layer.add_mapping_for_all"
tags:
- "Layers"
summary: "Adds an attribute mapping to the each Layer of the Use-Case"
description: "Adds an attribute mapping to the each Layer of the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
delete:
security:
- JwtRegular: []
operationId: "routes.layer.delete_mapping_for_all"
tags:
- "Layers"
summary: "Deletes an attribute mapping for all Layers of the Use-Case"
description: "Deletes an attribute mapping for all Layers of the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
/use-cases/{use_case}/layers/{name}/mapping:
put:
security:
- JwtRegular: []
operationId: "routes.layer.add_mapping"
tags:
- "Layers"
summary: "Adds an attribute mapping to the selected Layer"
description: "Adds an attribute mapping to the selected Layer"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the Layer (must exist)"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing"
delete:
security:
- JwtRegular: []
operationId: "routes.layer.delete_mapping"
tags:
- "Layers"
summary: "Deletes an attribute mapping from the selected Layer"
description: "Deletes an attribute mapping from the selected Layer"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the Layer (must exist)"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing"
definitions: paths:
LayerMapping: $ref: 'routes.yml#paths'
type: "object" \ No newline at end of file
required:
- internal
properties:
internal:
type: string
example: "end_time"
Mapping:
type: "object"
required:
- internal
- external
properties:
internal:
type: string
example: "end_time"
external:
type: string
example: "arrival_unix_timestamp_utc"
Layer:
type: "object"
required:
- name
- use_case
- cluster_properties
- properties
properties:
name:
type: string
example: "layer1"
use_case:
type: string
example: "car-sharing"
cluster_properties:
type: array
items:
type: string
example: "internal_property_1"
properties:
type: array
items:
type: string
example: "internal_property_1"
\ No newline at end of file
...@@ -11,433 +11,9 @@ produces: ...@@ -11,433 +11,9 @@ produces:
basePath: "/api" basePath: "/api"
paths: # Import security definitions from seperate file
/use-cases: securityDefinitions:
get: $ref: '../../../../modules/security/security_local.yml#securityDefinitions'
operationId: "routes.use_case.all"
tags:
- "Use-Cases"
summary: "Retrieves all Use-Cases"
description: "Retrieves all Use-Cases"
responses:
'200':
description: "Successful Request"
delete:
operationId: "routes.use_case.delete_all"
tags:
- "Use-Cases"
summary: "Delete all Use-Cases"
description: "Delete all Use-Cases"
responses:
'200':
description: "Successful Request"
/schemas:
get:
operationId: "routes.schema.all"
tags:
- "Schemas"
summary: "Get all Use-Cases"
description: "Get all Use-Cases"
responses:
'200':
description: "Successful Request"
/use-cases/{use_case}/schema:
get:
operationId: "routes.schema.get_for_use_case"
tags:
- "Schemas"
summary: "Get the Schema assigned to the Use-Case"
description: "Get the Schema assigned to the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Schema belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Schema does not exist"
delete:
operationId: "routes.schema.delete_for_use_case"
tags:
- "Schemas"
summary: "Delete the Schema assigned to the Use-Case"
description: "Delete the Schema assigned to the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Schema belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Schema does not exist"
/use-cases/{use_case}/schema/mapping:
put:
operationId: "routes.schema.add_mapping"
tags:
- "Schemas"
summary: "Adds an attribute mapping to the Schema of the Use-Case"
description: "Adds an attribute mapping to the each Layer of the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Schema belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/Mapping'
responses:
'200':
description: "Successful Request"
/layers:
get:
operationId: "routes.layer.all"
tags:
- "Layers"
summary: "Retrieve all Layers from the DB"
description: "Retrieve all Layers from the DB"
responses:
'200':
description: "Successful Request"
delete:
operationId: "routes.layer.delete_all_layers"
tags:
- "Layers"
summary: "Delete all Layers from the DB"
description: "Delete all Layers from the DB"
responses:
'200':
description: "Successful Request"
post:
operationId: "routes.layer.add_complete"
tags:
- "Layers"
summary: "Adds a complete Layer (including its properties) to the DB"
description: "Adds a complete Layer (including its properties) to the DB"
parameters:
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/Layer'
responses:
'200':
description: "Successful Request"
'400':
description: "Bad structure in request body or Layer already exists"
/use-cases/{use_case}/layers:
get:
operationId: "routes.layer.get_all_for_use_case"
tags:
- "Layers"
summary: "Retrieves all layers belonging to the given Use-Case"
description: "Retrieves all layers belonging to the given Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Use-Case does not exist"
/use-cases/{use_case}/layers/{name}:
get:
operationId: "routes.layer.one"
tags:
- "Layers"
summary: "Retrieve one Layer from the DB"
description: "Retrieve one Layer from the DB"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the Layer"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
post:
operationId: "routes.layer.add_empty"
tags:
- "Layers"
summary: "Adds an empty Layer to the DB"
description: "Adds an empty Layer to the DB"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the new Layer"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'400':
description: "Layer already exists"
delete:
operationId: "routes.layer.delete_one"
tags:
- "Layers"
summary: "Delete one Layer from the DB"
description: "Delete one Layer from the DB"
parameters:
- name: "name"
in: "path"
description: "Name of the layer to delete"
required: true
type: "string"
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
/use-cases/{use_case}/cluster-mapping/layers/{name}:
put:
operationId: "routes.layer.add_cluster_mapping"
tags:
- "Layers"
summary: "Selects a property of the Layer as cluster property"
description: "Selects a property of the Layer as cluster property"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the layer (must exist)"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
attribute:
type: string
example: "end_time"
description: "Internal name of the attribute"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing or attribute does not exist in the Layer"
delete:
operationId: "routes.layer.delete_cluster_mapping"
tags:
- "Layers"
summary: "Deletes a cluster-attribute mapping from the selected layer"
description: "Deletes a cluster-attribute mapping from the selected layer"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the layer (must exist)"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
attribute:
type: string
example: "end_time"
description: "Internal name of the attribute"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing or attribute does not exist in the Layer"
/use-cases/{use_case}/layers/mapping:
put:
operationId: "routes.layer.add_mapping_for_all"
tags:
- "Layers"
summary: "Adds an attribute mapping to the each Layer of the Use-Case"
description: "Adds an attribute mapping to the each Layer of the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
delete:
operationId: "routes.layer.delete_mapping_for_all"
tags:
- "Layers"
summary: "Deletes an attribute mapping for all Layers of the Use-Case"
description: "Deletes an attribute mapping for all Layers of the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
/use-cases/{use_case}/layers/{name}/mapping:
put:
operationId: "routes.layer.add_mapping"
tags:
- "Layers"
summary: "Adds an attribute mapping to the selected Layer"
description: "Adds an attribute mapping to the selected Layer"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the Layer (must exist)"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing"
delete:
operationId: "routes.layer.delete_mapping"
tags:
- "Layers"
summary: "Deletes an attribute mapping from the selected Layer"
description: "Deletes an attribute mapping from the selected Layer"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the Layer (must exist)"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing"
definitions: paths:
LayerMapping: $ref: 'routes.yml#paths'
type: "object" \ No newline at end of file
required:
- internal
properties:
internal:
type: string
example: "end_time"
Mapping:
type: "object"
required:
- internal
- external
properties:
internal:
type: string
example: "end_time"
external:
type: string
example: "arrival_unix_timestamp_utc"
Layer:
type: "object"
required:
- name
- use_case
- cluster_properties
- properties
properties:
name:
type: string
example: "layer1"
use_case:
type: string
example: "car-sharing"
cluster_properties:
type: array
items:
type: string
example: "internal_property_1"
properties:
type: array
items:
type: string
example: "internal_property_1"
\ No newline at end of file
...@@ -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