Cased.Sensitive.Handler behaviour (cased v1.0.0)
Behaviour used to identify sensitive data.
Implementing custom handlers only requires two functions:
new/2
, which is called byfrom_spec/1
, passing any custom configuration.ranges/3
, which is called for each value in an audit event byCased.Sensitive.Processor.process/2
.
See Cased.Sensitive.RegexHandler
and tests for example implementations.
Link to this section Summary
Functions
Create a handler from a handler specification (commonly loaded from application config).
Callbacks
Create a handler with a given label and custom configuration.
Extract Cased.Sensitive.Range
structs for a given value
at key
.
Link to this section Types
handler_module()
Specs
handler_module() :: module()
spec()
Specs
spec() :: {module :: handler_module(), label :: atom(), config :: any()}
A tuple structure used to declare the options for a handler.
Examples
Configuring a Cased.Sensitive.RegexHandler
to detect @
-prefixed usernames:
{Cased.Sensitive.RegexHandler, :username, ~r/@w+/}
For your own, custom defined handlers:
{MyApp.CustomHandler, :custom_label_for_handler, custom_configuration_for_handler}
Specs
t() :: %{ :__struct__ => handler_module(), :label => atom(), optional(atom()) => any() }
Link to this section Functions
from_spec(handler)
Specs
Create a handler from a handler specification (commonly loaded from application config).
Examples
Creating a Cased.Sensitive.RegexHandler
from the tuple specification:
iex> handler_spec = {Cased.Sensitive.RegexHandler, :username, ~r/@w+/}
iex> Cased.Sensitive.Handler.from_spec(handler)
%Cased.Sensitive.RegexHandler{label: :username, regex: ~r/@w+/}
Link to this section Callbacks
new(label, config)
Specs
Create a handler with a given label and custom configuration.
ranges(handler, audit_event, {})
Specs
ranges( handler :: t(), audit_event :: map(), {key :: Cased.Sensitive.Range.key(), value :: any()} ) :: [Cased.Sensitive.Range.t()]
Extract Cased.Sensitive.Range
structs for a given value
at key
.
Note that value
can be of any type; your implementation should return an
empty list for any unsupported values.