@@ -68,7 +68,7 @@ defmodule Sentry.Config do
6868
6969 basic_opts_schema = [
7070 dsn: [
71- type: { :or , [ nil , { :custom , __MODULE__ , :__validate_string_dsn__ , [ ] } ] } ,
71+ type: { :or , [ nil , { :custom , Sentry.DSN , :parse , [ ] } ] } ,
7272 default: nil ,
7373 type_doc: "`t:String.t/0` or `nil`" ,
7474 doc: """
@@ -459,7 +459,7 @@ defmodule Sentry.Config do
459459 """
460460 end
461461
462- @ spec dsn ( ) :: nil | { String . t ( ) , String . t ( ) , String . t ( ) }
462+ @ spec dsn ( ) :: nil | Sentry.DSN . t ( )
463463 def dsn , do: get ( :dsn )
464464
465465 # TODO: remove me on v11.0.0, :included_environments has been deprecated
@@ -671,69 +671,4 @@ defmodule Sentry.Config do
671671 { :error , "expected #{ inspect ( key ) } to be a #{ inspect ( mod ) } struct, got: #{ inspect ( term ) } " }
672672 end
673673 end
674-
675- def __validate_string_dsn__ ( dsn ) when is_binary ( dsn ) do
676- uri = URI . parse ( dsn )
677-
678- if uri . query do
679- raise ArgumentError , """
680- using a Sentry DSN with query parameters is not supported since v9.0.0 of this library.
681- The configured DSN was:
682-
683- #{ inspect ( dsn ) }
684-
685- The query string in that DSN is:
686-
687- #{ inspect ( uri . query ) }
688-
689- Please remove the query parameters from your DSN and pass them in as regular
690- configuration. Check out the guide to upgrade to 9.0.0 at:
691-
692- https://hexdocs.pm/sentry/upgrade-9.x.html
693-
694- See the documentation for the Sentry module for more information on configuration
695- in general.
696- """
697- end
698-
699- unless is_binary ( uri . path ) do
700- throw ( "missing project ID at the end of the DSN URI: #{ inspect ( dsn ) } " )
701- end
702-
703- unless is_binary ( uri . userinfo ) do
704- throw ( "missing user info in the DSN URI: #{ inspect ( dsn ) } " )
705- end
706-
707- { public_key , secret_key } =
708- case String . split ( uri . userinfo , ":" , parts: 2 ) do
709- [ public , secret ] -> { public , secret }
710- [ public ] -> { public , nil }
711- end
712-
713- with { :ok , { base_path , project_id } } <- pop_project_id ( uri . path ) do
714- new_path = Enum . join ( [ base_path , "api" , project_id , "envelope" ] , "/" ) <> "/"
715- endpoint_uri = URI . merge ( % URI { uri | userinfo: nil } , new_path )
716-
717- { :ok , { URI . to_string ( endpoint_uri ) , public_key , secret_key } }
718- end
719- catch
720- message -> { :error , message }
721- end
722-
723- def __validate_string_dsn__ ( other ) do
724- { :error , "expected :dsn to be a string or nil, got: #{ inspect ( other ) } " }
725- end
726-
727- defp pop_project_id ( uri_path ) do
728- path = String . split ( uri_path , "/" )
729- { project_id , path } = List . pop_at ( path , - 1 )
730-
731- case Integer . parse ( project_id ) do
732- { _project_id , "" } ->
733- { :ok , { Enum . join ( path , "/" ) , project_id } }
734-
735- _other ->
736- { :error , "expected the DSN path to end with an integer project ID, got: #{ inspect ( path ) } " }
737- end
738- end
739674end
0 commit comments