Noizu.Comms.Config (noizu_comms v0.1.0)

Copy Markdown View Source

Targets file: named aliases and webhook env-var indirection.

Loaded from COMMS_TARGETS_FILE (default ~/.config/noizu-comms/targets.yaml; precedence: load/1 :file opt > app env :noizu_comms, :targets_file > env var > default).

targets:
  ops-alerts:   { uri: "discord://channel/123456789012345678", allow_write: true }
  releases:     { uri: "slack://channel/C0123456", allow_write: true }
  keith-phone:  { uri: "whatsapp://15551234567", allow_write: false }
webhooks:        # alias -> env var NAME holding the URL (never the URL itself)
  discord:
    deploys: DISCORD_WEBHOOK_DEPLOYS

Token env vars (DISCORD_BOT_TOKEN, SLACK_BOT_TOKEN, TELEGRAM_BOT_TOKEN, WHATSAPP_ACCESS_TOKEN, WHATSAPP_PHONE_NUMBER_ID) belong to the SDKs and are never stored in the targets file.

Summary

Functions

An empty config (used when the targets file is absent/unreadable).

Loads and parses the targets YAML. A missing file is an error here —

Looks up an alias -> {:ok, entry} or {:error, %Error{kind: :not_configured}}.

Targets file path (see precedence in the moduledoc).

Resolves a webhook URL for channel + alias. The config stores the env var NAME; the URL itself is read from the environment at call time.

Types

t()

@type t() :: %Noizu.Comms.Config{
  path: String.t() | nil,
  targets: %{required(String.t()) => target_entry()},
  webhooks: %{required(String.t()) => %{required(String.t()) => String.t()}}
}

target_entry()

@type target_entry() :: %{uri: String.t(), allow_write: boolean()}

Functions

empty()

@spec empty() :: t()

An empty config (used when the targets file is absent/unreadable).

load(opts \\ [])

@spec load(keyword()) :: {:ok, t()} | {:error, Noizu.Comms.Error.t()}

Loads and parses the targets YAML. A missing file is an error here —

lookup(config, name)

@spec lookup(t(), String.t()) ::
  {:ok, target_entry()} | {:error, Noizu.Comms.Error.t()}

Looks up an alias -> {:ok, entry} or {:error, %Error{kind: :not_configured}}.

targets_file(opts \\ [])

@spec targets_file(keyword()) :: String.t()

Targets file path (see precedence in the moduledoc).

webhook_url(config, channel, alias_name)

@spec webhook_url(t() | nil, atom(), String.t()) ::
  {:ok, String.t()} | {:error, Noizu.Comms.Error.t()}

Resolves a webhook URL for channel + alias. The config stores the env var NAME; the URL itself is read from the environment at call time.