Sprites.Policy (Sprites v0.1.0)

View Source

Network policy management for sprites.

Summary

Functions

Network policy containing a list of rules.

Creates a network policy from a map.

Gets the current network policy for a sprite.

Gets the current network policy for a sprite by name.

Converts a network policy to a map for JSON encoding.

Updates the network policy for a sprite.

Updates the network policy for a sprite by name.

Types

t()

@type t() :: %Sprites.Policy{rules: [Sprites.Policy.Rule.t()]}

Functions

%Sprites.Policy{}

(struct)

Network policy containing a list of rules.

Fields

from_map(map)

@spec from_map(map()) :: t()

Creates a network policy from a map.

get(sprite)

@spec get(Sprites.Sprite.t()) :: {:ok, t()} | {:error, term()}

Gets the current network policy for a sprite.

Examples

{:ok, policy} = Sprites.Policy.get(sprite)

get_by_name(client, name)

@spec get_by_name(Sprites.Client.t(), String.t()) :: {:ok, t()} | {:error, term()}

Gets the current network policy for a sprite by name.

to_map(policy)

@spec to_map(t()) :: map()

Converts a network policy to a map for JSON encoding.

update(sprite, policy)

@spec update(Sprites.Sprite.t(), t()) :: :ok | {:error, term()}

Updates the network policy for a sprite.

Examples

policy = %Sprites.Policy{
  rules: [
    %Sprites.Policy.Rule{domain: "example.com", action: "allow"},
    %Sprites.Policy.Rule{domain: "blocked.com", action: "deny"}
  ]
}
:ok = Sprites.Policy.update(sprite, policy)

update_by_name(client, name, policy)

@spec update_by_name(Sprites.Client.t(), String.t(), t()) :: :ok | {:error, term()}

Updates the network policy for a sprite by name.