Commit 52f460c3 authored by Manuel's avatar Manuel

roleStageDiscovery: added security

used prance to resolve the yaml file (enables file-splitting)

added global security definition to swagger.yml

added token verification stubs

added security jwtRegular to all endpoints
parent 82b4a802
...@@ -4,6 +4,10 @@ info: ...@@ -4,6 +4,10 @@ info:
description: This is the documentation for the role stage discovery microservice. description: This is the documentation for the role stage discovery microservice.
version: "1.0.0" version: "1.0.0"
# Import security definitions from global security definition
securityDefinitions:
$ref: '../../../../modules/security/security.yml#securityDefinitions'
consumes: consumes:
- "application/json" - "application/json"
produces: produces:
...@@ -26,13 +30,15 @@ paths: ...@@ -26,13 +30,15 @@ paths:
schema: schema:
type: object type: object
responses: responses:
200: '200':
description: "Successful echo of request data" description: "Successful echo of request data"
#region Layers #region Layers
/layers: /layers:
post: post:
operationId: "routes.layers.post" operationId: "routes.layers.post"
security:
- JwtRegular: []
tags: tags:
- "Layers" - "Layers"
summary: "Add a new layer [TODO: or overwrite an existing one]" summary: "Add a new layer [TODO: or overwrite an existing one]"
...@@ -44,18 +50,20 @@ paths: ...@@ -44,18 +50,20 @@ paths:
schema: schema:
$ref: "#/definitions/Layer-UpperCase" $ref: "#/definitions/Layer-UpperCase"
responses: responses:
201: '201':
description: "Successful operation" description: "Successful operation"
400: '400':
description: "Invalid input" description: "Invalid input"
get: get:
operationId: "routes.layers.get" operationId: "routes.layers.get"
security:
- JwtRegular: []
tags: tags:
- "Layers" - "Layers"
summary: "Get all layer data" summary: "Get all layer data"
parameters: [] parameters: []
responses: responses:
200: '200':
description: "Successful operation" description: "Successful operation"
schema: schema:
$ref: "#/definitions/LayerCollection" $ref: "#/definitions/LayerCollection"
...@@ -63,6 +71,8 @@ paths: ...@@ -63,6 +71,8 @@ paths:
/layers/{name}: /layers/{name}:
get: get:
operationId: "routes.layers.get_by_name" operationId: "routes.layers.get_by_name"
security:
- JwtRegular: []
tags: tags:
- "Layers" - "Layers"
summary: "Get single layer data" summary: "Get single layer data"
...@@ -73,16 +83,18 @@ paths: ...@@ -73,16 +83,18 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: '200':
description: "Successful operation" description: "Successful operation"
schema: schema:
$ref: "#/definitions/Layer" $ref: "#/definitions/Layer"
404: '404':
description: "Layer not found" description: "Layer not found"
/layers/{name}/nodes: /layers/{name}/nodes:
get: get:
operationId: "routes.layers.get_nodes" operationId: "routes.layers.get_nodes"
security:
- JwtRegular: []
tags: tags:
- "Layers" - "Layers"
summary: "Get all individual nodes for the layer" summary: "Get all individual nodes for the layer"
...@@ -93,14 +105,16 @@ paths: ...@@ -93,14 +105,16 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: '200':
description: "Successful operation" description: "Successful operation"
schema: schema:
$ref: "#/definitions/NodeCollection" $ref: "#/definitions/NodeCollection"
404: '404':
description: "Layer not found" description: "Layer not found"
post: post:
operationId: "routes.layers.post_nodes" operationId: "routes.layers.post_nodes"
security:
- JwtRegular: []
tags: tags:
- "Layers" - "Layers"
summary: "Adds a single or multiple nodes to the layer" summary: "Adds a single or multiple nodes to the layer"
...@@ -117,14 +131,16 @@ paths: ...@@ -117,14 +131,16 @@ paths:
schema: schema:
$ref: "#/definitions/NodeCollection" $ref: "#/definitions/NodeCollection"
responses: responses:
201: '201':
description: "Successful operation" description: "Successful operation"
400: '400':
description: "Invalid input" description: "Invalid input"
/layers/{name}/clusters: /layers/{name}/clusters:
get: get:
operationId: "routes.clustersets.get_by_name" operationId: "routes.clustersets.get_by_name"
security:
- JwtRegular: []
tags: tags:
- "Layers" - "Layers"
summary: "Get all clusters for the layer" summary: "Get all clusters for the layer"
...@@ -135,16 +151,18 @@ paths: ...@@ -135,16 +151,18 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: '200':
description: "Successful operation" description: "Successful operation"
schema: schema:
$ref: "#/definitions/ClusterCollection" $ref: "#/definitions/ClusterCollection"
404: '404':
description: "Layer not found" description: "Layer not found"
/layers/{name}/timeslices: /layers/{name}/timeslices:
get: get:
operationId: "routes.timeslices.get_by_name" operationId: "routes.timeslices.get_by_name"
security:
- JwtRegular: []
tags: tags:
- "Layers" - "Layers"
summary: "Get all timeslices for the layer" summary: "Get all timeslices for the layer"
...@@ -155,11 +173,11 @@ paths: ...@@ -155,11 +173,11 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: '200':
description: "Successful operation" description: "Successful operation"
schema: schema:
$ref: "#/definitions/TimeSliceCollection" $ref: "#/definitions/TimeSliceCollection"
404: '404':
description: "Layer not found" description: "Layer not found"
#endregion #endregion
...@@ -168,12 +186,14 @@ paths: ...@@ -168,12 +186,14 @@ paths:
/rfc/run: /rfc/run:
post: post:
operationId: "routes.functions.run_agi_clustering_and_graph_creation" operationId: "routes.functions.run_agi_clustering_and_graph_creation"
security:
- JwtRegular: []
tags: tags:
- "Remote function calls" - "Remote function calls"
summary: "Insert locations from AGI, create clusters for starting time and location layers, create graphs for the location clusters" summary: "Insert locations from AGI, create clusters for starting time and location layers, create graphs for the location clusters"
parameters: [] parameters: []
responses: responses:
204: '204':
description: "Successful operation" description: "Successful operation"
#endregion #endregion
...@@ -182,12 +202,14 @@ paths: ...@@ -182,12 +202,14 @@ paths:
/connectedClusters: /connectedClusters:
get: get:
operationId: "routes.connClusters.get_conn_clusters" operationId: "routes.connClusters.get_conn_clusters"
security:
- JwtRegular: []
tags: tags:
- "Connected" - "Connected"
summary: "Get connected Clusters data" summary: "Get connected Clusters data"
description: "Returns a dictionary of cluster. The clusters contain the associated connected clusters and connected nodes data." description: "Returns a dictionary of cluster. The clusters contain the associated connected clusters and connected nodes data."
responses: responses:
200: '200':
description: "Successful operation" description: "Successful operation"
schema: schema:
$ref: "#/definitions/ConnectedDict" $ref: "#/definitions/ConnectedDict"
...@@ -195,6 +217,8 @@ paths: ...@@ -195,6 +217,8 @@ paths:
/clusterSimilarity: /clusterSimilarity:
get: get:
operationId: "routes.similarity.get_similarity" operationId: "routes.similarity.get_similarity"
security:
- JwtRegular: []
tags: tags:
- "Similarity" - "Similarity"
summary: "Get data of the similarity between clusters." summary: "Get data of the similarity between clusters."
...@@ -212,7 +236,7 @@ paths: ...@@ -212,7 +236,7 @@ paths:
description: "Data is returned in batches of size 1000. Returns a dictionary where the key is a tuple of cluster_labels (i.e. [0,319]) and the value is the computed similarity between 2 clusters in the tuple, in regard to each layer in the input. \n Note: the tuple clusters have the same layer and the computed similarity is in regard to clusters from OTHER layers." description: "Data is returned in batches of size 1000. Returns a dictionary where the key is a tuple of cluster_labels (i.e. [0,319]) and the value is the computed similarity between 2 clusters in the tuple, in regard to each layer in the input. \n Note: the tuple clusters have the same layer and the computed similarity is in regard to clusters from OTHER layers."
responses: responses:
200: '200':
description: "Successful operation" description: "Successful operation"
schema: schema:
$ref: "#/definitions/ClusterSimilarityArray" $ref: "#/definitions/ClusterSimilarityArray"
...@@ -220,12 +244,14 @@ paths: ...@@ -220,12 +244,14 @@ paths:
/clusterRunArray: /clusterRunArray:
get: get:
operationId: "routes.connRun.get_connected_run" operationId: "routes.connRun.get_connected_run"
security:
- JwtRegular: []
tags: tags:
- "RunId" - "RunId"
summary: "Get RunId" summary: "Get RunId"
description: "Returns the RunId and the associated datetime when a connection of clusters/simillarity of clusters was computed." description: "Returns the RunId and the associated datetime when a connection of clusters/simillarity of clusters was computed."
responses: responses:
200: '200':
description: "Successful operation" description: "Successful operation"
schema: schema:
$ref: "#/definitions/ClusterRunArray" $ref: "#/definitions/ClusterRunArray"
......
...@@ -13,10 +13,13 @@ LOGGER = logging.getLogger(__name__) ...@@ -13,10 +13,13 @@ LOGGER = logging.getLogger(__name__)
############################# #############################
import connexion import connexion
from security import swagger_util
from pathlib import Path
# load swagger config # load swagger config
app = connexion.App(__name__, specification_dir='configs/') app = connexion.App(__name__, specification_dir='configs/')
app.add_api('swagger.yml') app.add_api(swagger_util.get_bundled_specs(Path("configs/swagger.yml")),
resolver = connexion.RestyResolver("cms_rest_api"))
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
def api_root(): def api_root():
......
...@@ -27,6 +27,7 @@ mccabe==0.6.1 ...@@ -27,6 +27,7 @@ mccabe==0.6.1
networkx==2.4 networkx==2.4
numpy==1.18.1 numpy==1.18.1
openapi-spec-validator==0.2.8 openapi-spec-validator==0.2.8
prance==0.19.0
pycodestyle==2.5.0 pycodestyle==2.5.0
pylint==2.4.4 pylint==2.4.4
pymongo==3.10.1 pymongo==3.10.1
......
def verifyTokenRegular(token, required_scopes):
# TODO call restGateway to verify the token
return {}
def verifyTokenAdmin(token, required_scopes):
# TODO call restGateway to verify the token
return {}
from typing import Dict, Any
from pathlib import Path
import prance
def get_bundled_specs(main_file: Path) -> Dict[str, Any]:
'''
parses the given swagger.yml file and resolves dependencies
from that file to enable the possibility to split the
configuration into several files
'''
parser = prance.ResolvingParser(str(main_file.absolute()),
lazy = True, backend = 'openapi-spec-validator')
parser.parse()
return parser.specification
\ No newline at end of file
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