Feat v0.7.7 api tokens ext permissions (#61)
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
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
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #61.
This commit is contained in:
44
server/sandbox/permissions_module.go
Normal file
44
server/sandbox/permissions_module.go
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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
|
||||
}),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user