K8s.Client.Provider behaviour (k8s v2.7.0)

View Source

HTTP Request / Response provider behaviour

Summary

Callbacks

Perform HTTP requests and returns a stream of response chunks

Perform HTTP requests and stream response to another process

Perform websocket requests and returns a stream of response chunks

Perform websocket requests and returns a stream of response chunks

Functions

Generates HTTP headers from K8s.Conn.RequestOptions

Types

error_t()

@type error_t() :: {:error, K8s.Client.APIError.t() | K8s.Client.HTTPError.t()}

headers()

@type headers() :: [{header_name :: String.t(), header_value :: String.t()}]

http_chunk_t()

@type http_chunk_t() ::
  {:data | binary()}
  | {:status, integer()}
  | {:headers, headers()}
  | {:error, K8s.Client.HTTPError.t()}
  | :done

response_t()

@type response_t() :: success_t() | error_t()

send_callback()

@type send_callback() :: (any() -> :ok)

stream_response_t()

@type stream_response_t() :: stream_success_t() | error_t()

stream_success_t()

@type stream_success_t() :: {:ok, Enumerable.t(http_chunk_t() | websocket_chunk_t())}

stream_to_response_t()

@type stream_to_response_t() :: {:ok, send_callback()} | :ok | error_t()

success_t()

@type success_t() :: {:ok, [map()] | map() | reference() | binary() | [binary()]}

websocket_chunk_t()

@type websocket_chunk_t() ::
  {:stdout, binary()}
  | {:stderr, binary()}
  | {:error, binary()}
  | {:close, {integer(), binary()}}

websocket_response_t()

@type websocket_response_t() :: websocket_success_t() | error_t()

websocket_success_t()

@type websocket_success_t() ::
  {:ok, %{stdin: binary(), stderr: binary(), error: binary()}}

Callbacks

request(method, uri, body, headers, http_opts)

@callback request(
  method :: atom(),
  uri :: URI.t(),
  body :: binary(),
  headers :: list(),
  http_opts :: keyword()
) :: response_t()

Perform HTTP requests

stream(method, uri, body, headers, http_opts)

@callback stream(
  method :: atom(),
  uri :: URI.t(),
  body :: binary(),
  headers :: list(),
  http_opts :: keyword()
) :: stream_response_t()

Perform HTTP requests and returns a stream of response chunks

stream_to(method, uri, body, headers, http_opts, stream_to)

@callback stream_to(
  method :: atom(),
  uri :: URI.t(),
  body :: binary(),
  headers :: list(),
  http_opts :: keyword(),
  stream_to :: pid()
) :: stream_to_response_t()

Perform HTTP requests and stream response to another process

websocket_request(uri, headers, http_opts)

@callback websocket_request(
  uri :: URI.t(),
  headers :: list(),
  http_opts :: keyword()
) :: websocket_response_t()

Perform HTTP requests

websocket_stream(uri, headers, http_opts)

@callback websocket_stream(
  uri :: URI.t(),
  headers :: list(),
  http_opts :: keyword()
) :: stream_response_t()

Perform websocket requests and returns a stream of response chunks

websocket_stream_to(uri, headers, http_opts, stream_to)

@callback websocket_stream_to(
  uri :: URI.t(),
  headers :: list(),
  http_opts :: keyword(),
  stream_to :: pid()
) :: stream_to_response_t()

Perform websocket requests and returns a stream of response chunks

Functions

headers(opts)

@spec headers(K8s.Conn.RequestOptions.t()) :: keyword()

Generates HTTP headers from K8s.Conn.RequestOptions

  • Adds {:Accept, "application/json"} to all requests if the header is not set.

Examples

Sets Content-Type to application/json

iex> opts = %K8s.Conn.RequestOptions{headers: [Authorization: "Basic AF"]}
...> K8s.Client.HTTPProvider.headers(opts)
[Accept: "application/json", Authorization: "Basic AF"]