/
seed.js
84 lines (70 loc) · 1.61 KB
/
seed.js
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
75
76
77
78
79
80
81
82
83
84
'use strict';
const dotenv = require('dotenv');
dotenv.config();
const fs = require('fs');
const oso = require('../oso');
main().catch(error => {
console.error(error);
process.exit(-1);
});
async function main() {
const policy = fs.readFileSync('./scripts/main.polar', 'utf8');
await oso.policy(policy);
await oso.tell(
'has_relation',
{ type: 'File', id: 'tps-report.txt' },
'owner',
{ type: 'User', id: 'Peter' }
);
await oso.tell(
'has_relation',
{ type: 'File', id: 'tps-reports/tps-report.txt' },
'folder',
{ type: 'Folder', id: 'tps-reports' }
);
await oso.tell(
'has_relation',
{ type: 'Folder', id: 'tps-reports' },
'organization',
{ type: 'Organization', id: 'initech' }
);
await oso.tell(
'has_role',
{ type: 'User', id: 'Bill' },
'admin',
{ type: 'Organization', id: 'initech' }
);
await oso.tell(
'has_role',
{ type: 'User', id: 'Peter' },
'member',
{ type: 'Organization', id: 'initech' }
);
await oso.tell(
'has_role',
{ type: 'User', id: 'Samir' },
'member',
{ type: 'Organization', id: 'initech' }
);
await oso.tell(
'has_role',
{ type: 'User', id: 'Michael' },
'member',
{ type: 'Organization', id: 'initech' }
);
await oso.tell(
'is_public',
{ type: 'File', id: 'test.txt' }
);
await oso.tell(
'is_readable_by_org',
{ type: 'File', id: 'tps-reports/tps-report.txt' }
);
await oso.tell(
'has_role',
{ type: 'User', id: 'Michael' },
'writer',
{ type: 'File', id: 'tps-reports/tps-report.txt' }
);
console.log('Done');
}