Skip to content

Commit 5489108

Browse files
committed
move public/secret key parsing into function
1 parent ce818a1 commit 5489108

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/sentry/client.ex

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ defmodule Sentry.Client do
212212

213213
with %URI{userinfo: userinfo, host: host, port: port, path: path, scheme: protocol}
214214
when is_binary(path) and is_binary(userinfo) <- URI.parse(dsn),
215-
[public_key, secret_key | _] <- String.split(userinfo, ":", parts: 2) ++ [nil],
215+
[public_key, secret_key] <- keys_from_userinfo(userinfo),
216216
[_, binary_project_id] <- String.split(path, "/"),
217217
{project_id, ""} <- Integer.parse(binary_project_id),
218218
endpoint <- "#{protocol}://#{host}:#{port}/api/#{project_id}/store/" do
@@ -305,6 +305,14 @@ defmodule Sentry.Client do
305305
end
306306
end
307307

308+
defp keys_from_userinfo(userinfo) do
309+
case String.split(userinfo, ":", parts: 2) do
310+
[public, secret] -> [public, secret]
311+
[public] -> [public, nil]
312+
_ -> :error
313+
end
314+
end
315+
308316
defp get_headers_and_endpoint do
309317
case get_dsn() do
310318
{endpoint, public_key, secret_key} ->

0 commit comments

Comments
 (0)