# `Huginn.Clickhouse.Config`
[🔗](https://github.com/nyo16/huginn/blob/v0.6.0/lib/huginn/clickhouse/config.ex#L1)

Configuration for a ClickHouse gRPC connection pool.

Supports both password and JWT authentication methods. A config is built with
`new/1` and started as a pool with `Huginn.child_spec/1` (or
`Huginn.Clickhouse.Pool`), which registers it under its `:pool_name` so that
queries routed to that pool use its database and credentials.

The `:auth` field is excluded from `inspect/2` output so credentials never
end up in logs or crash reports.

## Examples

    # Password authentication
    config = Huginn.Clickhouse.Config.new(
      host: "localhost",
      port: 9100,
      database: "default",
      auth: {:password, "default", "secret"}
    )

    # JWT authentication
    config = Huginn.Clickhouse.Config.new(
      host: "localhost",
      port: 9100,
      database: "default",
      auth: {:jwt, "eyJ..."}
    )

# `auth`

```elixir
@type auth() :: {:password, String.t(), String.t()} | {:jwt, String.t()}
```

# `t`

```elixir
@type t() :: %Huginn.Clickhouse.Config{
  auth: auth() | nil,
  database: String.t(),
  host: String.t(),
  pool_name: atom(),
  pool_size: pos_integer(),
  port: pos_integer(),
  ssl: boolean() | keyword()
}
```

# `auth_opts`

```elixir
@spec auth_opts(t()) :: keyword()
```

Extracts authentication credentials for query building.

# `default_pool`

```elixir
@spec default_pool() :: atom()
```

Returns the name of the default pool: the `:pool_name` of the
`:huginn, :clickhouse` application config, or `:clickhouse_pool`.

# `fetch`

```elixir
@spec fetch(atom()) :: {:ok, t()} | {:error, Huginn.Error.t()}
```

Returns the config registered for `pool_name` by `Huginn.Clickhouse.Pool`.

# `new`

```elixir
@spec new(keyword() | map()) :: t()
```

Creates a new config struct from a keyword list or a map.

Raises `ArgumentError` when an option is missing, unknown or invalid. Error
messages name the offending option but never include option values, so
credentials cannot leak through a configuration error.

## Options

  * `:host` - ClickHouse server host (required)
  * `:port` - gRPC port (default: 9100)
  * `:database` - Default database for queries on this pool (default: "default")
  * `:auth` - Authentication tuple: `{:password, user, pass}` or `{:jwt, token}`
  * `:pool_size` - Connection pool size (default: 5)
  * `:pool_name` - Pool name for registration (default: :clickhouse_pool)
  * `:ssl` - `false` (default) for plaintext h2c, `true` to enable TLS with
    peer verification against the system CA store, or a keyword list of
    `:ssl` options (e.g. `[cacertfile: "/ca.pem"]`) for custom CAs or client
    certificates. A keyword list without `:verify` gets `verify: :verify_peer`,
    the system CA store (unless `:cacerts`/`:cacertfile` is given) and HTTPS
    hostname checking merged underneath it; your keys always win. Pass
    `verify: :verify_none` explicitly to opt out of verification.

## Examples

    Huginn.Clickhouse.Config.new(host: "localhost")
    Huginn.Clickhouse.Config.new(%{host: "localhost", database: "analytics"})

# `to_pool_config`

```elixir
@spec to_pool_config(t()) :: keyword()
```

Converts config to GrpcConnectionPool keyword list format.

Raises `ArgumentError` when `ssl: true` cannot produce a peer-verifying TLS
configuration on the running OTP release.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
