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

# クイックスタート

> 最小限のコネクタを最初から最後まで作成します: モジュール、マニフェスト、アダプター、配線、イメージ

この手順では、`vulnerabilities` カテゴリに `example` というコネクタを追加します。`vulnerabilities` と `example` は、目的のカテゴリとスラッグに置き換えてください。

## 前提条件

* Go 1.26 以上
* [Task](https://taskfile.dev) 3.x
* Docker 20.10 以上（イメージのビルドと実行に使用）

## モジュールを作成する

ディレクトリは `<category>/<slug>` です。

```bash theme={null}
mkdir -p vulnerabilities/example
cd vulnerabilities/example
```

SDK を require する `go.mod` を作成し、`replace` でローカルのコピーを参照させます。

```go theme={null}
module github.com/oasm-platform/oasm-connectors/vulnerabilities/example

go 1.26

require github.com/oasm-platform/oasm-connectors/sdk v0.0.0

replace github.com/oasm-platform/oasm-connectors/sdk => ../../sdk
```

```bash theme={null}
GOWORK=off go mod tidy
```

## `manifest.yaml` を書く

```yaml theme={null}
name: Example
slug: example
version: 1.0.0
image: ghcr.io/oasm-platform/connector-example:1.0.0
author: 'you'
pricingTier: [free]
shortDescription: 'Example vulnerability scanner'
description: 'Scans a target for example findings.'
capabilities: [vulnerabilities]
inputsSchema:
  type: object
  required: [target]
  properties:
    target:
      type: string
      format: uri
      title: Scan target
      description: 'Target URL or hostname to scan.'
  additionalProperties: false
configSchema:
  type: object
  additionalProperties: false
  properties:
    severity:
      type: string
      enum: [info, low, medium, high, critical]
      title: Minimum severity
      default: high
```

すべてのフィールドについては [マニフェストのリファレンス](https://docs.oasm.io/ja/connectors/manifest.md) を参照してください。

## アダプターを書く

`adapter.go` は、ツール固有の唯一のコードです。

```go theme={null}
package main

import (
    "context"
    "fmt"
    "os"
    "strings"

    "github.com/oasm-platform/oasm-connectors/sdk/connector"
)

type ExampleAdapter struct{}

// Validate rejects inputs the tool cannot run.
func (a *ExampleAdapter) 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 runs the tool and streams findings to out.
func (a *ExampleAdapter) Execute(ctx context.Context, inputs map[string]any, out chan<- connector.Finding) error {
    target, _ := inputs["target"].(string)
    severity := os.Getenv("OASM_CONFIG") // parse in real connectors

    _ = severity
    for _, raw := range runTool(ctx, target) {
        f := connector.Finding{
            Name:     raw.Name,
            Severity: normalizeSeverity(raw.Severity),
            Host:     target,
        }
        select {
        case out <- f:
        case <-ctx.Done():
            return ctx.Err()
        }
    }
    return nil
}

func normalizeSeverity(s string) string {
    switch strings.ToLower(strings.TrimSpace(s)) {
    case "info", "low", "medium", "high", "critical":
        return strings.ToLower(strings.TrimSpace(s))
    default:
        return "info"
    }
}
```

[アダプターのリファレンス](https://docs.oasm.io/ja/connectors/adapter.md) と [Finding のリファレンス](https://docs.oasm.io/ja/connectors/finding.md) を参照してください。

## `main.go` を配線する

`main.go` はアダプターを構築してランタイムを起動するだけです。キャンセルされたコンテキストは正常終了として扱います。

```go theme={null}
package main

import (
    "context"
    "log"

    sdkconn "github.com/oasm-platform/oasm-connectors/sdk/connector"
    "github.com/oasm-platform/oasm-connectors/sdk/runtime"
)

func main() {
    conn := sdkconn.New(&ExampleAdapter{})
    rt := runtime.New(conn)

    log.Println("example connector starting...")
    if err := rt.Run(context.Background()); err != nil && err != context.Canceled {
        log.Fatalf("connector failed: %v", err)
    }
    log.Println("example connector stopped")
}
```

> [!NOTE]
>
> `runtime.New` から `Run` までの処理（接続、登録、ストリーム）はすべて SDK が担当します。設定する必要はありません。

## `Dockerfile` を書く

ビルドコンテキストは **リポジトリのルート** なので、`sdk/` とコネクタのディレクトリを明示的にコピーします。依存関係のレイヤーがキャッシュされるよう、まず両方の `go.mod`/`go.sum` をコピーします。

```dockerfile theme={null}
FROM golang:1.26-alpine AS builder
WORKDIR /src
COPY sdk/go.mod sdk/go.sum sdk/
COPY vulnerabilities/example/go.mod vulnerabilities/example/go.sum vulnerabilities/example/
RUN cd vulnerabilities/example && GOWORK=off go mod download
COPY sdk/ sdk/
COPY vulnerabilities/example/ vulnerabilities/example/
RUN cd vulnerabilities/example && CGO_ENABLED=0 GOWORK=off go build -trimpath -o /out/connector .

FROM alpine:3.20
COPY --from=builder /out/connector /usr/local/bin/connector
RUN adduser -D -u 10001 connector
USER 10001
ENTRYPOINT ["/usr/local/bin/connector"]
```

イメージはポートを公開したり、シェルを必要としたりしてはいけません。

## 再生成とテスト

```bash theme={null}
task manifest   # regenerate manifest.json
task test       # per-module tests
task vet        # per-module go vet
```

## 次のステップ

> [card] [ビルドとテスト](https://docs.oasm.io/ja/connectors/build-and-test.md)
>
> Task のコマンド、テストのルール、公開。

> [card] [入力と設定](https://docs.oasm.io/ja/connectors/inputs-and-config.md)
>
> 設定プロファイルを正しく読み取る。


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