Skip to content

Commit

Permalink
fix: only regex a string (#16)
Browse files Browse the repository at this point in the history
Co-authored-by: Vasilis Spilka <[email protected]>
  • Loading branch information
twhitbeck and vasspilka authored Jan 31, 2024
1 parent 0d8a92b commit b13b235
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/logger_json/plug/metadata_formatters/datadog_logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ if Code.ensure_loaded?(Plug) do
- The expected outcome would be something like "stord_sk_publickeyasdfasdf_*******", assuming "*******" is the scrub value.
- You can use DataDog's regex to extract the public key part and turn it into a standard attribute.
"""
def extract_public_key(value, scrub_value) do
def extract_public_key(value, scrub_value) when is_binary(value) do
case Regex.named_captures(
~r/Bearer stord_(?<type>sk|ak)_(?<public_key>[A-Za-z0-9+\/]+)_(?<secret_key>.+)/,
value
Expand All @@ -121,6 +121,8 @@ if Code.ensure_loaded?(Plug) do
end
end

def extract_public_key(_value, scrub_value), do: scrub_value

defp scrubbed_value(key, actual_value, scrub_map) do
case Map.get(scrub_map, key) do
{mod, func, args} when is_atom(mod) and is_atom(func) and is_list(args) ->
Expand Down

0 comments on commit b13b235

Please sign in to comment.