IMDS. Provider behaviour
(imds v1.0.0)
Copy Markdown
The behaviour every provider implements, plus the helpers they share.
Summary
Callbacks
Return the base URL of the metadata service.
Answer :ok when the current instance is of this provider.
Return the normalized identity of the instance.
Return the identifier of the provider.
Send one request to the metadata service and return the raw response.
Functions
Return the base URL of module, with a trailing / removed.
Decode a JSON body. An invalid body gives {:error, :decode_failed}.
Decode a JSON body that MUST hold an object.
Return the body of path when the provider answers with HTTP 200.
Return the body of path decoded as a JSON object.
Return the body of path with an empty body turned into nil.
Turn an instance identifier into a binary.
Turn an empty binary into nil.
Answer true when value holds only decimal digits.
Send method to path on the metadata service of module.
Return a copy of map with every empty binary value turned into nil.
Return the absolute URL of path on the base URL of module.
Check a metadata path.
Types
@type provider() ::
:aws
| :gce
| :azure
| :oracle
| :hetzner
| :scaleway
| :openstack
| :digital_ocean
| :akamai
| :vultr
@type reason() :: :not_detected | :token_failed | :decode_failed | :invalid_document | :invalid_path | :timeout | {:http, non_neg_integer()} | {:unknown_provider, term()} | term()
Callbacks
@callback default_base_url() :: binary()
Return the base URL of the metadata service.
@callback detect(keyword()) :: :ok | {:error, :not_detected}
Answer :ok when the current instance is of this provider.
Every other result means that the instance is not of this provider.
Return the normalized identity of the instance.
@callback name() :: provider()
Return the identifier of the provider.
@callback request(:get | :put, binary(), keyword()) :: {:ok, IMDS.HTTP.response()} | {:error, reason()}
Send one request to the metadata service and return the raw response.
A provider adds its own authentication to the request.
Functions
Return the base URL of module, with a trailing / removed.
Decode a JSON body. An invalid body gives {:error, :decode_failed}.
Decode a JSON body that MUST hold an object.
Return the body of path when the provider answers with HTTP 200.
Return the body of path decoded as a JSON object.
A body that is not a JSON object gives {:error, :decode_failed}.
Return the body of path with an empty body turned into nil.
A failed request gives nil, because a provider omits a field that the
metadata service does not report.
Turn an instance identifier into a binary.
A metadata service reports the identifier as a number or as a string. Any
other type, and nil, gives nil.
Turn an empty binary into nil.
The metadata services of the providers answer with an empty body or an empty JSON string for a field that does not exist.
Answer true when value holds only decimal digits.
@spec send_request(module(), :get | :put, binary(), keyword(), IMDS.HTTP.headers()) :: {:ok, IMDS.HTTP.response()} | {:error, term()}
Send method to path on the metadata service of module.
The provider gives its own headers. A :put request carries an empty body.
Return a copy of map with every empty binary value turned into nil.
Return the absolute URL of path on the base URL of module.
@spec validate_path(binary()) :: :ok | {:error, :invalid_path}
Check a metadata path.
A path MUST start with /. The path part before the query or the fragment
MUST NOT hold a . or .. segment, in plain or percent-encoded form.