Validated configuration — and the client handle you pass to every API call.
A %Config{} is cheap, immutable, and stateless: build it once and hand it to
GcpCompute.Instances/GcpCompute.Operations (or the GcpCompute facade).
There is no process to supervise — Req manages connection pooling under the
hood.
Building a config
# Production: tokens minted by Goth
{:ok, config} =
GcpCompute.Config.production(
project: "my-project",
zone: "us-central1-a",
goth: MyApp.Goth
)
# From application env
{:ok, config} = GcpCompute.Config.from_env(:my_app, :gcp_compute)
# Local / emulator / tests (static token)
{:ok, config} = GcpCompute.Config.local(project: "my-project")Options
:project(String.t/0) - Required. GCP project id.:zone(String.t/0) - Default zone for zonal operations. The default value is"us-central1-a".:token_provider- A{module, arg}implementingGcpCompute.TokenProvider. The default value is{GcpCompute.TokenProvider.Goth, GcpCompute.Goth}.:base_url(String.t/0) - Compute API base URL. Override for the emulator or a proxy. The default value is"https://compute.googleapis.com/compute/v1".:req_options(keyword/0) - Extra options merged into everyReqrequest (e.g.:adapterfor tests,:retry). Treated as trusted application config: the request:method,:url, and:authare always computed by the library and layered on top, soreq_optionscannot override the target URL or drop the bearer token. It can still set transport and connection options (:connect_options, includingverify) — that is the app owner's choice, not attacker-controlled input. The default value is[].:allow_insecure(boolean/0) - Permit a non-https://:base_url. Off by default: a bearer token is never sent in cleartext unless you explicitly opt in. Settrueonly for a local emulator/proxy on a trusted network (local/1sets it for you). Independent of the token provider — even aStatictoken stays TLS-only unless this is set. The default value isfalse.
Summary
Functions
Fetch a fresh access token using the configured GcpCompute.TokenProvider.
Load options from application env and build a config.
Build a config for local development, the emulator, or tests.
Same as local/1 but raises on invalid options.
Build and validate a config from a keyword list.
Same as new/1 but raises ArgumentError on invalid options.
Build a production config that mints tokens via Goth.
Types
Functions
@spec fetch_token(t()) :: {:ok, GcpCompute.TokenProvider.token()} | {:error, term()}
Fetch a fresh access token using the configured GcpCompute.TokenProvider.
Load options from application env and build a config.
config :my_app, :gcp_compute,
project: "my-project",
zone: "europe-west4-a",
token_provider: {GcpCompute.TokenProvider.Goth, MyApp.Goth}
{:ok, config} = GcpCompute.Config.from_env(:my_app, :gcp_compute)
Build a config for local development, the emulator, or tests.
Defaults to a Static token provider so you never touch Goth. Pass :token
to set the static token (default "local-token"), and :base_url to point at
an emulator. Defaults allow_insecure: true so an http:// emulator URL works
out of the box — override it to false to force TLS even locally.
{:ok, config} = GcpCompute.Config.local(project: "p", base_url: "http://localhost:8080/compute/v1")
Same as local/1 but raises on invalid options.
Build and validate a config from a keyword list.
Returns {:ok, config} or {:error, message} with a precise validation
message.
Same as new/1 but raises ArgumentError on invalid options.
Build a production config that mints tokens via Goth.
Pass :goth (the registered Goth name) instead of :token_provider.
{:ok, config} = GcpCompute.Config.production(project: "p", goth: MyApp.Goth)Uses a Goth token provider with allow_insecure defaulting to false, so
new/1's https rule applies: the :base_url must be https:// and a bearer
token can't be sent in cleartext.