-module(acumen@fetch_authorization). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/acumen/fetch_authorization.gleam"). -export([build/3, response/2]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " Fetch an ACME authorization.\n" "\n" " After creating an order, fetch each authorization to see the available\n" " challenges for proving domain control.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " import acumen\n" " import acumen/authorization.{type Authorization}\n" " import acumen/fetch_authorization\n" "\n" " let assert Ok(#(resp, ctx)) = acumen.execute(\n" " ctx,\n" " build: fetch_authorization.build(auth_url, _, registered_key),\n" " send: httpc.send,\n" " )\n" "\n" " let assert Ok(auth) = fetch_authorization.response(resp, auth_url)\n" " ```\n" ). -file("src/acumen/fetch_authorization.gleam", 30). ?DOC(" Builds a signed POST-as-GET request to fetch an authorization.\n"). -spec build(acumen@url:url(), acumen:context(), acumen:registered_key()) -> {ok, gleam@http@request:request(binary())} | {error, acumen:acme_error()}. build(Url, Context, Key) -> acumen:build_fetch(Url, Context, Key). -file("src/acumen/fetch_authorization.gleam", 39). ?DOC(" Parses an authorization fetch response.\n"). -spec response(gleam@http@response:response(binary()), acumen@url:url()) -> {ok, acumen@authorization:authorization()} | {error, acumen:acme_error()}. response(Resp, Url) -> case erlang:element(2, Resp) of 200 -> acumen@authorization:parse_authorization_response(Resp, Url); _ -> {error, {invalid_response, acumen@internal@utils:unexpected_status_message( erlang:element(2, Resp) )}} end.