View Source ExAzureKeyVault.HTTPUtils (ex_azure_key_vault v2.2.0)

Internal module for returning HTTP utilities.

Link to this section Summary

Functions

Returns authorization header.

Returns "application/x-www-form-urlencoded" header.

Returns ssl options.

Returns basic error message for 4xx status codes.

Returns error message for 4xx status codes.

Returns basic error or :ok response.

Returns client error or :ok response.

Returns ok response.

Returns error message for server errors.

Returns error message for :nxdomain error.

Link to this section Functions

Link to this function

headers_authorization(bearer_token)

View Source
@spec headers_authorization(String.t()) :: list()

Returns authorization header.

examples

Examples

iex(1)> ExAzureKeyVault.HTTPUtils.headers_authorization("Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...")
["Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "Content-Type": "application/json; charset=utf-8"]
Link to this function

headers_form_urlencoded()

View Source
@spec headers_form_urlencoded() :: list()

Returns "application/x-www-form-urlencoded" header.

examples

Examples

iex(1)> ExAzureKeyVault.HTTPUtils.headers_form_urlencoded()
["Content-Type": "application/x-www-form-urlencoded"]
@spec options_ssl() :: list()

Returns ssl options.

examples

Examples

iex(1)> ExAzureKeyVault.HTTPUtils.options_ssl()
[ssl: [{:versions, [:'tlsv1.2']}]]
Link to this function

response_client_error(status, url)

View Source
@spec response_client_error(integer(), String.t()) :: {:error, String.t()} | nil

Returns basic error message for 4xx status codes.

examples

Examples

iex(1)> ExAzureKeyVault.HTTPUtils.response_client_error(401, "https://wrong-vault.vault.azure.net/secrets")
{:error, "Error: 401: https://wrong-vault.vault.azure.net/secrets"}
Link to this function

response_client_error(status, url, body)

View Source
@spec response_client_error(integer(), String.t(), String.t()) ::
  {:error, any()} | nil

Returns error message for 4xx status codes.

examples

Examples

iex(1)> ExAzureKeyVault.HTTPUtils.response_client_error(404, "", "{\"error_message\":\"Not found\"}")
{:error, %{"error_message" => "Not found"}}
Link to this function

response_client_error_or_ok(status, url)

View Source
@spec response_client_error_or_ok(integer(), String.t()) :: {:error, String.t()} | :ok

Returns basic error or :ok response.

examples

Examples

When is a client error.

iex(1)> ExAzureKeyVault.HTTPUtils.response_client_error_or_ok(401, "https://wrong-vault.vault.azure.net/secrets")
{:error, "Error: 401: https://wrong-vault.vault.azure.net/secrets"}

When is a redirection.

iex(1)> ExAzureKeyVault.HTTPUtils.response_client_error_or_ok(301, "https://wrong-vault.vault.azure.net/secrets")
:ok
Link to this function

response_client_error_or_ok(status, url, body)

View Source
@spec response_client_error_or_ok(integer(), String.t(), String.t()) ::
  {:error, String.t()} | {:ok, String.t()}

Returns client error or :ok response.

examples

Examples

When is a client error.

iex(1)> ExAzureKeyVault.HTTPUtils.response_client_error_or_ok(404, "", "{\"error_message\":\"Not found\"}")
{:error, %{"error_message" => "Not found"}}

When is a redirection.

iex(1)> ExAzureKeyVault.HTTPUtils.response_client_error_or_ok(301, "", "{}")
{:ok, %{}}
@spec response_ok(String.t()) :: {:ok, any()}

Returns ok response.

examples

Examples

iex(1)> ExAzureKeyVault.HTTPUtils.response_ok("{}")
{:ok, %{}}
Link to this function

response_server_error(reason)

View Source
@spec response_server_error(atom()) :: {:error, any()}

Returns error message for server errors.

examples

Examples

iex(1)> ExAzureKeyVault.HTTPUtils.response_server_error(:econnrefused)
{:error, :econnrefused}
Link to this function

response_server_error(atom, url)

View Source
@spec response_server_error(atom(), String.t()) :: {:error, String.t()}

Returns error message for :nxdomain error.

examples

Examples

iex(1)> ExAzureKeyVault.HTTPUtils.response_server_error(:nxdomain, "https://wrong-vault.vault.azure.net/secrets")
{:error, "Error: Couldn't resolve host name https://wrong-vault.vault.azure.net/secrets"}