implement first draft of sprockets
This commit is contained in:
@@ -2,13 +2,71 @@ package acl
|
||||
|
||||
import (
|
||||
"lol.mleku.dev/log"
|
||||
"next.orly.dev/app/config"
|
||||
"next.orly.dev/pkg/encoders/bech32encoding"
|
||||
"next.orly.dev/pkg/utils"
|
||||
)
|
||||
|
||||
type None struct{}
|
||||
type None struct {
|
||||
cfg *config.C
|
||||
owners [][]byte
|
||||
admins [][]byte
|
||||
}
|
||||
|
||||
func (n None) Configure(cfg ...any) (err error) { return }
|
||||
func (n *None) Configure(cfg ...any) (err error) {
|
||||
for _, ca := range cfg {
|
||||
switch c := ca.(type) {
|
||||
case *config.C:
|
||||
n.cfg = c
|
||||
}
|
||||
}
|
||||
if n.cfg == nil {
|
||||
return
|
||||
}
|
||||
|
||||
func (n None) GetAccessLevel(pub []byte, address string) (level string) {
|
||||
// Load owners
|
||||
for _, owner := range n.cfg.Owners {
|
||||
if len(owner) == 0 {
|
||||
continue
|
||||
}
|
||||
var pk []byte
|
||||
if pk, err = bech32encoding.NpubOrHexToPublicKeyBinary(owner); err != nil {
|
||||
continue
|
||||
}
|
||||
n.owners = append(n.owners, pk)
|
||||
}
|
||||
|
||||
// Load admins
|
||||
for _, admin := range n.cfg.Admins {
|
||||
if len(admin) == 0 {
|
||||
continue
|
||||
}
|
||||
var pk []byte
|
||||
if pk, err = bech32encoding.NpubOrHexToPublicKeyBinary(admin); err != nil {
|
||||
continue
|
||||
}
|
||||
n.admins = append(n.admins, pk)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (n *None) GetAccessLevel(pub []byte, address string) (level string) {
|
||||
// Check owners first
|
||||
for _, v := range n.owners {
|
||||
if utils.FastEqual(v, pub) {
|
||||
return "owner"
|
||||
}
|
||||
}
|
||||
|
||||
// Check admins
|
||||
for _, v := range n.admins {
|
||||
if utils.FastEqual(v, pub) {
|
||||
return "admin"
|
||||
}
|
||||
}
|
||||
|
||||
// Default to write for everyone else
|
||||
return "write"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user