-
Notifications
You must be signed in to change notification settings - Fork 5
/
api.go
27 lines (23 loc) · 1.14 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package cedar
import "github.com/tetratelabs/wazero/api"
type function string
const (
allocate function = "allocate"
deallocate function = "deallocate"
setEntities function = "set_entities"
setPolicies function = "set_policies"
isAuthorizedString function = "is_authorized_string"
isAuthorizedJSON function = "is_authorized_json"
)
// exportFuncs returns a map of exported functions from the wasm module.
func exportFuncs(module api.Module) map[string]api.Function {
exportedFuncs := make(map[string]api.Function)
exportedFuncs[string(isAuthorizedString)] = module.ExportedFunction(string(isAuthorizedString))
exportedFuncs[string(isAuthorizedJSON)] = module.ExportedFunction(string(isAuthorizedJSON))
exportedFuncs[string(setEntities)] = module.ExportedFunction(string(setEntities))
exportedFuncs[string(setPolicies)] = module.ExportedFunction(string(setPolicies))
// allocate and deallocate help us manage memory in the wasm module.
exportedFuncs[string(allocate)] = module.ExportedFunction(string(allocate))
exportedFuncs[string(deallocate)] = module.ExportedFunction(string(deallocate))
return exportedFuncs
}