Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Add Backend Configuration API

未关闭
#57 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
python

调研方向

从 fastly_compute.requests.backend 和 stubs/wit_world/imports/backend.py 中的 WIT bindings 开始,了解现有的 backend 解析方式和可用操作。定义公开的 Backend wrapper、DynamicBackendConfig 以及 API design 中描述的 enum 映射,同时保留现有的 requests facade。使用 SDK 测试验证 wrapper 转换、introspection 和错误处理,并使用 Viceroy 或 mock endpoints 发送 backend 请求。

由索引模型根据 Issue 内容生成。

描述

Overview

Extract and enhance backend functionality as a public API for both high-level and low-level use cases.

Current State:

  • ✅ Basic backend resolution in fastly_compute.requests.backend (internal)
  • ✅ Static backend lookup via wit_backend.Backend.open()
  • ✅ Dynamic backend registration with TLS/timeout config
  • ❌ Limited to requests facade - not exposed publicly
  • ❌ Missing advanced features (client certs, custom CA, cipher selection, gRPC, pooling, keepalive)
  • ❌ Returns raw WIT objects instead of wrapped resources

This Issue:
Create public fastly_compute.backend module exposing:

  1. Backend wrapper - Pythonic wrapper around WIT Backend resource
  2. Advanced configuration - All WIT features (certs, ciphers, TLS versions, keepalive, pooling)
  3. Introspection API - Query backend properties (health, timeouts, TLS settings)
  4. Requests integration - Existing facade continues working unchanged

WIT Interface

interface backend {
  use types.{error, open-error};
  use http-types.{tls-version};
  use secret-store.{secret};

  resource dynamic-backend-options {
    constructor();
    override-host: func(value: string);
    connect-timeout: func(value: u32);
    first-byte-timeout: func(value: u32);
    between-bytes-timeout: func(value: u32);
    use-tls: func(value: bool);
    tls-min-version: func(value: tls-version);
    tls-max-version: func(value: tls-version);
    cert-hostname: func(value: string);
    ca-certificate: func(value: string);
    tls-ciphers: func(value: string);
    sni-hostname: func(value: string);
    client-cert: func(client-cert: string, key: borrow<secret>);
    http-keepalive-time-ms: func(value: u32);
    tcp-keepalive-enable: func(value: u32);
    tcp-keepalive-interval-secs: func(value: u32);
    tcp-keepalive-probes: func(value: u32);
    tcp-keepalive-time-secs: func(value: u32);
    max-connections: func(value: u32);
    max-use: func(value: u32);
    max-lifetime-ms: func(value: u32);
    pooling: func(value: bool);
    grpc: func(value: bool);
    prefer-ipv6: func(value: bool);
  }

  type timeout-ms = u32;
  type timeout-secs = u32;
  type probe-count = u32;

  enum backend-health {
    unknown,
    healthy,
    unhealthy,
  }

  resource backend {
    open: static func(name: string) -> result<backend, open-error>;
    get-name: func() -> string;
    is-healthy: func() -> result<backend-health, error>;
    is-dynamic: func() -> result<bool, error>;
    get-host: func(max-len: u64) -> result<string, error>;
    get-override-host: func(max-len: u64) -> result<option<list<u8>>, error>;
    get-port: func() -> result<u16, error>;
    get-connect-timeout-ms: func() -> result<timeout-ms, error>;
    get-first-byte-timeout-ms: func() -> result<timeout-ms, error>;
    get-between-bytes-timeout-ms: func() -> result<timeout-ms, error>;
    is-tls: func() -> result<bool, error>;
    get-tls-min-version: func() -> result<option<tls-version>, error>;
    get-tls-max-version: func() -> result<option<tls-version>, error>;
    get-http-keepalive-time: func() -> result<timeout-ms, error>;
    get-tcp-keepalive-enable: func() -> result<bool, error>;
    get-tcp-keepalive-interval: func() -> result<timeout-secs, error>;
    get-tcp-keepalive-probes: func() -> result<probe-count, error>;
    get-tcp-keepalive-time: func() -> result<timeout-secs, error>;
  }

  register-dynamic-backend: func(prefix: string, target: string, options: dynamic-backend-options) -> result<backend, error>;
}

WIT bindings: stubs/wit_world/imports/backend.py

API Design

Extract backend logic from internal fastly_compute.requests.backend module into public fastly_compute.backend:

  • Implement Backend resource wrapper around WIT Backend
  • Static backends: Backend.open(name)
  • Dynamic backends: Backend.create_dynamic(target, **options) for simple cases
  • Advanced config: Backend.register_dynamic(name, DynamicBackendConfig(...)) with dataclass for all WIT options (TLS, certs, timeouts, pooling, keepalive, gRPC)
  • Introspection properties: name, health, is_dynamic, host, port, connect_timeout (as timedelta), TLS settings
  • Use TLSVersion enum (V1_0, V1_1, V1_2, V1_3) and BackendHealth enum (UNKNOWN, HEALTHY, UNHEALTHY)
  • Existing requests facade continues working unchanged (uses new module internally)

Cross-SDK Comparison: Rust uses builder pattern for dynamic backends, Go uses simple factory functions with struct fields, JS uses constructor config object. Python should use DynamicBackendConfig dataclass (more Pythonic than builder).

Viceroy Testing

Viceroy supports backend configuration via viceroy.toml and dynamic backend registration. Tests can verify SDK wrapper logic (property conversion, enum mapping, error handling), but actual backend requests require mock server or real endpoints.

Reference

主要语言
Python
星标
5
派生
1
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

fastly/compute-sdk-python 的其他 Issue

查看 fastly/compute-sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。