Bunnyx.StorageZone (Bunnyx v0.3.1)

Copy Markdown View Source

Storage zones are the containers that hold files served through bunny.net's edge storage network. This module manages storage zones through the main API — creating, configuring, and deleting them.

This is separate from Bunnyx.Storage, which handles file operations (upload, download) within a storage zone using a different authentication method.

Uses the main API client created with Bunnyx.new/1.

Usage

client = Bunnyx.new(api_key: "sk-...")

{:ok, zone} = Bunnyx.StorageZone.create(client,
  name: "my-zone",
  region: "DE"
)

# For S3-compatible storage (requires S3 beta access):
{:ok, s3_zone} = Bunnyx.StorageZone.create(client,
  name: "my-s3-zone",
  region: "DE",
  storage_zone_type: 1
)

{:ok, zone} = Bunnyx.StorageZone.get(client, zone.id)
{:ok, page} = Bunnyx.StorageZone.list(client)
{:ok, zone} = Bunnyx.StorageZone.update(client, zone.id, rewrite_404_to_200: true)
{:ok, nil} = Bunnyx.StorageZone.delete(client, zone.id)

Summary

Functions

Checks if a storage zone name is available.

Creates a storage zone with the given attributes.

Deletes a storage zone.

Fetches a storage zone by ID.

Lists storage zones.

Resets the storage zone password.

Resets the storage zone read-only password.

Returns storage zone statistics.

Updates a storage zone.

Types

t()

@type t() :: %Bunnyx.StorageZone{
  custom_404_file_path: String.t() | nil,
  date_modified: String.t() | nil,
  deleted: boolean() | nil,
  files_stored: integer() | nil,
  id: pos_integer() | nil,
  name: String.t() | nil,
  password: String.t() | nil,
  read_only_password: String.t() | nil,
  region: String.t() | nil,
  replication_regions: [String.t()] | nil,
  rewrite_404_to_200: boolean() | nil,
  storage_hostname: String.t() | nil,
  storage_used: integer() | nil,
  storage_zone_type: integer() | nil,
  zone_tier: integer() | nil
}

Functions

check_availability(client, name)

@spec check_availability(Bunnyx.t() | keyword(), String.t()) ::
  {:ok, boolean()} | {:error, Bunnyx.Error.t()}

Checks if a storage zone name is available.

create(client, attrs)

@spec create(Bunnyx.t() | keyword(), Bunnyx.Params.attrs()) ::
  {:ok, t()} | {:error, Bunnyx.Error.t()}

Creates a storage zone with the given attributes.

Options

  • :name (required) — storage zone name
  • :region (required) — "DE", "NY", "LA", "SG", etc.
  • :zone_tier — storage tier (0=HDD, 1=SSD)
  • :storage_zone_type — S3 compatibility (0=Standard, 1=S3-compatible)
  • Other options: :replication_regions, :origin_url

S3-compatible zones

To create an S3-compatible storage zone, pass storage_zone_type: 1:

Bunnyx.StorageZone.create(client, name: "my-s3-zone", region: "DE", storage_zone_type: 1)

Note: S3 must be enabled for your bunny.net account. Standard zones use storage.bunnycdn.com while S3 zones use {region}-s3.storage.bunnycdn.com.

delete(client, id)

@spec delete(Bunnyx.t() | keyword(), pos_integer()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Deletes a storage zone.

get(client, id)

@spec get(Bunnyx.t() | keyword(), pos_integer()) ::
  {:ok, t()} | {:error, Bunnyx.Error.t()}

Fetches a storage zone by ID.

list(client, opts \\ [])

@spec list(
  Bunnyx.t() | keyword(),
  keyword()
) ::
  {:ok,
   [t()]
   | %{
       items: [t()],
       current_page: integer(),
       total_items: integer(),
       has_more_items: boolean()
     }}
  | {:error, Bunnyx.Error.t()}

Lists storage zones.

Options

  • :page — page number
  • :per_page — items per page
  • :search — search term
  • :include_deleted — include deleted zones

reset_password(client, id)

@spec reset_password(Bunnyx.t() | keyword(), pos_integer()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Resets the storage zone password.

reset_read_only_password(client, id)

@spec reset_read_only_password(Bunnyx.t() | keyword(), pos_integer()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Resets the storage zone read-only password.

statistics(client, id, opts \\ [])

@spec statistics(Bunnyx.t() | keyword(), pos_integer(), keyword()) ::
  {:ok, %{storage_used_chart: map(), file_count_chart: map()}}
  | {:error, Bunnyx.Error.t()}

Returns storage zone statistics.

Options

  • :date_from — start date (ISO 8601 string)
  • :date_to — end date (ISO 8601 string)

update(client, id, attrs)

@spec update(Bunnyx.t() | keyword(), pos_integer(), Bunnyx.Params.attrs()) ::
  {:ok, t()} | {:error, Bunnyx.Error.t()}

Updates a storage zone.