Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
826c3dbd
Commit
826c3dbd
authored
Jun 24, 2021
by
Manuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[reputation-calculation] added skeleton for microservice
parent
3966f9e5
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
340 additions
and
20 deletions
+340
-20
routes.yml
...eputation-calculation-microservice/app/configs/routes.yml
+203
-0
swagger.yml
...putation-calculation-microservice/app/configs/swagger.yml
+5
-16
swagger_local.yml
...on-calculation-microservice/app/configs/swagger_local.yml
+19
-0
context.py
...calculation-microservice/app/database/entities/context.py
+16
-0
trust_adapter.py
...ation-microservice/app/database/entities/trust_adapter.py
+42
-0
main.py
src/data-hub/reputation-calculation-microservice/app/main.py
+45
-4
context.py
...reputation-calculation-microservice/app/routes/context.py
+5
-0
trust_adapter.py
...tion-calculation-microservice/app/routes/trust_adapter.py
+5
-0
No files found.
src/data-hub/reputation-calculation-microservice/app/configs/routes.yml
0 → 100644
View file @
826c3dbd
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
src/data-hub/reputation-calculation-microservice/app/configs/swagger.yml
View file @
826c3dbd
...
@@ -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"
src/data-hub/reputation-calculation-microservice/app/configs/swagger_local.yml
0 → 100644
View file @
826c3dbd
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
src/data-hub/reputation-calculation-microservice/app/database/entities/context.py
0 → 100644
View file @
826c3dbd
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
src/data-hub/reputation-calculation-microservice/app/database/entities/trust_adapter.py
0 → 100644
View file @
826c3dbd
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"
],
)
src/data-hub/reputation-calculation-microservice/app/main.py
View file @
826c3dbd
# 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) -5
s
%(asctime)
s
%(name)
s:
%(funcName) -35
s
%(lineno) -5
d:
%(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
src/data-hub/reputation-calculation-microservice/app/routes/context.py
0 → 100644
View file @
826c3dbd
def
add
(
use_case
:
str
):
return
"nice"
def
all_for_use_case
(
use_case
:
str
):
return
f
"uc: {use_case}"
src/data-hub/reputation-calculation-microservice/app/routes/trust_adapter.py
0 → 100644
View file @
826c3dbd
def
add
(
use_case
:
str
,
context
:
str
):
return
"nice"
def
all_for_use_case
(
use_case
:
str
,
context
:
str
):
return
f
"uc: {use_case}"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment