Commit 826c3dbd authored by Manuel's avatar Manuel

[reputation-calculation] added skeleton for microservice

parent 3966f9e5
paths:
#####
# Trust Adapters
#####
/use-cases/{use_case}/contexts/{context}/trust-adapters:
get:
operationId: "routes.trust_adapter.all_for_use_case"
tags:
- "Trust Adapter"
summary: "Get all trust adapters for a use case"
description: "Get all trust adapters for a use case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Trust-Adapter belongs to"
required: true
type: "string"
- name: "context"
in: "path"
description: "Name of the Context the Trust-Adapter belongs to"
required: true
type: "string"
responses:
"200":
description: "OK"
"404":
description: "Use-Case or Context was not found"
post:
operationId: "routes.trust_adapter.add"
tags:
- "Trust Adapter"
summary: "Add a new trust adapters to a use case/context"
description: "Add a new trust adapters to a use case/context"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Trust-Adapter belongs to"
required: true
type: "string"
- name: "context"
in: "path"
description: "Name of the Context the Trust-Adapter belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/TrustAdapter'
responses:
"200":
description: "OK"
"404":
description: "Use-Case or Context was not found"
#####
# Contexts
#####
/use-cases/{use_case}/contexts:
get:
operationId: "routes.context.all_for_use_case"
tags:
- "Context"
summary: "Get all contexts for a use case"
description: "Get all contexts for a use case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Contexts belongs to"
required: true
type: "string"
responses:
"200":
description: "OK"
"404":
description: "Use-Case was not found"
post:
operationId: "routes.context.add"
tags:
- "Context"
summary: "Adds a new context to the system"
description: "Adds a new context to the system"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Contexts belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/Context'
responses:
"200":
description: "Context was successfully added"
/debug:
post:
operationId: "debug.echo"
tags:
- "Echo"
summary: "Echo function for debugging purposes"
description: "Echoes the input back to the caller."
parameters:
- in: body
name: "Object"
required: true
schema:
type: object
responses:
"200":
description: "Successful echo of request data"
definitions:
Context:
type: "object"
required:
- use_case
- name
properties:
use_case:
type: string
example: "car-sharing"
name:
type: string
example: "context1"
TrustAdapter:
type: "object"
required:
- use_case
- context
- user_source
- volume_source
- conversion
- certainty
- cutoff
- bias_positive
- bias_negative
properties:
use_case:
type: string
example: "car-sharing"
context:
type: string
example: "context1"
user_source:
type: string
example: "user//id"
volume_source:
type: string
example: "trip//price"
conversion:
type: number
format: float
example: 100.50
certainty:
type: number
format: float
minimum: 0
maximum: 1
example: 0.75
cutoff:
type: number
format: float
example: 8.0
bias_negative:
type: number
format: float
example: 1
bias_positive:
type: number
format: float
example: 1
TrustTrace:
type: "object"
required:
- use_case
- context
- user
- volume
- trust
properties:
use_case:
type: string
example: "car-sharing"
context:
type: string
example: "context1"
user:
type: string
example: "bob"
volume:
type: number
format: float
example: 12.1524
trust:
type: number
format: float
minimum: -1
maximum: 1
\ No newline at end of file
...@@ -11,20 +11,9 @@ produces: ...@@ -11,20 +11,9 @@ produces:
basePath: "/api" basePath: "/api"
# Import security definitions from seperate file
securityDefinitions:
$ref: '../security/security.yml#securityDefinitions'
paths: paths:
/debug: $ref: 'routes.yml#paths'
post: \ No newline at end of file
operationId: "debug.echo"
tags:
- "Echo"
summary: "Echo function for debugging purposes"
description: "Echoes the input back to the caller."
parameters:
- in: body
name: "Object"
required: true
schema:
type: object
responses:
200:
description: "Successful echo of request data"
swagger: "2.0"
info:
title: Reputation Calculation microservice
description: This is the documentation for the reputation calculation microservice.
version: "1.0.0"
consumes:
- "application/json"
produces:
- "application/json"
basePath: "/api"
# Import security definitions from seperate file
securityDefinitions:
$ref: '../../../../modules/security/security_local.yml#securityDefinitions'
paths:
$ref: 'routes.yml#paths'
\ No newline at end of file
from typing import Dict
class Context:
def __init__(self, use_case:str, name:str):
self.use_case = use_case
self.name = name
def to_serializable_dict(self):
return {
"use_case": self.use_case,
"name": self.name
}
@staticmethod
def from_serializable_dict(data: Dict):
return Context(data["use_case"], data["context"])
\ No newline at end of file
from typing import Dict
class Context:
def __init__(self, use_case: str, context: str, user_source: str, volume_source: str,
conversion: float, certainty: float, cutoff: float, bias_negative: float, bias_positive: float):
self.use_case = use_case
self.context = context
self.user_source = user_source
self.volume_source = volume_source
self.conversion = conversion
self.certainty = certainty
self.cutoff = cutoff
self.bias_negative = bias_negative
self.bias_positive = bias_positive
def to_serializable_dict(self):
return {
"use_case": self.use_case,
"context": self.context,
"user_source": self.user_source,
"volume_source": self.volume_source,
"conversion": self.conversion,
"certainty": self.certainty,
"cutoff": self.cutoff,
"bias_negative": self.bias_negative,
"bias_positive": self.bias_positive
}
@staticmethod
def from_serializable_dict(data: Dict):
return Context(
data["use_case"],
data["context"],
data["user_source"],
data["volume_source"],
data["conversion"],
data["certainty"],
data["cutoff"],
data["bias_negative"],
data["bias_positive"],
)
# add modules folder to interpreter path
import sys
import os
from pathlib import Path
modules_path = '../../../modules/'
if os.path.exists(modules_path):
sys.path.insert(1, modules_path)
# init logging to file
import logging
LOG_FORMAT = ('%(levelname) -5s %(asctime)s %(name)s:%(funcName) -35s %(lineno) -5d: %(message)s')
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
LOGGER = logging.getLogger(__name__)
#############################
import connexion import connexion
from security import swagger_util
from env_info import is_running_locally, get_resources_path
from flask import request
from flask import redirect
from flask_cors import CORS
# 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') CORS(app.app)
@app.app.before_request
def before_request():
if request.url.startswith('http://'):
url = request.url.replace('http://', 'https://', 1)
code = 301
return redirect(url, code=code)
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
def api_root(): def api_root():
return 'Endpoint of reputation-calculation-microservice!' return redirect('/api/ui')
# SSL configuration
certificate_path = get_resources_path()
context = (os.path.normpath(f'{certificate_path}/articonf1.crt'), os.path.normpath(f'{certificate_path}/articonf1.key')) # certificate and key files
if is_running_locally():
print("Running locally...")
app.add_api(swagger_util.get_bundled_specs(Path("configs/swagger_local.yml")),
resolver = connexion.RestyResolver("cms_rest_api"))
else:
app.add_api(swagger_util.get_bundled_specs(Path("configs/swagger.yml")),
resolver = connexion.RestyResolver("cms_rest_api"))
# start app # start app
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True) app.run(host='0.0.0.0', port=5000, debug=True, use_reloader=False, ssl_context=context) # disable reloader so only subscribed once to rabbitmq
def add(use_case: str):
return "nice"
def all_for_use_case(use_case: str):
return f"uc: {use_case}"
def add(use_case: str, context: str):
return "nice"
def all_for_use_case(use_case: str, context: str):
return f"uc: {use_case}"
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