This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/server/sandbox/permissions_module.go
Jeffrey Smith e4f0bdbd36
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-frontend (push) Successful in 6s
CI/CD / test-runners (push) Has been skipped
CI/CD / test-go-pg (push) Successful in 2m48s
CI/CD / test-sqlite (push) Successful in 2m49s
CI/CD / build-and-deploy (push) Successful in 28s
Feat v0.7.7 api tokens ext permissions (#61)
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
2026-04-02 19:11:47 +00:00

45 lines
1.3 KiB
Go

// Package sandbox — permissions_module.go
//
// Read-only module for checking user permissions from Starlark scripts.
// No sandbox permission required — extensions can check whether a user
// has a specific permission without needing any special grants.
//
// Starlark API:
// permissions.check(user_id, "image-gen.use") → True/False
package sandbox
import (
"context"
"go.starlark.net/starlark"
"go.starlark.net/starlarkstruct"
"armature/auth"
"armature/store"
)
// BuildPermissionsModule creates the "permissions" module.
// Always available to all extensions (no permission gate).
func BuildPermissionsModule(ctx context.Context, stores store.Stores) *starlarkstruct.Module {
return MakeModule("permissions", starlark.StringDict{
"check": starlark.NewBuiltin("permissions.check", func(
thread *starlark.Thread, b *starlark.Builtin,
args starlark.Tuple, kwargs []starlark.Tuple,
) (starlark.Value, error) {
var userID, perm string
if err := starlark.UnpackPositionalArgs(b.Name(), args, kwargs, 2, &userID, &perm); err != nil {
return nil, err
}
perms, err := auth.ResolvePermissions(ctx, stores, userID)
if err != nil {
return starlark.False, nil
}
if perms[perm] {
return starlark.True, nil
}
return starlark.False, nil
}),
})
}