Skip to content

Commit

Permalink
chore: hide further config messages
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Mar 13, 2024
1 parent aa76aae commit 1c67f72
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/postal/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ def initialize_config
Dotenv.load(".env")
sources << Konfig::Sources::Environment.new(ENV)

silence_config_messages = ENV.fetch("SILENCE_POSTAL_CONFIG_MESSAGES", "false") == "true"

# If a config file exists, we need to load that. Config files can
# either be legacy (v1) or new (v2). Any file without a 'version'
# key is a legacy file whereas new-style config files will include
# the 'version: 2' key/value.
if File.file?(config_file_path)
unless ENV.fetch("SILENCE_POSTAL_CONFIG_LOCATION_MESSAGE", "false") == "true"
unless silence_config_messages
warn "Loading config from #{config_file_path}"
end

Expand All @@ -52,18 +54,20 @@ def initialize_config
config_version = yaml["version"] || 1
case config_version
when 1
puts "WARNING: Using legacy config file format. Upgrade your postal.yml to use"
puts "version 2 of the Postal configuration or configure using environment"
puts "variables. See https://postalserver.io/config-v2 for details."
unless silence_config_messages
warn "WARNING: Using legacy config file format. Upgrade your postal.yml to use"
warn "version 2 of the Postal configuration or configure using environment"
warn "variables. See https://postalserver.io/config-v2 for details."
end
sources << LegacyConfigSource.new(yaml)
when 2
sources << Konfig::Sources::YAML.new(config_file)
else
raise "Invalid version specified in Postal config file. Must be 1 or 2."
end
else
puts "No configuration file found at #{config_file_path}"
puts "Only using environment variables for configuration"
elsif !silence_config_messages
warn "No configuration file found at #{config_file_path}"
warn "Only using environment variables for configuration"
end

# Build configuration with the provided sources.
Expand Down

0 comments on commit 1c67f72

Please sign in to comment.