Rename group package and defaults to halls

This commit is contained in:
Storm Dragon
2026-05-17 22:37:38 -04:00
parent 55528b8e62
commit a8ada950d5
26 changed files with 459 additions and 459 deletions
+24 -24
View File
@@ -13,7 +13,7 @@ import (
"golang.org/x/crypto/bcrypt"
"git.stormux.org/storm/skald/group"
"git.stormux.org/storm/skald/hall"
"git.stormux.org/storm/skald/stats"
"git.stormux.org/storm/skald/token"
)
@@ -47,7 +47,7 @@ func checkPasswordAdmin(w http.ResponseWriter, r *http.Request, hallname, user s
}
}
if ok && !wildcard && username == user {
desc, err := group.GetDescription(hallname)
desc, err := hall.GetDescription(hallname)
if err != nil {
internalError(w,
"Get description for group %v: %v",
@@ -193,7 +193,7 @@ func apiGroupHandler(w http.ResponseWriter, r *http.Request, pth string) {
methodNotAllowed(w, "HEAD, GET")
return
}
groups, err := group.GetDescriptionNames()
groups, err := hall.GetDescriptionNames()
if err != nil {
httpError(w, err)
return
@@ -233,7 +233,7 @@ func apiGroupHandler(w http.ResponseWriter, r *http.Request, pth string) {
}
if r.Method == "HEAD" || r.Method == "GET" {
desc, etag, err := group.GetSanitisedDescription(g)
desc, etag, err := hall.GetSanitisedDescription(g)
if err != nil {
httpError(w, err)
return
@@ -249,7 +249,7 @@ func apiGroupHandler(w http.ResponseWriter, r *http.Request, pth string) {
sendJSON(w, r, desc)
return
} else if r.Method == "PUT" {
etag, err := group.GetDescriptionTag(g)
etag, err := hall.GetDescriptionTag(g)
if errors.Is(err, os.ErrNotExist) {
err = nil
etag = ""
@@ -263,12 +263,12 @@ func apiGroupHandler(w http.ResponseWriter, r *http.Request, pth string) {
return
}
var newdesc group.Description
var newdesc hall.Description
done = getJSON(w, r, &newdesc)
if done {
return
}
err = group.UpdateDescription(g, etag, &newdesc)
err = hall.UpdateDescription(g, etag, &newdesc)
if err != nil {
httpError(w, err)
return
@@ -280,7 +280,7 @@ func apiGroupHandler(w http.ResponseWriter, r *http.Request, pth string) {
}
return
} else if r.Method == "DELETE" {
etag, err := group.GetDescriptionTag(g)
etag, err := hall.GetDescriptionTag(g)
if err != nil {
httpError(w, err)
return
@@ -290,7 +290,7 @@ func apiGroupHandler(w http.ResponseWriter, r *http.Request, pth string) {
if done {
return
}
err = group.DeleteDescription(g, etag)
err = hall.DeleteDescription(g, etag)
if err != nil {
httpError(w, err)
return
@@ -318,7 +318,7 @@ func usersHandler(w http.ResponseWriter, r *http.Request, g, pth string) {
methodNotAllowed(w, "HEAD, GET")
return
}
users, etag, err := group.GetUsers(g)
users, etag, err := hall.GetUsers(g)
if err != nil {
httpError(w, err)
return
@@ -371,7 +371,7 @@ func userHandler(w http.ResponseWriter, r *http.Request, g, user string, wildcar
}
if r.Method == "HEAD" || r.Method == "GET" {
user, etag, err := group.GetSanitisedUser(g, user, wildcard)
user, etag, err := hall.GetSanitisedUser(g, user, wildcard)
if err != nil {
httpError(w, err)
return
@@ -384,7 +384,7 @@ func userHandler(w http.ResponseWriter, r *http.Request, g, user string, wildcar
sendJSON(w, r, user)
return
} else if r.Method == "PUT" {
etag, err := group.GetUserTag(g, user, wildcard)
etag, err := hall.GetUserTag(g, user, wildcard)
if errors.Is(err, os.ErrNotExist) {
etag = ""
err = nil
@@ -398,12 +398,12 @@ func userHandler(w http.ResponseWriter, r *http.Request, g, user string, wildcar
return
}
var newdesc group.UserDescription
var newdesc hall.UserDescription
done = getJSON(w, r, &newdesc)
if done {
return
}
err = group.UpdateUser(g, user, wildcard, etag, &newdesc)
err = hall.UpdateUser(g, user, wildcard, etag, &newdesc)
if err != nil {
httpError(w, err)
return
@@ -415,7 +415,7 @@ func userHandler(w http.ResponseWriter, r *http.Request, g, user string, wildcar
}
return
} else if r.Method == "DELETE" {
etag, err := group.GetUserTag(g, user, wildcard)
etag, err := hall.GetUserTag(g, user, wildcard)
if err != nil {
httpError(w, err)
return
@@ -426,7 +426,7 @@ func userHandler(w http.ResponseWriter, r *http.Request, g, user string, wildcar
return
}
err = group.DeleteUser(g, user, wildcard, etag)
err = hall.DeleteUser(g, user, wildcard, etag)
if err != nil {
httpError(w, err)
return
@@ -447,12 +447,12 @@ func passwordHandler(w http.ResponseWriter, r *http.Request, g, user string, wil
}
if r.Method == "PUT" {
var pw group.Password
var pw hall.Password
done := getJSON(w, r, &pw)
if done {
return
}
err := group.SetUserPassword(g, user, wildcard, pw)
err := hall.SetUserPassword(g, user, wildcard, pw)
if err != nil {
httpError(w, err)
return
@@ -471,11 +471,11 @@ func passwordHandler(w http.ResponseWriter, r *http.Request, g, user string, wil
}
k := string(key)
pw := group.Password{
pw := hall.Password{
Type: "bcrypt",
Key: &k,
}
err = group.SetUserPassword(g, user, wildcard, pw)
err = hall.SetUserPassword(g, user, wildcard, pw)
if err != nil {
httpError(w, err)
return
@@ -483,7 +483,7 @@ func passwordHandler(w http.ResponseWriter, r *http.Request, g, user string, wil
w.WriteHeader(http.StatusNoContent)
return
} else if r.Method == "DELETE" {
err := group.SetUserPassword(g, user, wildcard, group.Password{})
err := hall.SetUserPassword(g, user, wildcard, hall.Password{})
if err != nil {
httpError(w, err)
return
@@ -528,7 +528,7 @@ func keysHandler(w http.ResponseWriter, r *http.Request, g string) {
httpError(w, err)
return
}
err = group.SetKeys(g, keys.Keys)
err = hall.SetKeys(g, keys.Keys)
if err != nil {
httpError(w, err)
return
@@ -536,7 +536,7 @@ func keysHandler(w http.ResponseWriter, r *http.Request, g string) {
w.WriteHeader(http.StatusNoContent)
return
} else if r.Method == "DELETE" {
err := group.SetKeys(g, nil)
err := hall.SetKeys(g, nil)
if err != nil {
httpError(w, err)
return
@@ -563,7 +563,7 @@ func tokensHandler(w http.ResponseWriter, r *http.Request, g, pth string) {
if g != "" {
// check that the group exists
_, err := group.GetDescription(g)
_, err := hall.GetDescription(g)
if err != nil {
httpError(w, err)
return
+12 -12
View File
@@ -15,7 +15,7 @@ import (
"path/filepath"
"testing"
"git.stormux.org/storm/skald/group"
"git.stormux.org/storm/skald/hall"
"git.stormux.org/storm/skald/token"
)
@@ -34,8 +34,8 @@ func setup() {
func setupTest(dir, datadir string) error {
setup()
group.Directory = dir
group.DataDirectory = datadir
hall.Directory = dir
hall.DataDirectory = datadir
config := `{
"writableGroups": true,
"users": {
@@ -45,7 +45,7 @@ func setupTest(dir, datadir string) error {
}
}
}`
f, err := os.Create(filepath.Join(group.DataDirectory, "config.json"))
f, err := os.Create(filepath.Join(hall.DataDirectory, "config.json"))
if err != nil {
return err
}
@@ -142,7 +142,7 @@ func TestApi(t *testing.T) {
t.Errorf("Create hall: %v %v", err, resp.StatusCode)
}
var desc *group.Description
var desc *hall.Description
err = getJSON("/skald-api/v0/.halls/test/", &desc)
if err != nil || len(desc.Users) != 0 {
t.Errorf("Get hall: %v", err)
@@ -223,7 +223,7 @@ func TestApi(t *testing.T) {
t.Errorf("Set password (POST): %v %v", err, resp.StatusCode)
}
var user group.UserDescription
var user hall.UserDescription
err = getJSON("/skald-api/v0/.halls/test/.users/jch", &user)
if err != nil {
t.Errorf("Get user: %v", err)
@@ -232,7 +232,7 @@ func TestApi(t *testing.T) {
t.Errorf("User not sanitised properly")
}
desc, err = group.GetDescription("test")
desc, err = hall.GetDescription("test")
if err != nil {
t.Errorf("GetDescription: %v", err)
}
@@ -251,7 +251,7 @@ func TestApi(t *testing.T) {
t.Errorf("Delete hall: %v %v", err, resp.StatusCode)
}
desc, err = group.GetDescription("test")
desc, err = hall.GetDescription("test")
if err != nil {
t.Errorf("GetDescription: %v", err)
}
@@ -272,7 +272,7 @@ func TestApi(t *testing.T) {
t.Errorf("Get wildcard user: %v", err)
}
desc, err = group.GetDescription("test")
desc, err = hall.GetDescription("test")
if err != nil {
t.Errorf("GetDescription: %v", err)
}
@@ -287,7 +287,7 @@ func TestApi(t *testing.T) {
t.Errorf("Delete wildcard user: %v %v", err, resp.StatusCode)
}
desc, err = group.GetDescription("test")
desc, err = hall.GetDescription("test")
if err != nil {
t.Errorf("GetDescription: %v", err)
}
@@ -414,7 +414,7 @@ func TestApi(t *testing.T) {
t.Errorf("Delete hall: %v %v", err, resp.StatusCode)
}
_, err = group.GetDescription("test")
_, err = hall.GetDescription("test")
if !errors.Is(err, os.ErrNotExist) {
t.Errorf("Group exists after delete")
}
@@ -451,7 +451,7 @@ func TestApiBadAuth(t *testing.T) {
do("GET", "/skald-api/v0/.halls/")
do("PUT", "/skald-api/v0/.halls/test/")
f, err := os.Create(filepath.Join(group.Directory, "test.json"))
f, err := os.Create(filepath.Join(hall.Directory, "test.json"))
if err != nil {
t.Fatalf("Create(test.json): %v", err)
}
+22 -22
View File
@@ -22,7 +22,7 @@ import (
"github.com/gorilla/websocket"
"git.stormux.org/storm/skald/diskwriter"
"git.stormux.org/storm/skald/group"
"git.stormux.org/storm/skald/hall"
"git.stormux.org/storm/skald/rtpconn"
"github.com/jech/cert"
)
@@ -64,7 +64,7 @@ func Serve(address string, dataDir string) error {
}
}
s.RegisterOnShutdown(func() {
group.Shutdown("server is shutting down")
hall.Shutdown("server is shutting down")
})
server = s
@@ -130,11 +130,11 @@ func httpError(w http.ResponseWriter, err error) {
notFound(w)
return
}
if errors.Is(err, group.ErrUnknownPermission) {
if errors.Is(err, hall.ErrUnknownPermission) {
http.Error(w, "unknown permission", http.StatusBadRequest)
return
}
var autherr *group.NotAuthorisedError
var autherr *hall.NotAuthorisedError
if errors.As(err, &autherr) {
log.Printf("HTTP server error: %v", err)
http.Error(w, "not authorised", http.StatusUnauthorized)
@@ -160,7 +160,7 @@ const (
)
func redirect(w http.ResponseWriter, r *http.Request) bool {
conf, err := group.GetConfiguration()
conf, err := hall.GetConfiguration()
if err != nil || conf.CanonicalHost == "" {
return false
}
@@ -285,7 +285,7 @@ func serveFile(w http.ResponseWriter, r *http.Request, p string) {
http.ServeContent(w, r, fi.Name(), fi.ModTime(), f)
}
func parseGroupName(prefix string, p string) string {
func parseHallName(prefix string, p string) string {
if !strings.HasPrefix(p, prefix) {
return ""
}
@@ -346,13 +346,13 @@ func groupHandler(w http.ResponseWriter, r *http.Request) {
return
}
name := parseGroupName("/hall/", r.URL.Path)
name := parseHallName("/hall/", r.URL.Path)
if name == "" {
notFound(w)
return
}
g, err := group.Add(name, nil)
g, err := hall.Add(name, nil)
if err != nil {
httpError(w, err)
return
@@ -375,7 +375,7 @@ func groupHandler(w http.ResponseWriter, r *http.Request) {
}
func baseURL(r *http.Request) (*url.URL, error) {
conf, err := group.GetConfiguration()
conf, err := hall.GetConfiguration()
if err != nil {
return nil, err
}
@@ -415,13 +415,13 @@ func groupStatusHandler(w http.ResponseWriter, r *http.Request) {
internalError(w, "groupStatusHandler: this shouldn't happen")
return
}
name := parseGroupName("/hall/", pth)
name := parseHallName("/hall/", pth)
if name == "" {
notFound(w)
return
}
g, err := group.Add(name, nil)
g, err := hall.Add(name, nil)
if err != nil {
httpError(w, err)
return
@@ -458,13 +458,13 @@ func publicHandler(w http.ResponseWriter, r *http.Request) {
return
}
g := group.GetPublic(base)
g := hall.GetPublic(base)
e := json.NewEncoder(w)
e.Encode(g)
}
func adminMatch(username, password string) (bool, error) {
conf, err := group.GetConfiguration()
conf, err := hall.GetConfiguration()
if err != nil {
return false, err
}
@@ -512,7 +512,7 @@ func CheckOrigin(w http.ResponseWriter, r *http.Request, admin bool) bool {
if err == nil && strings.EqualFold(o.Host, r.Host) {
ok = true
} else {
conf, err := group.GetConfiguration()
conf, err := hall.GetConfiguration()
if err != nil {
return false
}
@@ -613,20 +613,20 @@ func recordingsHandler(w http.ResponseWriter, r *http.Request) {
for len(p) > 0 && p[len(p)-1] == '/' {
p = p[:len(p)-1]
}
group = parseGroupName("/", p)
group = parseHallName("/", p)
if group == "" {
http.Error(w, "Bad group name", http.StatusBadRequest)
http.Error(w, "Bad hall name", http.StatusBadRequest)
return
}
} else {
if p[len(p)-1] == '/' {
http.Error(w, "Bad group name", http.StatusBadRequest)
http.Error(w, "Bad hall name", http.StatusBadRequest)
return
}
group, filename = path.Split(p)
group = parseGroupName("/", group)
group = parseHallName("/", group)
if group == "" {
http.Error(w, "Bad group name", http.StatusBadRequest)
http.Error(w, "Bad hall name", http.StatusBadRequest)
return
}
}
@@ -711,13 +711,13 @@ func checkGroupPermissions(w http.ResponseWriter, r *http.Request, hallname stri
return false
}
g := group.Get(hallname)
g := hall.Get(hallname)
if g == nil {
return false
}
_, p, err := g.GetPermission(
group.ClientCredentials{
hall.ClientCredentials{
Username: &user,
Password: pass,
},
@@ -732,7 +732,7 @@ func checkGroupPermissions(w http.ResponseWriter, r *http.Request, hallname stri
}
}
if err != nil || !record {
var autherr *group.NotAuthorisedError
var autherr *hall.NotAuthorisedError
if errors.As(err, &autherr) {
time.Sleep(200 * time.Millisecond)
}
+6 -6
View File
@@ -10,10 +10,10 @@ import (
"github.com/pion/webrtc/v4"
"git.stormux.org/storm/skald/group"
"git.stormux.org/storm/skald/hall"
)
func TestParseGroupName(t *testing.T) {
func TestParseHallName(t *testing.T) {
a := []struct{ p, g string }{
{"", ""},
{"/foo", ""},
@@ -29,7 +29,7 @@ func TestParseGroupName(t *testing.T) {
}
for _, pg := range a {
g := parseGroupName("/hall/", pg.p)
g := parseHallName("/hall/", pg.p)
if g != pg.g {
t.Errorf("Path %v, got %v, expected %v",
pg.p, g, pg.g)
@@ -58,10 +58,10 @@ func TestBase(t *testing.T) {
}
dir := t.TempDir()
group.DataDirectory = dir
hall.DataDirectory = dir
for _, v := range a {
conf := group.Configuration{
conf := hall.Configuration{
ProxyURL: v.p,
}
c, err := json.Marshal(conf)
@@ -200,7 +200,7 @@ func TestFormatICEServer(t *testing.T) {
func TestMatchAdmin(t *testing.T) {
d := t.TempDir()
group.DataDirectory = d
hall.DataDirectory = d
filename := filepath.Join(d, "config.json")
f, err := os.Create(filename)
+10 -10
View File
@@ -17,7 +17,7 @@ import (
"github.com/pion/webrtc/v4"
"git.stormux.org/storm/skald/group"
"git.stormux.org/storm/skald/hall"
"git.stormux.org/storm/skald/ice"
"git.stormux.org/storm/skald/rtpconn"
"git.stormux.org/storm/skald/sdpfrag"
@@ -153,13 +153,13 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
return
}
name := parseGroupName("/hall/", pth)
name := parseHallName("/hall/", pth)
if name == "" {
notFound(w)
return
}
g, err := group.Add(name, nil)
g, err := hall.Add(name, nil)
if err != nil {
httpError(w, err)
return
@@ -199,7 +199,7 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
token := parseBearerToken(r.Header.Get("Authorization"))
whip := "whip"
creds := group.ClientCredentials{
creds := hall.ClientCredentials{
Username: &whip,
Token: token,
}
@@ -221,7 +221,7 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
c := rtpconn.NewWhipClient(g, id, token, addr)
_, err = group.AddClient(g.Name(), c, creds)
_, err = hall.AddClient(g.Name(), c, creds)
if err != nil {
log.Printf("WHIP: %v", err)
httpError(w, err)
@@ -229,7 +229,7 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
}
if !canPresent(c.Permissions()) {
group.DelClient(c)
hall.DelClient(c)
http.Error(w, "Forbidden", http.StatusForbidden)
return
}
@@ -238,7 +238,7 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
answer, err := c.NewConnection(r.Context(), body)
if err != nil {
group.DelClient(c)
hall.DelClient(c)
log.Printf("WHIP offer: %v", err)
httpError(w, err)
return
@@ -269,13 +269,13 @@ func whipResourceHandler(w http.ResponseWriter, r *http.Request) {
return
}
name := parseGroupName("/hall/", pth)
name := parseHallName("/hall/", pth)
if name == "" {
notFound(w)
return
}
g := group.Get(name)
g := hall.Get(name)
if g == nil {
notFound(w)
return
@@ -295,7 +295,7 @@ func whipResourceHandler(w http.ResponseWriter, r *http.Request) {
if t := c.Token(); t != "" {
token := parseBearerToken(r.Header.Get("Authorization"))
if !group.ConstantTimeCompare(t, token) {
if !hall.ConstantTimeCompare(t, token) {
http.Error(w, "Forbidden", http.StatusForbidden)
return
}