ExAtlas.Config (ExAtlas v0.5.0)

Copy Markdown View Source

Resolves which provider and which API key a call should use.

Resolution order

For the provider:

  1. opts[:provider] if present.
  2. Application.get_env(:ex_atlas, :default_provider).
  3. Raises ArgumentError.

For the API key (per provider):

  1. opts[:api_key] if present.
  2. Application.get_env(:ex_atlas, provider)[:api_key].
  3. Environment variable (e.g. RUNPOD_API_KEY, LAMBDA_LABS_API_KEY).
  4. nil (providers decide whether to raise).

This mirrors the stripity_stripe / ex_aws pattern: per-call overrides win, application config is the default, no global mutable state. Multi-tenant hosts pass api_key: per request and skip config entirely.

Configuring the default provider

# config/config.exs
config :ex_atlas,
  default_provider: :runpod,
  start_orchestrator: false

config :ex_atlas, :runpod, api_key: System.get_env("RUNPOD_API_KEY")
config :ex_atlas, :lambda_labs, api_key: System.get_env("LAMBDA_LABS_API_KEY")

Summary

Functions

Build the ctx map passed to every provider callback.

Map of built-in provider atoms to their implementing modules.

Standard environment variable name for a provider's API key.

Pop :provider from opts and return {provider_atom_or_module, remaining_opts}.

Resolve the module that implements ExAtlas.Provider for a given provider atom.

Types

opts()

@type opts() :: keyword()

Functions

build_ctx(provider, opts)

@spec build_ctx(atom() | module(), opts()) :: ExAtlas.Provider.ctx()

Build the ctx map passed to every provider callback.

Resolves the API key and any Req overrides in one place.

builtin_providers()

@spec builtin_providers() :: %{required(atom()) => module()}

Map of built-in provider atoms to their implementing modules.

env_var(provider)

@spec env_var(atom()) :: String.t() | nil

Standard environment variable name for a provider's API key.

pop_provider!(opts)

@spec pop_provider!(opts()) :: {atom() | module(), opts()}

Pop :provider from opts and return {provider_atom_or_module, remaining_opts}.

provider_module(provider)

@spec provider_module(atom() | module()) :: module()

Resolve the module that implements ExAtlas.Provider for a given provider atom.