mix templates.upgrade.http (GenServerVirtualTime v0.6.1)

Copy Markdown View Source

The one part of mix templates.upgrade that needs the network: an HTTP GET with certificate verification, plus a token when one is in the environment.

It lives in its own module so the task around it stays testable: everything here is either a request (which cannot run in a test) or the request's configuration (which can, and which is worth pinning — asking for a package version over an unverified TLS connection is not something to leave to a default).

Anonymous GitHub API requests are limited to 60 per hour and the task makes about a dozen, so GH_TOKEN or GITHUB_TOKEN is used when set.

Summary

Functions

Fetches url, returning its body or an error.

The request headers, including an authorization header when GH_TOKEN or GITHUB_TOKEN is set.

The request options: timeouts, and peer verification against the certificates OTP ships with.

Functions

get(url)

@spec get(String.t()) :: {:ok, binary()} | {:error, term()}

Fetches url, returning its body or an error.

The body is returned as received; parsing is ActorSimulation.TemplateVersions.Upgrade's job.

headers()

@spec headers() :: [{charlist(), charlist()}]

The request headers, including an authorization header when GH_TOKEN or GITHUB_TOKEN is set.

options()

@spec options() :: keyword()

The request options: timeouts, and peer verification against the certificates OTP ships with.