z_config_files (zotonic_core v1.0.0-rc.17)
Generic support for finding and parsing config files.
Summary
Functions
Find the default directory for cache files. Checks the following locations
Find the directory with the configuration files. Defaults to the OS specific directory for all configurations. This checks a list of possible locations
Read a config file, return a list of the contents. The file can be in erlang, yaml, or json format.
Find the default directory for data files. Checks the following locations
List all (regular) files in a directory, skip hidden and temp files.
List all (regular) files in a directory, skip hidden and temp files. Ensures the list of files is sorted in a consistent way.
Find the default directory for log files. Checks the following locations
Find the default directory for certificates and other secrets. Checks the following locations
List all zotonic config files in the zotonic config directory and the "config.d" subdirectory for the current node. Zotonic config files are "zotonic.*" files in the root of the config directory and all files the 'config.d' subdirectory.
List all zotonic config files in the zotonic config directory and the "config.d" subdirectory. Zotonic config files are "zotonic.*" files in the root of the config directory and all files the 'config.d' subdirectory.
Functions
-spec cache_dir() -> {ok, file:filename_all()} | {error, term()}.
Find the default directory for cache files. Checks the following locations:
- The environment variable <tt>ZOTONIC_CACHE_DIR</tt>
- Local working directory <tt>caches</tt>
- The OS specific directory for application cache files
If no directory is found then the OS specific directory is used:
- Linux: <tt>$HOME/.cache/zotonic/</tt>
- macOS: <tt>$HOME/Library/Caches/zotonic/</tt>
-spec config_dir() -> {ok, file:filename_all()} | {error, term()}.
Find the directory with the configuration files. Defaults to the OS specific directory for all configurations. This checks a list of possible locations:
- The init argument <tt>zotonic_config_dir</tt>
- The environment variable <tt>ZOTONIC_CONFIG_DIR</tt>
- The directory <tt>$HOME/.zotonic</tt>
- The directory <tt>/etc/zotonic</tt> (only on Unix)
- The OS specific directory for application config files
In the last three cases subdirectories are also checked, in the following order:
- The complete Erlang node name
- The short node name without the server address
- The complete Zotonic version (eg. 1.2.3)
- The minor Zotonic version (eg. 1.2)
- The major Zotonic version (eg. 1)
- The directory itself, without any version
If no directory is found then the OS specific directory with the the major Zotonic version is used. Examples:
- Linux: <tt>$HOME/.config/zotonic/config/1/</tt>
- macOS: <tt>$HOME/Library/Application Support/zotonic/config/1/</tt>
-spec config_dir(node()) -> {ok, file:filename_all()} | {error, term()}.
-spec consult(file:filename_all()) -> {ok, [map() | proplists:proplist()]} | {error, term()}.
Read a config file, return a list of the contents. The file can be in erlang, yaml, or json format.
-spec data_dir() -> {ok, file:filename_all()} | {error, term()}.
Find the default directory for data files. Checks the following locations:
- The environment variable <tt>ZOTONIC_DATA_DIR</tt>
- Local working directory <tt>data</tt>
- The OS specific directory for application data files
If no directory is found then the OS specific directory is used:
- Linux: <tt>$HOME/.local/share/zotonic/</tt>
- macOS: <tt>$HOME/Library/Application Support/zotonic/</tt>
-spec files(file:filename_all()) -> [file:filename_all()].
List all (regular) files in a directory, skip hidden and temp files.
-spec files(file:filename_all(), string()) -> [file:filename_all()].
List all (regular) files in a directory, skip hidden and temp files. Ensures the list of files is sorted in a consistent way.
-spec log_dir() -> {ok, file:filename_all()} | {error, term()}.
Find the default directory for log files. Checks the following locations:
- The environment variable <tt>ZOTONIC_LOG_DIR</tt>
- Local working directory <tt>logs</tt>
- The OS specific directory for application log files
If no directory is found then the OS specific directory is used:
- Linux: <tt>$HOME/.cache/zotonic/log/</tt>
- macOS: <tt>$HOME/Library/Logs/zotonic//</tt>
-spec security_dir() -> {ok, file:filename_all()} | {error, term()}.
Find the default directory for certificates and other secrets. Checks the following locations:
- The environment variable <tt>ZOTONIC_SECURITY_DIR</tt>
- The directory <tt>$HOME/.zotonic/security</tt>
- The directory <tt>/etc/zotonic/security</tt> (only on Unix)
- The OS specific directory for application config files
If no directory is found then the OS specific directory with the the subdirectory <tt>security</tt> is used:
- Linux: <tt>$HOME/.config/zotonic/security/</tt>
- macOS: <tt>$HOME/Library/Application Support/zotonic/security/</tt>
-spec zotonic_config_files() -> [file:filename()].
List all zotonic config files in the zotonic config directory and the "config.d" subdirectory for the current node. Zotonic config files are "zotonic.*" files in the root of the config directory and all files the 'config.d' subdirectory.
-spec zotonic_config_files(node()) -> [file:filename()].
List all zotonic config files in the zotonic config directory and the "config.d" subdirectory. Zotonic config files are "zotonic.*" files in the root of the config directory and all files the 'config.d' subdirectory.