Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tilt #28

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ WORKDIR /mood
# Copies project requirements into working directory
COPY package*.json ./

# Copies requirements.txt into working directory
COPY ./requirements.txt /mood/requirements.txt

# install python and pip
RUN apk add --no-cache python3 py3-pip

# Install requirements
RUN pip install --no-cache-dir --upgrade -r /mood/requirements.txt

# Copy app code
COPY ./app ./app

Expand Down
9 changes: 9 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ ENV NODE_ENV production
# Copies project requirements into working directory
COPY package*.json ./

# Copies requirements.txt into working directory
COPY ./requirements.txt /mood/requirements.txt

# install python and pip
RUN apk add --no-cache python3 py3-pip

# Install requirements
RUN pip install --no-cache-dir --upgrade -r /mood/requirements.txt

# Install dependencies
RUN npm ci

Expand Down
31 changes: 23 additions & 8 deletions app/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import authMiddleware from '../middleware/auth';
import validateError from '../middleware/validationError';
import { notFoundError, serverError } from '../middleware/defaultError';
import { usingPipe } from '../utils';
import { spawn } from 'child_process';


const applyMiddlewares = (app) => {
app.use(authMiddleware);
Expand Down Expand Up @@ -87,15 +89,28 @@ const defineRoutes = (app) => {
}).catch(next);
});

// TODO add tilt routes
// app.get('/tilt/', (req, res) => {
// // TODO
// });
// // TODO add endpoint for motivator service, motivator calls mood diary return
// app.get('/motivator/', (req, res) => {
// Get Tilt schema for mood diary
app.get('/tilt', (req, res) => {
var process = spawn('python3', ['app/tilt/mood_tilt.py']);
var tilt_data = [];

process.stdout.on('data', function (data) {
tilt_data.push(data);
});

process.stderr.on('data', data => {
console.error(`stderr: ${data}`);
})

process.on('close', (code) => {
console.log(`child process close all stdio with code ${code}`);
// send tilt schema
res.send(tilt_data.join(""));
});

});


// // TODO
// });
};

export default (app) => {
Expand Down
63 changes: 63 additions & 0 deletions app/tilt/mood_tilt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"dataDisclosed": [
{
"_id": "mood-service-tilt-01",
"category": "Language Preference",
"legalBases": [
{
"description": "General Data Protection Regulation (GDPR) Art.",
"reference": "GDPR-99-1-a"
},
{
"description": "BDSG-42-5 refers to the processing of personal data within..",
"reference": "BDSG-42-5"
}
],
"legitimateInterests": [
{
"exists": false,
"reasoning": "No legitimate interests"
}
],
"nonDisclosure": {
"consequences": "If the data is not disclosed, the shipment cannot be delivered.",
"contractualRegulation": false,
"legalRequirement": false,
"obligationToProvide": false
},
"purposes": [
{
"description": "To provide the mood-service-tilt",
"purpose": "To provide the mood-service-tilt"
}
],
"recipients": [
{
"address": "",
"category": "",
"country": "DE",
"division": "",
"name": "",
"representative": null
}
],
"storage": [
{
"aggregationFunction": "min",
"legalBasisConditional": [
"SGB-100-42"
],
"purposeConditional": [
"Data is always stored"
],
"temporal": [
{
"description": "Temporal element for the mood-service-tilt",
"ttl": ""
}
]
}
]
}
]
}
85 changes: 85 additions & 0 deletions app/tilt/mood_tilt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from tilt import tilt
import fastjsonschema
import json
import requests

# List of legal_bases with reference and description
first_legal_base = tilt.AnyOfSchemaForTheLegalBasesOfTheDataDisclosed(
reference="GDPR-99-1-a",
description="General Data Protection Regulation (GDPR) Art."
)
second_legal_base = tilt.AnyOfSchemaForTheLegalBasesOfTheDataDisclosed(
reference="BDSG-42-5",
description="BDSG-42-5 refers to the processing of personal data within.."
)

# Store the mood-service-tilt
temporal = tilt.TemporalElement(
description='Temporal element for the mood-service-tilt',
ttl=''
)
storage = tilt.StorageElement(
temporal=[temporal],
purpose_conditional=["Data is always stored"],
legal_basis_conditional=["SGB-100-42"],
aggregation_function=tilt.AggregationFunction.MIN
)

legitimate_interests = tilt.AnyOfSchemaForLegitimateInterests(
exists=False,
reasoning="No legitimate interests"
)

non_disclosure = tilt.NonDisclosure(
legal_requirement=False,
contractual_regulation=False,
obligation_to_provide=False,
consequences="If the data is not disclosed, the shipment cannot be delivered."
)

purposes = tilt.AnyOfSchemaForThePurposes(
purpose="To provide the mood-service-tilt",
description="To provide the mood-service-tilt"
)

first_recipient = tilt.Recipient(
name="",
address="",
category="",
country="DE",
division="",
representative=None
)

# Data disclosed to mood-service-tilt
disclosed_data = tilt.DataDisclosedElement(
id='mood-service-tilt-01',
category="Language Preference",
legal_bases=[first_legal_base, second_legal_base],
storage=[storage],
legitimate_interests=[legitimate_interests],
non_disclosure=non_disclosure,
purposes=[purposes],
recipients=[first_recipient]
)

tilt_dict = {}

tilt_dict['dataDisclosed'] = [disclosed_data.to_dict()]

print(json.dumps(tilt_dict, indent = 4))
# Add validator to check the tilt_dict
# Load schema to validate against
file = requests.get('https://raw.githubusercontent.com/Transparency-Information-Language/schema/master/tilt-schema.json')
schema = json.loads(file.content)

# As we don't use the full TILT spec, we only need the 'dataDisclosed' schema from the file
examples_schema = schema['examples']
dataDisclosed_schema = examples_schema[0]['dataDisclosed']
# Compile schema
validate_func = fastjsonschema.compile(dataDisclosed_schema[0])

# Validate instance against schema
validate_func(tilt_dict)

#print(json.dumps(tilt_dict, indent = 4))
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tilt==0.0.5
jsonschema==4.5.1
requests==2.28.1
fastjsonschema==2.15.3