> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oasm.io/llms.txt
> Use this file to discover all available pages before exploring further.

# 输入与配置

> 每次运行的输入和工具配置档案如何传递到你的适配器

连接器从不通过命令行参数或文件进行配置。输入和配置通过 `Execute` 以及 Worker 注入的环境变量传入。

## 在 `Execute` 中读取输入

你的适配器直接以参数形式接收 `inputs map[string]any`。请从中读取值；除非需要环境变量默认值，否则不要自行读取 `INPUT_*`。

```go theme={null}
func (a *MyAdapter) Execute(ctx context.Context, inputs map[string]any, out chan<- connector.Finding) error {
    target, _ := inputs["target"].(string)
    // ...
}
```

## `INPUT_*` 默认值

`env.LoadInputs()` 读取所有 `INPUT_*` 环境变量并以 map 形式返回。键会去掉前缀并转为小写。

| 环境变量 | 转换为 |
| - | - |
| `INPUT_TARGET` | `inputs["target"]` |
| `INPUT_SOME_KEY` | `inputs["some_key"]` |

```go theme={null}
import "github.com/oasm-platform/oasm-connectors/sdk/env"

defaults := env.LoadInputs()
```

**优先级：** Worker 提供的每个任务的输入会覆盖 `INPUT_*` 环境变量默认值。你的适配器收到的 `inputs` map 已合并了两者，以 Worker 提供的值为准。

> [!NOTE]
>
> 运行时会在调用你的适配器之前合并这两个来源，因此在生产代码中很少需要 `env.LoadInputs()`。它在 Worker 之外手动运行连接器时很有用。

## 配置档案（`OASM_CONFIG`）

`configSchema` 的值以 JSON 字符串的形式通过 `OASM_CONFIG` 环境变量传递。请 **在执行时** 读取，而不是在启动时。

> [!WARNING]
>
> 被复用于第二个任务的容器，其 `OASM_CONFIG` 会在每次执行前后被替换。在 `main` 或包级 `init` 中读取会得到过期的配置，请始终在 `Execute` 内读取。

```go theme={null}
type Config struct {
    Severity []string `json:"severity"`
    RateLimit *int    `json:"rateLimit"`
}

func parseConfig(raw string) (Config, error) {
    if strings.TrimSpace(raw) == "" {
        return Config{}, nil
    }
    var cfg Config
    if err := json.Unmarshal([]byte(raw), &cfg); err != nil {
        return Config{}, err
    }
    return cfg, nil
}

func (a *MyAdapter) Execute(ctx context.Context, inputs map[string]any, out chan<- connector.Finding) error {
    cfg, err := parseConfig(os.Getenv("OASM_CONFIG"))
    if err != nil {
        return fmt.Errorf("fatal: invalid OASM_CONFIG: %w", err)
    }
    _ = cfg
    // ...
}
```

对可选的数值或布尔字段使用指针，以便区分"未提供"和零值；当字段为 nil 时，回退到 manifest 中的 `default`。

## 环境变量

| 变量 | 用途 |
| - | - |
| `INPUT_*` | 每次运行的输入默认值。`INPUT_TARGET` → `inputs["target"]`。 |
| `OASM_CONFIG` | 任务的配置档案（JSON）。在执行时读取。 |
| `LOG_LEVEL` / `OASM_LOG_LEVEL` | 设为 `debug` 可输出详细跟踪信息（每条结果一行、已发出发现的预览）。INFO 及以上级别始终开启。 |
| `OASM_LOG_COLOR` | `always` 强制使用 ANSI 颜色，`never` 去除颜色。未设置时仅在终端中使用颜色。 |

> [!NOTE]
>
> 连接变量（`WORKER_GRPC_ADDR`、`WORKER_TOKEN`、mTLS 路径）由 Worker 注入，并完全由 SDK 使用。你的适配器从不读取或设置它们。

## 相关内容

> [card] [manifest.yaml](https://docs.oasm.io/zh/connectors/manifest.md)
>
> 声明 `inputsSchema` 和 `configSchema`。

> [card] [Adapter](https://docs.oasm.io/zh/connectors/adapter.md)
>
> 输入和配置被使用的地方。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.