repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

pico / pgs
Eric Bower · 28 Feb 24

access.go

 1package pgs
 2
 3import (
 4	"slices"
 5
 6	"github.com/picosh/pico/db"
 7	"golang.org/x/crypto/ssh"
 8)
 9
10func HasProjectAccess(project *db.Project, owner *db.User, requester *db.User, pubkey ssh.PublicKey) bool {
11	aclType := project.Acl.Type
12	data := project.Acl.Data
13
14	if aclType == "public" {
15		return true
16	}
17
18	if requester != nil {
19		if owner.ID == requester.ID {
20			return true
21		}
22	}
23
24	if aclType == "pico" {
25		if requester == nil {
26			return false
27		}
28
29		if len(data) == 0 {
30			return true
31		}
32		return slices.Contains(data, requester.Name)
33	}
34
35	if aclType == "pubkeys" {
36		key := ssh.FingerprintSHA256(pubkey)
37		if len(data) == 0 {
38			return true
39		}
40		return slices.Contains(data, key)
41	}
42
43	return true
44}