Skip to content

neutvd/ProvTemplateCatalog

 
 

Repository files navigation

THIS IS WORK IN PROGRESS

Please direct enquiries to https://github.com/d0rg0ld

Visit a running instance of this code at https://envriplus-provenance.test.fedcloud.eu/ Do not use Internet Explorer This service uses a self issued certificate

Proof of concept: MongoDB Backend with a Flask API and a vue.js frontend, using flask-jwt-simple for API authorization and Authomatic for user authentication via oauth2 services from existing social media sites.

Basic setup

The basic setup of vue.js follows

https://skyronic.com/blog/vue-project-scratch

Authomatic integration based on

https://authomatic.github.io/authomatic/ Live Demo

Requires MongoDb engine

Required python components:

sudo pip install flask
sudo pip install flask-jwt-simple
sudo pip install flask-API
sudo pip install authomatic
sudo pip install pymongo
sudo pip install python-openid
sudo pip install pyOpenSSL
sudo pip install prov
sudo pip install pydot
sudo pip install requests

Javascript environment:

sudo npm install -g webpack
sudo npm install axios

In "template" directory:

npm install
npm install --save vue

Setup on Ubuntu without Docker containers

Setup on Ubuntu without using docker container.:

  1. Install necessary packages
  2. Set up MongoDB db with name TemplateData and create collection Templates.
  3. In app.py change the os.environ['PROV_TMPL_MONGODB_HOSTPORT'] for connecting to mongodb to the hostname and port where your mongodb server is running with "host:port".
  4. Change ServerName value to your hostname in example_conf_apache2_sites-enabled.conf
  5. Provide social media oauth2 app key and secret for each used site in config.py: Uncomment the lines setting the keys and secrets directly and comment out the lines obtaining the keys and secrets from the environment. For github, the instructions to obtain the key and secret can be found at https://developer.github.com/apps/building-oauth-apps/creating-an-oauth-app/.
  6. Change os.environ['PROV_TMPL_JWT_SECRET'] secret keys in app.py with your own made up secret.
  7. Use webpack to compile build.js from templates/src/main.js put or symlink build.js in static/js/build.js
         cd templates
         npm run build
    
  8. Setup virtualhost in etc/apache2/sites-enabled
  9. Create wsgi file
  10. Mandatory global (eg in apache2.conf) WSGI Setting for JWT to work: WSGIPAssAuthorization On

Setup using Docker

Create a file with the OAuth keys and secrets e.g. oauth-keys.txt:

PROV_TMPL_github_KEY="github-consumer-key"
PROV_TMPL_github_SECRET="github-consumer-secret"
PROV_TMPL_linkedin_KEY="linkedin-consumer-key"
PROV_TMPL_linkedin_SECRET="linkedin-consumer-secret"
PROV_TMPL_google_KEY="google-consumer-key"
PROV_TMPL_google_SECRET="google-consumer-key"

Make sure this file is not committed to the git repository, so keep it above the repository directory.

Create a directory where the MongoDB container will store its data, e.g. /data/prov.

Run the run-container.sh script for a server that can be reached from anywhere under 'myserver.com':

./run-container.sh -d /data/prov -h myserver.com -b myserver.com -a ../oauth-keys.txt

To run the server locally on a workstation you can do:

./run-container.sh -d $HOME/tmp/data/prov -a ../oauth-keys.txt

After that command has spinned up both the MongoDB and prov-template containers the application is available at https://localhost. You will need to allow an exception when your browser gives you a warning about the self signed certificate.

To spin down the containers do docker-compose down in the directory where the docker-compose.yml file is.

The run-container.sh commands creates files in $HOME/secrets and in $HOME/conf.

Setup using Kubernetes

Nothing special needs to be done once you have a running kubernetes cluster with an ingress controller installed. All you need to do is run the run-container.sh command with the -k option:

./run-container.sh -h <k8s-ingress-hostname> -b <k8s-ingress-hostname> -a ../oauth-keys.txt -k

And it should deploy into your cluster. The requirements for the oauth file are the same as for starting the docker containers with docker-compose. You can remove the pod with the command

kubectl -n swirrl delete -f kubernetes/prov-template.yaml
kubectl -n swirrl delete configmap prov-template-conf
kubectl -n swirrl delete configmap prov-template-oauth
kubectl -n swirrl delete configmap server-url-jwt-conf

