@@ -140,30 +140,37 @@ defmodule Sentry.Config do
140140 check_dsn = Keyword . get ( opts , :check_dsn , true )
141141 type = Keyword . get ( opts , :type )
142142
143- environment_result =
144- case get_from_application_environment ( key ) do
145- { :ok , value } -> { :ok , value }
146- :not_found -> get_from_system_environment ( config_key_to_system_environment_key ( key ) )
143+ result =
144+ with :not_found <- get_from_application_environment ( key ) ,
145+ env_key = config_key_to_system_environment_key ( key ) ,
146+ system_func = fn -> get_from_system_environment ( env_key ) end ,
147+ :not_found <- save_system_to_application ( key , system_func ) do
148+ if check_dsn do
149+ query_func = fn -> key |> Atom . to_string ( ) |> get_from_dsn_query_string ( ) end
150+ save_system_to_application ( key , query_func )
151+ else
152+ :not_found
153+ end
147154 end
148155
149- result =
150- case environment_result do
151- { :ok , value } ->
152- { :ok , value }
156+ convert_type ( result , type , default )
157+ end
153158
154- :not_found ->
155- if ( check_dsn , do: get_from_dsn_query_string ( Atom . to_string ( key ) ) , else: :not_found )
156- end
159+ defp save_system_to_application ( key , func ) do
160+ case func . ( ) do
161+ :not_found ->
162+ :not_found
157163
158- case result do
159- { :ok , value } -> convert_type ( value , type )
160- :not_found -> default
164+ { :ok , value } ->
165+ Application . put_env ( :sentry , key , value )
166+ { :ok , value }
161167 end
162168 end
163169
164- defp convert_type ( value , nil ) , do: value
165- defp convert_type ( value , :list ) when is_list ( value ) , do: value
166- defp convert_type ( value , :list ) when is_binary ( value ) , do: String . split ( value , "," )
170+ defp convert_type ( { :ok , value } , nil , _ ) , do: value
171+ defp convert_type ( { :ok , value } , :list , _ ) when is_list ( value ) , do: value
172+ defp convert_type ( { :ok , value } , :list , _ ) when is_binary ( value ) , do: String . split ( value , "," )
173+ defp convert_type ( _ , _ , default ) , do: default
167174
168175 defp get_from_application_environment ( key ) when is_atom ( key ) do
169176 case Application . fetch_env ( :sentry , key ) do
0 commit comments