UniFi Network API — ACL rule management.
Create, read, update, delete, and reorder access control list rules.
ACL rule fields
type—"IPV4"or"MAC"id,name,description,enabled,indexaction—"ALLOW"or"BLOCK"enforcingDeviceFilter,sourceFilter,destinationFilterprotocolFilter,networkId,metadata
Summary
Functions
Creates a new ACL rule.
Deletes an ACL rule.
Gets a specific ACL rule.
Gets the current ACL rule ordering.
Lists all ACL rules on a site.
Returns a lazy stream that auto-paginates through all ACL rules.
Updates an existing ACL rule.
Updates the ACL rule ordering.
Functions
@spec create(Req.Request.t(), String.t(), map()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Creates a new ACL rule.
Examples
{:ok, rule} = UnifiApi.Network.ACL.create(client, site_id, %{
type: "IPV4",
name: "Block SSH",
enabled: true,
action: "BLOCK",
protocolFilter: %{protocol: "TCP", dstPort: 22}
})
@spec delete(Req.Request.t(), String.t(), String.t()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Deletes an ACL rule.
Examples
{:ok, _} = UnifiApi.Network.ACL.delete(client, site_id, rule_id)
@spec get(Req.Request.t(), String.t(), String.t()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Gets a specific ACL rule.
Examples
{:ok, rule} = UnifiApi.Network.ACL.get(client, site_id, rule_id)
rule["action"] # => "BLOCK"
rule["type"] # => "IPV4"
@spec get_ordering(Req.Request.t(), String.t()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Gets the current ACL rule ordering.
Examples
{:ok, ordering} = UnifiApi.Network.ACL.get_ordering(client, site_id)
# => %{"ids" => ["rule-1", "rule-2", "rule-3"]}
@spec list(Req.Request.t(), String.t(), keyword()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Lists all ACL rules on a site.
Options
Supports pagination: :offset, :limit, :filter.
Examples
{:ok, rules} = UnifiApi.Network.ACL.list(client, site_id)
@spec stream(Req.Request.t(), String.t(), keyword()) :: Enumerable.t()
Returns a lazy stream that auto-paginates through all ACL rules.
Error contract
A mid-stream error does not raise by default: the stream halts and
yields {:error, %UnifiApi.StreamError{}, last_offset} as its final
element, so the enumerable is heterogeneous. Match the tail:
case Enum.to_list(stream) do
items when is_list(items) ->
case List.last(items) do
{:error, error, cursor} -> {:error, error, cursor}
_ -> {:ok, items}
end
endPass raise_errors: true to raise UnifiApi.StreamError instead.
Options
:max_pages— halt after this many successful pages (default: unbounded).:max_items— halt once this many items have been yielded (default: unbounded).:raise_errors— raiseUnifiApi.StreamErroron error instead of yielding the error tuple (default:false).
Examples
UnifiApi.Network.ACL.stream(client, site_id, raise_errors: true)
|> Stream.filter(& &1["enabled"])
|> Enum.to_list()
@spec update(Req.Request.t(), String.t(), String.t(), map()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Updates an existing ACL rule.
Examples
{:ok, _} = UnifiApi.Network.ACL.update(client, site_id, rule_id, %{enabled: false})
@spec update_ordering(Req.Request.t(), String.t(), map()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Updates the ACL rule ordering.
Examples
{:ok, _} = UnifiApi.Network.ACL.update_ordering(client, site_id, %{
ids: ["rule-3", "rule-1", "rule-2"]
})