Aker.Store behaviour (Aker v0.1.0)

Copy Markdown View Source

Where a host keeps its licence. The gate reads and writes it only through this behaviour, so the library takes no database dependency.

A record is any map or struct with :envelope (the licence file's bytes), :licence_id, :serial, :term_end and :last_seen_at. store/3's attributes add :customer_name, :seats, :features and :term_start.

The actor passes from the host's call to store/3 untouched; the gate never reads it. A renewal stores as :system. The store decides who may write, and answers {:error, :forbidden} to anyone else.

Each callback gets the opts of the gate's store: {module, opts}.

Summary

Callbacks

The newest licence by serial, nil when none is stored.

Stores a licence that passed every check.

Moves the latest time seen on record.

Types

record()

@type record() :: map()

Callbacks

current(opts)

@callback current(opts :: keyword()) :: {:ok, record() | nil} | {:error, term()}

The newest licence by serial, nil when none is stored.

store(attrs, actor, opts)

@callback store(attrs :: map(), actor :: term(), opts :: keyword()) ::
  {:ok, record()} | {:error, :forbidden} | {:error, :not_stored}

Stores a licence that passed every check.

touch(record, last_seen_at, opts)

@callback touch(record(), last_seen_at :: DateTime.t(), opts :: keyword()) ::
  {:ok, record()} | {:error, term()}

Moves the latest time seen on record.