mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-10-24 01:37:50 +08:00
Plugin config forms can now ask the plugin while they are filled in:
- x-options {name, dependsOn, search} loads a field's choices from
/v1/options/{name}. POST /api/v1/plugins/:id/options merges the form's
values with the stored secrets (system, tenant or instance scope) so a
redacted token still works. Go and Python SDKs, OpenAPI and conformance
cover the endpoint.
- x-oauth turns a string field into an account connection. WeKnora runs
the authorization code flow (PKCE, client credentials from the plugin's
system config), keeps the tokens sealed in plugin_oauth_connections and
the field holds "oauth:<id>". The invoker swaps references for fresh
access tokens at call time, refreshing near expiry. Callback:
/api/v1/plugin-oauth/callback, one-time states in Redis or memory.
- SchemaForm gains an options widget (dependsOn reload, remote search)
and an OAuth connect widget; connector, web search, workspace and
platform config forms provide the plugin behind them.
Host plugins are capped per runtime.resources on Linux: RLIMIT_DATA for
memory (WEKNORA_PLUGIN_MEMORY_DEFAULT when undeclared) and, with a
delegated cgroup v2 (WEKNORA_PLUGIN_CGROUP), memory.max and cpu.max.
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package host
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/Tencent/WeKnora/internal/plugin/manifest"
|
|
)
|
|
|
|
// envMemoryDefault is the memory limit of plugins that declare none
|
|
// (runtime.resources.memory), e.g. "1Gi". Unset: no limit. The cgroup
|
|
// setting (envCgroup) is Linux-only.
|
|
const envMemoryDefault = "WEKNORA_PLUGIN_MEMORY_DEFAULT"
|
|
|
|
// limits is what a plugin process may use; zero means no limit.
|
|
type limits struct {
|
|
cpuMilli int64
|
|
memoryBytes int64
|
|
}
|
|
|
|
// limitsFor reads a plugin's declared resources, with the platform default
|
|
// memory for plugins that declare none. The manifest was validated, so
|
|
// parse errors only mean "no limit".
|
|
func limitsFor(m *manifest.Manifest) limits {
|
|
var l limits
|
|
if r := m.Runtime.Resources; r != nil {
|
|
if r.CPU != "" {
|
|
l.cpuMilli, _ = manifest.ParseCPU(r.CPU)
|
|
}
|
|
if r.Memory != "" {
|
|
l.memoryBytes, _ = manifest.ParseMemory(r.Memory)
|
|
}
|
|
}
|
|
if l.memoryBytes == 0 {
|
|
if def := strings.TrimSpace(os.Getenv(envMemoryDefault)); def != "" {
|
|
l.memoryBytes, _ = manifest.ParseMemory(def)
|
|
}
|
|
}
|
|
return l
|
|
}
|