> ## 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.

# 어댑터

> 모든 커넥터가 구현하는 Validate와 Execute 메서드, 그리고 워커가 재시도 여부를 판단하는 오류 규칙

어댑터는 모든 커넥터가 반드시 작성해야 하는 유일한 코드입니다. 두 메서드를 구현하는 것 외에는 아무것도 하지 않습니다. 수명 주기, 연결, 스트림 관리도 없습니다.

```go theme={null}
package connector

import "context"

// Adapter is the tool-specific implementation that each connector provides.
type Adapter interface {
    Validate(ctx context.Context, inputs map[string]any) error
    Execute(ctx context.Context, inputs map[string]any, out chan<- Finding) error
}
```

## `Validate`

컨테이너나 네트워크 리소스를 쓰기 **전에**, 도구가 도저히 실행할 수 없는 입력을 거부합니다.

```go theme={null}
func (a *MyAdapter) Validate(ctx context.Context, inputs map[string]any) error
```

* 실행 전에 동작합니다. 가볍게 유지하세요. 네트워크 호출이나 프로세스 생성은 하지 마세요.
* 실행을 막으려면 오류를 반환하고, 허용하려면 `nil`을 반환합니다.
* 커넥터의 `inputsSchema`에 대한 상위 검증은 이미 워커에서 실행되므로, 이것은 스키마로 표현할 수 없는 것에 대한 두 번째 방어선입니다.

```go theme={null}
func (a *MyAdapter) Validate(_ context.Context, inputs map[string]any) error {
    target, _ := inputs["target"].(string)
    if strings.TrimSpace(target) == "" {
        return fmt.Errorf("fatal: target is required")
    }
    return nil
}
```

## `Execute`

도구를 실행하고 발견 사항을 `out`으로 스트리밍합니다.

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

규칙:

* **버퍼링하지 말고 스트리밍하세요.** 발견 사항이 생기는 대로 `out`으로 보내세요. 긴 스캔은 끝나기 전에 결과를 반환해야 합니다.
* **취소를 존중하세요.** `ctx.Done()`이 닫히면 멈추세요. 런타임은 실행 도중에 취소할 수 있습니다. 보낼 때 `ctx.Done()`에 대해 `select`하세요.
* **`out`을 절대 닫지 마세요.** 채널은 런타임이 소유합니다.
* 도구별 코드는 이 패키지에만 두세요.

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

    findings, err := a.runTool(ctx, target) // your tool
    if err != nil {
        return fmt.Errorf("retryable: run tool: %w", err)
    }
    for _, raw := range findings {
        f, mapErr := toFinding(raw) // map scanner output -> connector.Finding
        if mapErr != nil {
            continue // skip unparseable items rather than failing the run
        }
        select {
        case out <- f:
        case <-ctx.Done():
            return ctx.Err()
        }
    }
    return nil
}
```

## 오류 규칙

워커는 오류의 접두사로 재시도 여부를 결정합니다. 반환하는 모든 오류에 접두사를 붙이세요.

| 접두사 | 의미 | 예시 |
| - | - | - |
| `fatal: ` | 구성, 자격 증명 또는 대상 문제. 재시도해도 소용없습니다. | 대상 누락, 잘못된 API 토큰, 형식이 잘못된 입력. |
| `retryable: ` | 일시적인 실패. 워커가 재시도할 수 있습니다. | 연결 시간 초과, 도구 충돌, 네트워크 오류, 취소. |

SDK는 자신이 발생시키는 오류에 접두사를 붙입니다. 접두사가 없는 오류는 재시도 가능으로 처리됩니다.

```go theme={null}
return fmt.Errorf("fatal: invalid credentials: %w", err)
return fmt.Errorf("retryable: scanner exited: %w", err)
```

## 어댑터 감싸기

`connector.New`는 런타임이 어댑터를 구동할 수 있도록 감쌉니다. `Validate`나 `Execute`를 직접 호출하지 않습니다.

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

conn := sdkconn.New(&MyAdapter{})
```

## 설계 노트

* 도구가 라이브러리를 제공한다면 **CLI 래퍼보다 프로세스 내 임베딩을 선호하세요.** 하위 프로세스 수명 주기도, 출력 형식 변화도 없고, 취소도 자연스럽게 전파됩니다.
* **원격 API 도구는 번들 바이너리를 포함하지 않습니다.** 어댑터가 클라이언트이며, 자격 증명은 코드나 이미지가 아니라 `configSchema`에 둡니다.
* **심각도는 문자열 추측이 아니라 조회 테이블로 명시적으로 매핑하세요.** [Finding](https://docs.oasm.io/ko/connectors/finding.md)을 참고하세요.
* **비밀 값을 발견 사항이나 로그에 절대 유출하지 마세요.** 발견 사항은 저장되고 표시되지만, 구성 값은 그렇지 않습니다.


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