module
Amber::Configuration
Defined in:
amber/configuration/app_config.cramber/configuration/credentials_directory.cr
amber/configuration/custom_registry.cr
amber/configuration/database_config.cr
amber/configuration/env_override.cr
amber/configuration/jobs_config.cr
amber/configuration/logging_config.cr
amber/configuration/mailer_config.cr
amber/configuration/params_config.cr
amber/configuration/pubsub_config.cr
amber/configuration/section_field.cr
amber/configuration/server_config.cr
amber/configuration/session_config.cr
amber/configuration/static_config.cr
Class Method Summary
-
.check_custom_yaml(key : String, section_yaml : String) : Nil
Raises when section_yaml does not read as the type registered for key: a
YAML::ParseException, or whatever the type's converter orafter_initializeraises. -
.credential_section?(key : String) : Bool
Returns true when the section's values come from a credentials directory.
-
.credential_source(key : String) : String | Nil
Returns a credentials section as YAML, each value a double-quoted string, or nil when the section does not come from a credentials directory.
-
.custom_config_defaults : Hash(String, YAML::Serializable)
Returns all registered custom config keys and their default instances.
-
.custom_config_fields(key : String) : Array(SectionField) | Nil
Returns the fields of a registered section's type, or nil when the section is not registered.
-
.custom_default_yaml(key : String) : String | Nil
Returns a registered section's default instance written as YAML, every field it reads included, or nil when the section is not registered.
-
.register_credentials(key : Symbol | String, type : T.class, directory : String, *, maximum_file_size : Int64 = CredentialsDirectory::DEFAULT_MAXIMUM_FILE_SIZE, maximum_total_size : Int64 = CredentialsDirectory::DEFAULT_MAXIMUM_TOTAL_SIZE) : Nil forall T
Registers a typed section whose values are read from a credentials directory: one file per credential, the file name as the key and the contents as the value (the layout of systemd's
$CREDENTIALS_DIRECTORY). -
.register_custom(key : String, default_instance : T) : Nil forall T
Runtime registration method called by the
registermacro. -
.store_credentials_section(key : String, credentials : T, values : Hash(String, String)) : Nil forall T
Registers an already-read credentials section and keeps its values, so the loader stores the section from them and rejects a YAML section with the same key.
Macro Summary
-
register(key, config_type)
Register a custom configuration type with the Amber settings system.
Class Method Detail
Raises when section_yaml does not read as the type registered for
key: a YAML::ParseException, or whatever the type's converter or
after_initialize raises. Does nothing for an unregistered key. :nodoc:
Returns true when the section's values come from a credentials directory.
Returns a credentials section as YAML, each value a double-quoted string, or nil when the section does not come from a credentials directory. The loader stores it as the section's YAML. :nodoc:
Returns all registered custom config keys and their default instances.
Returns the fields of a registered section's type, or nil when the section is not registered. :nodoc:
Returns a registered section's default instance written as YAML, every field it reads included, or nil when the section is not registered. :nodoc:
Registers a typed section whose values are read from a credentials
directory: one file per credential, the file name as the key and the
contents as the value (the layout of systemd's $CREDENTIALS_DIRECTORY).
Only the files the section's type declares are read.
The section must be registered before the first Amber.settings read,
so require the file that calls this before anything that reads settings.
The application, not Amber, reads ENV["CREDENTIALS_DIRECTORY"]? and
passes the directory in.
Raises Amber::Exceptions::CredentialsRegisteredAfterSettingsLoad when
Amber.settings is already loaded, and any other
Amber::Exceptions::CredentialsError the directory reader raises.
Example
# config/credentials.cr, required by config/application.cr right after "amber"
struct AppCredentials
include YAML::Serializable
property secret_key_base : String = ""
def initialize
end
end
if credentials_directory = ENV["CREDENTIALS_DIRECTORY"]?
Amber::Configuration.register_credentials(:credentials, AppCredentials, credentials_directory)
else
Amber::Configuration.register(:credentials, AppCredentials)
end
Runtime registration method called by the register macro.
Registers an already-read credentials section and keeps its values, so the loader stores the section from them and rejects a YAML section with the same key. :nodoc:
Macro Detail
Register a custom configuration type with the Amber settings system.
After registration, the config can be loaded from YAML files under
the given key and accessed via Amber.settings.custom(:key, Type).
Example
struct MyAppConfig
include YAML::Serializable
property api_key : String = ""
def initialize
end
end
Amber::Configuration.register(:my_app, MyAppConfig)