Shared utility functions used across PhoenixGenApi modules.
This module centralizes common logic that was previously duplicated across ConfigPuller, ConfigReceiver, PushConfig, FunConfig, and NodeSelector.
Summary
Functions
Enforces that a FunConfig's service name matches the expected service.
Ensures a FunConfig has a version string, defaulting to "0.0.0".
Validates that a value is a valid node identifier.
Compares two service names for equality, handling atom↔string comparisons.
Validates a list of nodes, filtering out invalid entries.
Functions
@spec enforce_service_name(PhoenixGenApi.Structs.FunConfig.t(), atom() | String.t()) :: PhoenixGenApi.Structs.FunConfig.t()
Enforces that a FunConfig's service name matches the expected service.
If the service names don't match, logs a warning and overwrites the FunConfig's service with the expected service name.
Parameters
config- A%FunConfig{}structservice_name- The expected service name (atom or string)
Returns
The FunConfig with the correct service name.
@spec ensure_version(PhoenixGenApi.Structs.FunConfig.t()) :: PhoenixGenApi.Structs.FunConfig.t()
Ensures a FunConfig has a version string, defaulting to "0.0.0".
If the FunConfig's version is nil or empty, sets it to "0.0.0".
Parameters
config- A%FunConfig{}struct
Returns
The FunConfig with a guaranteed version string.
Validates that a value is a valid node identifier.
A valid node is either an atom (e.g., :node1@host) or a binary string
(e.g., "node1@host").
Examples
iex> is_valid_node?(:node1@host)
true
iex> is_valid_node?("node1@host")
true
iex> is_valid_node?(123)
false
Compares two service names for equality, handling atom↔string comparisons.
Service names can be atoms or strings throughout the system. This function
normalizes the comparison so that :my_service and "my_service" are
considered the same service.
Examples
iex> same_service?(:my_service, "my_service")
true
iex> same_service?("my_service", :my_service)
true
iex> same_service?(:my_service, :other_service)
false
Validates a list of nodes, filtering out invalid entries.
Parameters
nodes- A list of potential node identifiers
Returns
A list containing only valid node identifiers.