Class: Sentry::DSN

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/dsn.rb

Constant Summary collapse

PORT_MAP =
{ "http" => 80, "https" => 443 }.freeze
REQUIRED_ATTRIBUTES =
%w[host path public_key project_id].freeze

Instance Method Summary collapse

Constructor Details

#initialize(dsn_string) ⇒ DSN

Returns a new instance of DSN.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sentry/dsn.rb', line 12

def initialize(dsn_string)
  @raw_value = dsn_string

  uri = URI.parse(dsn_string)
  uri_path = uri.path.split("/")

  if uri.user
    # DSN-style string
    @project_id = uri_path.pop
    @public_key = uri.user
    @secret_key = !(uri.password.nil? || uri.password.empty?) ? uri.password : nil
  end

  @scheme = uri.scheme
  @host = uri.host
  @port = uri.port if uri.port
  @path = uri_path.join("/")
end

Instance Method Details

#csp_report_uriObject



45
46
47
# File 'lib/sentry/dsn.rb', line 45

def csp_report_uri
  "#{server}/api/#{project_id}/security/?sentry_key=#{public_key}"
end

#envelope_endpointObject



49
50
51
# File 'lib/sentry/dsn.rb', line 49

def envelope_endpoint
  "#{path}/api/#{project_id}/envelope/"
end

#serverObject



39
40
41
42
43
# File 'lib/sentry/dsn.rb', line 39

def server
  server = "#{scheme}://#{host}"
  server += ":#{port}" unless port == PORT_MAP[scheme]
  server
end

#to_sObject



35
36
37
# File 'lib/sentry/dsn.rb', line 35

def to_s
  @raw_value
end

#valid?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/sentry/dsn.rb', line 31

def valid?
  REQUIRED_ATTRIBUTES.all? { |k| public_send(k) }
end