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

698 ldp patch import resource one by one #987

Merged
merged 62 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
df1b1f4
creating Mirror graph, protecting LDP actions against Mirror data
nikoPLP Jan 9, 2022
5a37663
fixing bug with root container not having his children as sub container
nikoPLP Jan 9, 2022
9e0daac
working void service for localData, need to test for mirror data
nikoPLP Jan 10, 2022
9907f66
creating Mirror graph, protecting LDP actions against Mirror data
nikoPLP Jan 9, 2022
776255c
Merge branch '849_mirror_service' of ssh://github.com/assemblee-virtu…
nikoPLP Jan 10, 2022
6627e10
first version of mirror service, brutaly mirrors everything everytime…
nikoPLP Jan 11, 2022
63471b2
starting the registry service asynchroniously again, so it can play w…
nikoPLP Jan 17, 2022
b81cb13
working void service for localData, need to test for mirror data
nikoPLP Jan 10, 2022
8de986a
creating Mirror graph, protecting LDP actions against Mirror data
nikoPLP Jan 9, 2022
c734b4a
first version of mirror service, brutaly mirrors everything everytime…
nikoPLP Jan 11, 2022
2f9819c
starting the registry service asynchroniously again, so it can play w…
nikoPLP Jan 17, 2022
97dafaf
Merge branch '849_mirror_service' of ssh://github.com/assemblee-virtu…
nikoPLP May 28, 2022
b3108d9
allowing multiple void#class in each partition
nikoPLP May 29, 2022
d913f9c
logging fdone properly at Mirror service startup. errors do not crash…
nikoPLP May 29, 2022
4269ba1
ldp.mirror service become independant mirror service. automatic creat…
nikoPLP May 31, 2022
3d32d03
FOLLOW of the relay actor once the mirror is done
nikoPLP Jun 1, 2022
3538c50
updateBot working well for create, update, delete. permission changes…
nikoPLP Jun 2, 2022
de26b7d
fix bug race condition on OIDC issuer retrieval
nikoPLP Jun 3, 2022
2e2ad02
ldp.container.isEmpty action
nikoPLP Jun 3, 2022
585b489
fixing the bug of first level containers not attached to root container
nikoPLP Jun 3, 2022
4f86bbf
UpdateBot: changing permissions sends activities to followers. it works
nikoPLP Jun 3, 2022
ab92036
docker service for migration + initial documentation
nikoPLP Jun 4, 2022
d574741
prettier
nikoPLP Jun 4, 2022
3f98975
working void service for localData, need to test for mirror data
nikoPLP Jan 10, 2022
872a7f6
creating Mirror graph, protecting LDP actions against Mirror data
nikoPLP Jan 9, 2022
f2647fa
first version of mirror service, brutaly mirrors everything everytime…
nikoPLP Jan 11, 2022
2970094
starting the registry service asynchroniously again, so it can play w…
nikoPLP Jan 17, 2022
99e4363
allowing multiple void#class in each partition
nikoPLP May 29, 2022
93690b2
logging fdone properly at Mirror service startup. errors do not crash…
nikoPLP May 29, 2022
2046418
ldp.mirror service become independant mirror service. automatic creat…
nikoPLP May 31, 2022
97d8596
FOLLOW of the relay actor once the mirror is done
nikoPLP Jun 1, 2022
2914013
updateBot working well for create, update, delete. permission changes…
nikoPLP Jun 2, 2022
52e506b
fix bug race condition on OIDC issuer retrieval
nikoPLP Jun 3, 2022
109f894
ldp.container.isEmpty action
nikoPLP Jun 3, 2022
8e7ef64
fixing the bug of first level containers not attached to root container
nikoPLP Jun 3, 2022
d6f8950
UpdateBot: changing permissions sends activities to followers. it works
nikoPLP Jun 3, 2022
4308567
docker service for migration + initial documentation
nikoPLP Jun 4, 2022
7bb4ac5
prettier
nikoPLP Jun 4, 2022
c04d38e
merge
nikoPLP Jun 4, 2022
6029cbc
Automatic prettier
nikoPLP Jun 4, 2022
733c3fc
prevent chain mirroring
nikoPLP Jun 5, 2022
331ea95
removing details in the 403 status text because it crashes the server…
nikoPLP Jun 5, 2022
dbefed2
Merge branch '849_mirror_service' of ssh://github.com/assemblee-virtu…
nikoPLP Jun 5, 2022
7ba2d78
Automatic prettier
nikoPLP Jun 5, 2022
d010efb
cleanup and more comments inline
nikoPLP Jun 5, 2022
4281239
prettier
nikoPLP Jun 5, 2022
a791775
PATCH action on containers. format is SPARQL-UPDATE
nikoPLP Jun 5, 2022
0a6dcf2
prettier
nikoPLP Jun 5, 2022
b7bab59
cron to refresh every hour the orphan mirrored resources + detach a r…
nikoPLP Jun 5, 2022
a693863
fix iteration on parsed sparql
nikoPLP Jun 5, 2022
311b6b7
Use same SemApps package versions for mirror service
srosset81 Jun 20, 2022
4a3b8bf
fix bug migration
nikoPLP Jun 23, 2022
cf75d68
Merge branch '698_ldp_patch_import_resource_one_by_one' of ssh://gith…
nikoPLP Jun 23, 2022
93dcb39
fixing all comments in merge request
nikoPLP Jun 23, 2022
963b521
prettier
nikoPLP Jun 23, 2022
5524eac
preferred view redirect. fixes #771
nikoPLP Jun 24, 2022
1d49099
prettier
nikoPLP Jun 24, 2022
fe3a72c
doc for preferre view
nikoPLP Jun 24, 2022
4382535
more cosmetic fixes
nikoPLP Jun 27, 2022
483dd5e
Automatic prettier
nikoPLP Jun 27, 2022
06e1958
binding this to preferredViewForResource so user can access broker
nikoPLP Jun 27, 2022
5a51bf5
Add missing predicate in context
srosset81 Jun 27, 2022
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
10 changes: 10 additions & 0 deletions src/jena/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ services:
container_name: fuseki_compact
volumes:
- ./data/rdf_data:/fuseki