Expanding templates

Example template(*) (in provn): #TODO: Put our own template here

document
  prefix xml <http://www.w3.org/XML/1998/namespace>
  prefix foaf <http://xmlns.com/foaf/0.1/>
  prefix rdfs <http://www.w3.org/2000/01/rdf-schema#>
  prefix rdf <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
  prefix var <http://openprovenance.org/var#>
  prefix tmpl <http://openprovenance.org/tmpl#>
  prefix vargen <http://openprovenance.org/vargen#>

  bundle vargen:bundleId
    prefix xml <http://www.w3.org/XML/1998/namespace>
    prefix foaf <http://xmlns.com/foaf/0.1/>
    prefix rdfs <http://www.w3.org/2000/01/rdf-schema#>
    prefix rdf <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    prefix var <http://openprovenance.org/var#>
    prefix tmpl <http://openprovenance.org/tmpl#>
    prefix vargen <http://openprovenance.org/vargen#>

    wasAttributedTo(var:quote, var:author)
    entity(var:quote, [prov:value='var:value'])
    entity(var:author, [prov:type='prov:Person', foaf:name='var:name'])
  endBundle
endDocument

Example bindings (in trig): # TODO: Put our own bindings here

@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix tmpl: <http://openprovenance.org/tmpl#> .
@prefix var: <http://openprovenance.org/var#> .
@prefix ex: <http://example.com/#> .

var:author a prov:Entity;
           tmpl:value_0 <http://orcid.org/0000-0002-3494-120X>.
var:name   a prov:Entity;
           tmpl:2dvalue_0_0 "Luc Moreau".
var:quote  a prov:Entity;
           tmpl:value_0 ex:quote1.
var:value  a prov:Entity;
           tmpl:2dvalue_0_0 "A Little Provenance Goes a Long Way".

Python example to expand with GET

import requests
import urllib

host_name = 'ec2-54-229-229-46.eu-west-1.compute.amazonaws.com'
template_id = '5c3dbc4d5a13e60008b76240'
trig_string = """
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix tmpl: <http://openprovenance.org/tmpl#> .
@prefix var: <http://openprovenance.org/var#> .
@prefix ex: <http://example.com/#> .

var:author a prov:Entity;
           tmpl:value_0 <http://orcid.org/0000-0002-3494-120X>.
var:name   a prov:Entity;
           tmpl:2dvalue_0_0 "Luc Moreau".
var:quote  a prov:Entity;
           tmpl:value_0 ex:quote1.
var:value  a prov:Entity;
           tmpl:2dvalue_0_0 "A Little Provenance Goes a Long Way".
"""
url_encoded_trig_string = urllib.urlencode({"bindings": trig_string})
r = requests.get('https://' + host_name + '/templates/' + template_id +
    '/expand?fmt=provjson&writeprov=false&bindver=v2&' + url_encoded_trig_string,
    verify=False)

print r.text

Python example to expand with POST

import requests

host_name = 'ec2-54-229-229-46.eu-west-1.compute.amazonaws.com'
template_id = '5c3dbc4d5a13e60008b76240'
trig_string = """
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix tmpl: <http://openprovenance.org/tmpl#> .
@prefix var: <http://openprovenance.org/var#> .
@prefix ex: <http://example.com/#> .

var:author a prov:Entity;
           tmpl:value_0 <http://orcid.org/0000-0002-3494-120X>.
var:name   a prov:Entity;
           tmpl:2dvalue_0_0 "Luc Moreau".
var:quote  a prov:Entity;
           tmpl:value_0 ex:quote1.
var:value  a prov:Entity;
           tmpl:2dvalue_0_0 "A Little Provenance Goes a Long Way".
"""

r = requests.post('https://' + host_name + '/templates/' + template_id +
    '/expand?fmt=provjson&writeprov=false&bindver=v2',
        data=trig_string, verify=False)

print r.text

(*) Example taken from Luc Moreau's ProvToolbox tutorial at https://lucmoreau.wordpress.com/2015/07/30/provtoolbox-tutorial-4-templates-for-provenance-part-1/

About

Proof-of-concept catalog for PROV-templates

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • CSS 80.4%
  • Python 7.1%
  • JavaScript 5.7%
  • HTML 4.5%
  • Shell 1.4%
  • Dockerfile 0.8%
  • Vue 0.1%