Files
zeekay 42520800f8 feat(base): add OpenFaaS functions plugin
Per-tenant serverless function management via OpenFaaS gateway:
- CRUD at /api/functions (deploy, list, get, delete)
- Invocation at /api/functions/{name}/invoke (sync + async)
- Tenant isolation via t-{slug}-{name} namespacing
- _functions system collection for tracking
- Auto-injected env: IAM_URL, STORAGE_URL
2026-03-01 18:38:16 -08:00

41 lines
1.1 KiB
Go

package functions
import (
"log/slog"
"github.com/hanzoai/base/core"
)
const collectionFunctions = "_functions"
func (p *plugin) ensureCollections() error {
_, err := p.app.FindCollectionByNameOrId(collectionFunctions)
if err == nil {
return nil // already exists
}
c := core.NewBaseCollection(collectionFunctions)
c.System = true
c.Fields.Add(
&core.TextField{Name: "name", Required: true, Max: 255},
&core.TextField{Name: "qualifiedName", Required: true, Max: 512},
&core.TextField{Name: "tenantId", Required: true, Max: 255},
&core.TextField{Name: "image", Max: 1024},
&core.TextField{Name: "runtime", Max: 64},
&core.TextField{Name: "handler", Max: 512},
&core.SelectField{
Name: "status",
Required: true,
MaxSelect: 1,
Values: []string{"deployed", "building", "error", "deleted"},
},
&core.JSONField{Name: "envVars"},
&core.JSONField{Name: "metadata"},
&core.AutodateField{Name: "created", OnCreate: true},
&core.AutodateField{Name: "updated", OnCreate: true, OnUpdate: true},
)
p.app.Logger().Info("creating functions system collection", slog.String("name", collectionFunctions))
return p.app.Save(c)
}