forked from SolidOS/solid-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacl.js
More file actions
74 lines (73 loc) · 2.15 KB
/
acl.js
File metadata and controls
74 lines (73 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import * as debug from '../../debug';
import { store } from 'solid-logic-jss';
/**
* set ACL
* @param keyDoc
* @param aclBody
*/
export async function setAcl(keyDoc, aclBody) {
// Some servers don't present a Link http response header
// if the container doesn't exist yet, refetch the resource
var _a;
await store.fetcher.load(keyDoc);
// FIXME: check the Why value on this quad:
// debug.log(store.statementsMatching(store.sym(keyDoc), store.sym('http://www.iana.org/assignments/link-relations/acl')))
const keyAclDoc = store.any(store.sym(keyDoc), store.sym('http://www.iana.org/assignments/link-relations/acl'));
if (!keyAclDoc) {
throw new Error('Key ACL doc not found!');
}
try {
await store.fetcher.webOperation('PUT', keyAclDoc.value, {
data: aclBody,
contentType: 'text/turtle'
});
}
catch (err) {
if (((_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) {
throw new Error(err);
}
debug.log('delete ' + keyAclDoc.value + ' ' + err.response.status); // should test 404 and 2xx
}
}
/**
* key container ACL
* @param me
* @returns aclBody
*/
export const keyContainerAclBody = (me) => {
const aclBody = `
@prefix : <#>.
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix key: <./>.
:ReadWrite
a acl:Authorization;
acl:accessTo key:;
acl:default key:;
acl:agent <${me}>;
acl:mode acl:Read, acl:Write.
`;
return aclBody;
};
/**
* Read only ACL
* @param keyDoc
* @param me
* @returns aclBody
*/
export const keyAclBody = (keyDoc, me) => {
let keyAgent = 'acl:agentClass foaf:Agent'; // publicKey
if (me === null || me === void 0 ? void 0 : me.length)
keyAgent = `acl:agent <${me}>`; // privateKey
const aclBody = `
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
<#Read>
a acl:Authorization;
${keyAgent};
acl:accessTo <${keyDoc.split('/').pop()}>;
acl:mode acl:Read.
`;
return aclBody;
};
//# sourceMappingURL=acl.js.map