module Amber::Configuration

Defined in:

amber/configuration/app_config.cr
amber/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

Macro Summary

Class Method Detail

def self.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 or after_initialize raises. Does nothing for an unregistered key. :nodoc:


[View source]
def self.credential_section?(key : String) : Bool #

Returns true when the section's values come from a credentials directory.


[View source]
def self.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. The loader stores it as the section's YAML. :nodoc:


[View source]
def self.custom_config_defaults : Hash(String, YAML::Serializable) #

Returns all registered custom config keys and their default instances.


[View source]
def self.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. :nodoc:


[View source]
def self.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. :nodoc:


[View source]
def self.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). 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

[View source]
def self.register_custom(key : String, default_instance : T) : Nil forall T #

Runtime registration method called by the register macro.


[View source]
def self.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. :nodoc:


[View source]

Macro Detail

macro register(key, config_type) #

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)

[View source]