2 * @file Strapp main driver
3 * @author Jordan Lavatai, Ken Grimes
6 * @copyright August 2017 - Ken Grimes, Jordan Lavatai
7 * @summmary Bootstrapper for the strapp.io mechanism
10 const StrappFile
= (() => {
11 const authorize
= (pubKey
, mode
, stat
) => {
13 if (pubKey
=== stat
.owner
)
14 allowed
= (stat
.perms
>>> 16) & 0xF
17 let uGroups
= StrappFile
.get(`acct/${pubKey}/groups`).split(' ')
18 for (let i
= 0; i
< uGroups
.length
; i
++) {
19 if (uGroups
[i
] === stat
.group
) {
25 allowed
= (stat
.perms
>>> 8) & 0xF
27 allowed
= stat
.perms
& 0xF
33 return (allowed
& 0x6) === 0x6
35 return (allowed
& 0x2) === 0x2
37 return (allowed
& 0x4) === 0x4
39 return (allowed
& 0x1) === 0x1
41 console
.log(`Unknown access mode: ${mode}`)
45 class StrappFile
extends Object
{
46 constructor(...props
) {
48 return Object
.assign(this, new.target
.defaults
, ...props
)
50 static PermissionDenied() {
51 return new Promise((resolve
, reject
) => reject('Permission denied'))
54 if (authorize(opt
.pubKey
, 'r', this.stat
))
55 return new Promise((resolve
, reject
) => resolve(''))
57 return StrappFile
.PermissionDenied()
60 if (authorize(opt
.pubKey
, 'r', this.stat
))
61 return StrappFile
.get(this.path
)
62 else return StrappFile
.PermissionDenied()
65 if (authorize(opt
.pubKey
, 'w', this.stat
))
66 return StrappFile
.set(this.path
, opt
.data
)
67 else return StrappFile
.PermissionDenied()
70 return this.PUT(Object
.assign(opt
, { data
: this.GET(opt
) + opt
.data
}))
73 if (authorize(opt
.pubKey
, 'w', this.stat
))
74 return StrappFile
.delete(this.path
)
75 else return StrappFile
.PermissionDenied()
88 StrappFile
.defaults
= {
91 owner
: 'thisOwnerPubKey',
95 accessed
: 'time - not saved'