fuseki_migrate:
build:
context: fuseki-docker
dockerfile: Dockerfile
entrypoint: /docker-migration-entrypoint.sh
image: semapps/jena-fuseki-webacl
container_name: fuseki_migration
volumes:
- ./data/rdf_data:/fuseki
5 changes: 4 additions & 1 deletion src/jena/fuseki-docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#FROM alpine:3.4
#RUN apk add --update openjdk8-jre pwgen bash wget ca-certificates && rm -rf /var/cache/apk/*
FROM openjdk:8-jre-alpine
RUN apk add --update pwgen bash curl ca-certificates procps && rm -rf /var/cache/apk/*
RUN apk add --update nodejs npm pwgen bash curl ca-certificates procps && rm -rf /var/cache/apk/*

MAINTAINER Niko PLP <[email protected]>

Expand Down Expand Up @@ -82,15 +82,18 @@ RUN chmod 755 $FUSEKI_HOME/bin/tdb2.*
# (which we'll generate on start-up)

COPY shiro.ini /jena-fuseki/
COPY migration /jena-fuseki/migration
COPY extra/commons-collections4-4.4.jar /jena-fuseki/extra/commons-collections4-4.4.jar
COPY extra/jena-permissions-3.17.0.jar /jena-fuseki/extra/jena-permissions-3.17.0.jar
COPY extra/semapps-jena-permissions-1.0.0.jar /jena-fuseki/extra/semapps-jena-permissions-1.0.0.jar
#COPY configuration/localData.ttl /jena-fuseki/configuration/localData.ttl
#COPY configuration/testData.ttl /jena-fuseki/configuration/testData.ttl
COPY docker-entrypoint.sh /
COPY docker-compact-entrypoint.sh /
COPY docker-migration-entrypoint.sh /
RUN chmod 755 /docker-entrypoint.sh
RUN chmod 755 /docker-compact-entrypoint.sh
RUN chmod 755 /docker-migration-entrypoint.sh

COPY load.sh /jena-fuseki/
COPY tdbloader /jena-fuseki/
Expand Down
26 changes: 26 additions & 0 deletions src/jena/fuseki-docker/docker-migration-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

cd /jena-fuseki/migration

npm i

cd /fuseki

node /jena-fuseki/migration/migrate.js > /fuseki/configuration/migration.log

Binary file modified src/jena/fuseki-docker/extra/semapps-jena-permissions-1.0.0.jar
Binary file not shown.
50 changes: 50 additions & 0 deletions src/jena/fuseki-docker/migration/migrate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const fs = require('fs');
const path = require('path');
const format = require('string-template');

const matchAll = require("match-all");

//const folder = path.join(__dirname,'configuration');
const folder = path.join(path.parse(__dirname).root,'fuseki','configuration');

const rdfsLabelRegex = new RegExp('^\\s*rdfs:label\\s*"([\\w\\s]+)"\\s*[;.]\\s*$','gm')
const fusekiNameRegex = new RegExp('^\\s*fuseki:name\\s*"([\\w]+)"\\s*[;.]\\s*$','gm')
const tdb2LocationRegex = new RegExp('^\\s*tdb2:location\\s*"([/\\\\:\\w]+)"\\s*[;.]\\s*$','gm')

let template = fs.readFileSync(path.join(__dirname,'templates','dataset.ttl'), {encoding: 'utf8'} )
let templateAcl = fs.readFileSync(path.join(__dirname,'templates','secure-dataset.ttl'), {encoding: 'utf8'} )


fs.readdirSync(folder).forEach(file => {
if (file.endsWith('.ttl')) {
console.log(file);
const filename = path.join(folder,file)
let content = fs.readFileSync(filename, {encoding: 'utf8'} )
if (!content.includes('mirror')) {
console.log('> migrating...')
fs.writeFileSync(filename+'.bak',content)
// extract names
const rdfsLabel = matchAll(content,rdfsLabelRegex).toArray()[0]
const fusekiName = matchAll(content,fusekiNameRegex).toArray()[0]
console.log('> rdfsLabel = ',rdfsLabel)
console.log('> fusekiName = ',fusekiName)
const locations = matchAll(content,tdb2LocationRegex).toArray();
if (content.includes('webacl')) {
let aclLocation = locations.filter(l => l.includes('acl') || l.includes('Acl'))
aclLocation = aclLocation.length == 1 && aclLocation[0]
if (!aclLocation) { console.log('> error: cannot find acl location'); }
else {
console.log('> aclLocation = ',aclLocation)
const newContent = format(templateAcl, { dataset: fusekiName, aclLocation, rdfsLabel });
fs.writeFileSync(filename,newContent)
}
} else {
const newContent = format(template, { dataset: fusekiName, rdfsLabel });
fs.writeFileSync(filename,newContent)
}

}
else console.log('> already done.')
console.log('')
}
});
39 changes: 39 additions & 0 deletions src/jena/fuseki-docker/migration/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/jena/fuseki-docker/migration/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "migration_mirror",
"version": "0.1.0",
"description": "Migrates the configuration files of jena fuseki for Dataset, to include the mirror namedGraph",
"license": "Apache-2.0",
"author": "Virtual Assembly",
"dependencies": {
"string-template": "^1.0.0",
"match-all": "^1.0.0"
}
}
64 changes: 64 additions & 0 deletions src/jena/fuseki-docker/migration/templates/dataset.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@prefix : <http://base/#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix tdb2: <http://jena.apache.org/2016/tdb#> .
@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix fuseki: <http://jena.apache.org/fuseki#> .

tdb2:DatasetTDB rdfs:subClassOf ja:RDFDataset .

ja:DatasetTxnMem rdfs:subClassOf ja:RDFDataset .

<http://jena.hpl.hp.com/2008/tdb#DatasetTDB>
rdfs:subClassOf ja:RDFDataset .

ja:ViewGraph rdfs:subClassOf ja:Model .

<http://jena.hpl.hp.com/2008/tdb#GraphTDB>
rdfs:subClassOf ja:Model .

tdb2:GraphTDB2 rdfs:subClassOf ja:Model .

ja:MemoryDataset rdfs:subClassOf ja:RDFDataset .

ja:RDFDatasetZero rdfs:subClassOf ja:RDFDataset .

<http://jena.apache.org/text#TextDataset>
rdfs:subClassOf ja:RDFDataset .

:service_tdb_all a fuseki:Service ;
rdfs:label "{rdfsLabel}" ;
fuseki:dataset :combinedDataset ;
fuseki:name "{dataset}" ;
fuseki:serviceQuery "query" , "" , "sparql" ;
fuseki:serviceReadGraphStore "get" ;
fuseki:serviceReadWriteGraphStore
"data" ;
fuseki:serviceUpdate "" , "update" ;
fuseki:serviceUpload "upload" .

:tdb_dataset_readwrite
a tdb2:DatasetTDB2 ;
tdb2:location "/fuseki/databases/{dataset}" .

:baseModel rdf:type tdb2:GraphTDB ;
tdb2:dataset :tdb_dataset_readwrite.

:mirrorModel rdf:type tdb2:GraphTDB ;
tdb2:graphName <http://semapps.org/mirror> ;
tdb2:dataset :tdb_dataset_readwrite.

:combinedDataset rdf:type ja:RDFDataset ;
ja:defaultGraph :baseModel;
ja:namedGraph
[ ja:graphName <http://semapps.org/mirror> ;
ja:graph :mirrorModel ] ;
.

tdb2:GraphTDB rdfs:subClassOf ja:Model .

ja:RDFDatasetOne rdfs:subClassOf ja:RDFDataset .

ja:RDFDatasetSink rdfs:subClassOf ja:RDFDataset .

tdb2:DatasetTDB2 rdfs:subClassOf ja:RDFDataset .
99 changes: 99 additions & 0 deletions src/jena/fuseki-docker/migration/templates/secure-dataset.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0

PREFIX : <#>
PREFIX fuseki: <http://jena.apache.org/fuseki#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX tdb2: <http://jena.apache.org/2016/tdb#>
PREFIX ja: <http://jena.hpl.hp.com/2005/11/Assembler#>
PREFIX sec: <http://apache.org/jena/permissions/Assembler#>
PREFIX sa: <http://semapps.org/#>
## ---------------------------------------------------------------
## Updatable TDB2 dataset with all services enabled.

<#tdb_dataset_readwrite_acl> rdf:type tdb2:DatasetTDB2 ;
tdb2:location "{aclLocation}" ;
##tdb2:unionDefaultGraph true ;
.

<#tdb_dataset_readwrite> rdf:type tdb2:DatasetTDB2 ;
tdb2:location "/fuseki/databases/{dataset}" ;
##tdb2:unionDefaultGraph true ;
.

<#tdb_dataset_readwrite_mirror> rdf:type tdb2:DatasetTDB2 ;
tdb2:location "/fuseki/databases/{dataset}Mirror" ;
.

sa:baseModel rdf:type tdb2:GraphTDB ;
tdb2:dataset <#tdb_dataset_readwrite> .

sa:mirrorModel rdf:type tdb2:GraphTDB ;
tdb2:dataset <#tdb_dataset_readwrite_mirror> .

[] ja:loadClass "org.apache.jena.permissions.SecuredAssembler" .
sec:Model rdfs:subClassOf ja:NamedModel .
sec:evaluator rdfs:domain sec:Model ;
rdfs:range sec:Evaluator .

sa:securedModel rdf:type sec:Model ;
sec:baseModel sa:baseModel ;
ja:modelName "http://semapps.org/securedModel" ;
sec:evaluatorImpl sa:secEvaluator .

sa:unprotectedDataset rdf:type ja:RDFDataset ;
ja:defaultGraph sa:baseModel;
ja:namedGraph
[ ja:graphName <http://semapps.org/webacl> ;
ja:graph sa:baseACLModel ] ;
.

sa:secEvaluator rdf:type sec:Evaluator ;
sec:args [
rdf:_1 sa:baseModel ;
rdf:_2 sa:baseACLModel ;
rdf:_3 sa:unprotectedDataset ;
] ;
sec:evaluatorClass "org.semapps.jena.permissions.ShiroEvaluator" .

sa:baseACLModel rdf:type tdb2:GraphTDB ;
tdb2:graphName <http://semapps.org/webacl> ;
tdb2:dataset <#tdb_dataset_readwrite_acl> .

sa:securedACLModel rdf:type sec:Model ;
sec:baseModel sa:baseACLModel ;
ja:modelName "http://semapps.org/securedWebacl" ;
sec:evaluatorImpl sa:secACLEvaluator .

sa:secACLEvaluator rdf:type sec:Evaluator ;
sec:args [
rdf:_1 sa:baseModel ;
rdf:_2 sa:baseACLModel ;
rdf:_3 sa:unprotectedDataset ;
] ;
sec:evaluatorClass "org.semapps.jena.permissions.ShiroEvaluator" .


sa:securedDataset rdf:type ja:RDFDataset ;
ja:defaultGraph sa:securedModel;
ja:namedGraph
[ ja:graphName <http://semapps.org/webacl> ;
ja:graph sa:securedACLModel ] ;
ja:namedGraph
[ ja:graphName <http://semapps.org/mirror> ;
ja:graph sa:mirrorModel ] ;
.

<#service_tdb_all> rdf:type fuseki:Service ;
rdfs:label "{rdfsLabel}" ;
fuseki:name "{dataset}" ;
fuseki:serviceQuery "query" ;
fuseki:serviceQuery "sparql" ;
fuseki:serviceUpdate "update" ;
fuseki:serviceUpload "upload" ;
fuseki:serviceReadWriteGraphStore "data" ;
# A separate read-only graph store endpoint:
fuseki:serviceReadGraphStore "get" ;
fuseki:dataset sa:securedDataset ;

.
2 changes: 1 addition & 1 deletion src/middleware/packages/activitypub/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ActivityPubService = {
jsonContext: ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'],
podProvider: false,
selectActorData: resource => ({
'@type': ACTOR_TYPES.PERSON,
'@type': resource.type || resource['@type'] || ACTOR_TYPES.PERSON,
name: undefined,
preferredUsername: getSlugFromUri(resource.id || resource['@id'])
}),
Expand Down
1 change: 1 addition & 0 deletions src/middleware/packages/activitypub/services/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const ActivityService = {
permissions: {},
newResourcesPermissions: {},
readOnly: true,
excludeFromMirror: true,
controlledActions: {
// Activities shouldn't be handled manually
patch: 'activitypub.activity.forbidden',
Expand Down
6 changes: 4 additions & 2 deletions src/middleware/packages/activitypub/services/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ActorService = {
baseUri: null,
jsonContext: ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'],
selectActorData: resource => ({
'@type': ACTOR_TYPES.PERSON,
'@type': resource.type || resource['@type'] || ACTOR_TYPES.PERSON,
name: undefined,
preferredUsername: getSlugFromUri(resource.id || resource['@id'])
}),
Expand Down Expand Up @@ -125,7 +125,9 @@ const ActorService = {
return uri.startsWith(this.settings.baseUri);
},
isActor(resource) {
return defaultToArray(resource['@type'] || resource.type).some(type => Object.values(ACTOR_TYPES).includes(type));
return defaultToArray(resource['@type'] || resource.type || []).some(type =>
Object.values(ACTOR_TYPES).includes(type)
);
}
},
events: {
Expand Down
Loading