E2bEx.Templates (E2bEx v0.1.0)

Copy Markdown View Source

Template operations.

Every function takes an E2bEx.Client as the first argument. create/2 and update/3 return the raw decoded response map (the API returns minimal, build-oriented payloads there); get/2 and list/2 return E2bEx.Template structs.

Summary

Functions

Get structured build logs (GET /templates/:id/builds/:build_id/logs).

Get build status and logs (GET /templates/:id/builds/:build_id/status).

Create a template (POST /v3/templates).

Delete a template (DELETE /templates/:id).

Check whether a build-cache file exists (GET /templates/:id/files/:hash).

Get a template with its builds (GET /templates/:id).

Look up a template by alias (GET /templates/aliases/:alias).

List templates (GET /templates).

Start a build for a template (POST /v2/templates/:id/builds/:build_id).

Update a template (PATCH /v2/templates/:id).

Functions

build_logs(client, template_id, build_id, opts \\ [])

@spec build_logs(E2bEx.Client.t(), String.t(), String.t(), keyword()) ::
  {:ok, [map()]} | {:error, E2bEx.Error.t()}

Get structured build logs (GET /templates/:id/builds/:build_id/logs).

Options (query): :cursor, :limit, :direction, :level, :source.

Returns the raw list of BuildLogEntry maps.

build_status(client, template_id, build_id, opts \\ [])

@spec build_status(E2bEx.Client.t(), String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, E2bEx.Error.t()}

Get build status and logs (GET /templates/:id/builds/:build_id/status).

Options (query): :logs_offset, :logs_limit, :level.

Returns the raw TemplateBuildInfo map (status, logs, logEntries, reason).

create(client, params)

@spec create(E2bEx.Client.t(), map()) :: {:ok, map()} | {:error, E2bEx.Error.t()}

Create a template (POST /v3/templates).

params is a map matching the OpenAPI TemplateBuildRequestV3 schema, e.g. %{name: "my-tmpl", cpuCount: 2}. Returns the raw response map containing templateID, buildID, etc.

delete(client, template_id)

@spec delete(E2bEx.Client.t(), String.t()) :: :ok | {:error, E2bEx.Error.t()}

Delete a template (DELETE /templates/:id).

file_exists?(client, template_id, hash)

@spec file_exists?(E2bEx.Client.t(), String.t(), String.t()) ::
  {:ok, boolean()} | {:error, E2bEx.Error.t()}

Check whether a build-cache file exists (GET /templates/:id/files/:hash).

Returns {:ok, true} on success, {:ok, false} on 404, and {:error, %Error{}} for any other failure.

get(client, template_id)

@spec get(E2bEx.Client.t(), String.t()) ::
  {:ok, E2bEx.Template.t()} | {:error, E2bEx.Error.t()}

Get a template with its builds (GET /templates/:id).

get_by_alias(client, alias_name)

@spec get_by_alias(E2bEx.Client.t(), String.t()) ::
  {:ok, E2bEx.TemplateAlias.t()} | {:error, E2bEx.Error.t()}

Look up a template by alias (GET /templates/aliases/:alias).

list(client, opts \\ [])

@spec list(
  E2bEx.Client.t(),
  keyword()
) :: {:ok, [E2bEx.Template.t()]} | {:error, E2bEx.Error.t()}

List templates (GET /templates).

Options (query): :team_id.

trigger_build(client, template_id, build_id, params \\ %{})

@spec trigger_build(E2bEx.Client.t(), String.t(), String.t(), map()) ::
  :ok | {:error, E2bEx.Error.t()}

Start a build for a template (POST /v2/templates/:id/builds/:build_id).

params matches the OpenAPI TemplateBuildStartV2 schema, e.g. %{fromImage: "ubuntu:22.04", steps: [...]}. Returns :ok on 202.

update(client, template_id, params)

@spec update(E2bEx.Client.t(), String.t(), map()) ::
  {:ok, map()} | {:error, E2bEx.Error.t()}

Update a template (PATCH /v2/templates/:id).

params matches the OpenAPI TemplateUpdateRequest schema, e.g. %{public: true}. Returns the raw response map.