Skip to content

[Feature] 新增 [external] 命名查询功能 #22

Description

@seeker-zuo

背景

wf-engine 新增 external("service_name", arg) WFL 函数,允许规则在运行时调用外部服务做点查询(弱口令检查、威胁情报 IP 查询等)。P0 仅支持 Redis 后端。

当前 wp-knowledge 已有 facade(redis_bf_exists / redis_hget / redis_get / redis_set_exists)及连接池、缓存、超时管理。external() 需要在 wp-knowledge 层提供"命名查询"抽象,让上层只需传 service name + arg,不感知底层是 Bloom filter、Hash 还是 Set。

需求

knowdb.toml 新增 [external]

[external.password_check]
call = "bf_exists"
key = "weak_passwords"

[external.threat_actor]
call = "hget"
key = "threat_actors"

[external.ip_whitelist]
call = "sismember"
key = "allowed_ips"

[external.config_value]
call = "get"
key = "app_config"
字段 必填 说明
call bf_exists / hget / get / sismember
key Redis key。get 时可省略,以 arg 作 key

新增 facade API

/// 执行 [external.<name>] 定义的命名查询。
/// - service: 对应配置中的 name
/// - arg: 查询参数(密码哈希、IP 地址等)
/// - 返回 Some(String) 命中,None 未命中
pub fn external_call(service: &str, arg: &str) -> KnowledgeResult<Option<String>>

缓存 & 超时

  • 复用已有 [cache] 配置
  • 缓存 key: (generation, "external", service_name, arg)
  • 超时复用 [provider.redis].command_timeout_ms

调用链路

WFL: external("password_check", e.password_hash)
  → wf-engine eval.rs
    → wf-runtime ExternalRuntime
      → wp_knowledge::facade::external_call("password_check", "<hash>")
        ├─ 查找注册表: [external.password_check]
        ├─ 缓存检查
        ├─ redis_bf_exists / redis_hget / ...
        └─ 缓存写入

不做的

  • P0 不提供 per-service 超时/缓存覆盖
  • P0 仅支持 Redis provider
  • on_error 不在 knowledge 层,由 wfusion 侧处理

关联

  • wfusion 侧: wp-reactor external() 实现
  • 设计文档: wp-reactor/docs/design/external-function-design.md
  • Redis provider: docs/zh/guides/redis-provider.md

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions