Policy builders and validators for visibility rules.
This module provides functions to create and validate visibility policies for different database resource types (schemas, tables, columns)
Schema and Table Policies
Schemas and tables use simple allow/deny policies:
Policy.schema_allow() # => :allow
Policy.schema_deny() # => :denyColumn Policies
Columns support more complex policies with various actions:
# Simple actions
Policy.column_allow() # Show column normally
Policy.column_omit() # Remove from results
Policy.column_error() # Fail query if selected
# Masking with strategies
Policy.column_mask(:sha256)
Policy.column_mask({:fixed, "REDACTED"})
Policy.column_mask({:partial, keep_last: 4})
# With options
Policy.column_mask(:sha256, show_in_schema?: false)
Summary
Functions
Checks if a column policy allows the column.
Checks if a column policy causes an error.
Creates a policy that allows a column to be shown normally.
Creates a policy that causes queries to error if the column is selected.
Creates a policy that masks column values using the specified strategy.
Creates a policy that omits a column from query results.
Checks if a column should be hidden from schema introspection.
Normalizes a column policy from various input formats.
Checks if a column policy omits the column.
Checks if a column policy requires masking.
Creates an allow policy for schemas.
Creates a deny policy for schemas.
Creates an allow policy for tables.
Creates a deny policy for tables.
Validates if a value is a valid column policy.
Validates if a value is a valid schema policy.
Validates if a value is a valid table policy.
Validates a mask strategy, raising if invalid.
Types
@type column_action() :: :allow | :omit | :mask | :error
@type column_policy() :: %{ action: column_action(), mask: mask_strategy() | nil, show_in_schema?: boolean() }
@type schema_policy() :: :allow | :deny
@type table_policy() :: :allow | :deny
Functions
@spec allows_column?(column_policy()) :: boolean()
Checks if a column policy allows the column.
@spec causes_error?(column_policy()) :: boolean()
Checks if a column policy causes an error.
@spec column_allow(keyword()) :: column_policy()
Creates a policy that allows a column to be shown normally.
Examples
iex> Policy.column_allow()
%{action: :allow, show_in_schema?: true}
@spec column_error(keyword()) :: column_policy()
Creates a policy that causes queries to error if the column is selected.
Examples
iex> Policy.column_error()
%{action: :error, show_in_schema?: true}
@spec column_mask( mask_strategy(), keyword() ) :: column_policy()
Creates a policy that masks column values using the specified strategy.
Mask Strategies
:null- Replace with NULL:sha256- Replace with SHA256 hash{:fixed, value}- Replace with fixed value{:partial, opts}- Partial masking with options:keep_first: n- Keep first n characterskeep_last: n- Keep last n charactersreplacement: str- Character to use for masking (default: "*")
Examples
iex> Policy.column_mask(:sha256)
%{action: :mask, mask: :sha256, show_in_schema?: true}
iex> Policy.column_mask({:fixed, "REDACTED"})
%{action: :mask, mask: {:fixed, "REDACTED"}, show_in_schema?: true}
iex> Policy.column_mask({:partial, keep_last: 4})
%{action: :mask, mask: {:partial, keep_last: 4}, show_in_schema?: true}
iex> Policy.column_mask(:sha256, show_in_schema?: false)
%{action: :mask, mask: :sha256, show_in_schema?: false}
@spec column_omit(keyword()) :: column_policy()
Creates a policy that omits a column from query results.
The column is removed entirely from the result set.
Examples
iex> Policy.column_omit()
%{action: :omit, show_in_schema?: true}
iex> Policy.column_omit(show_in_schema?: false)
%{action: :omit, show_in_schema?: false}
@spec normalize_column_policy(keyword() | atom() | map()) :: column_policy()
Normalizes a column policy from various input formats.
Accepts:
- Keyword list:
[action: :mask, mask: :sha256] - Atom shorthand:
:omit - Map:
%{action: :mask, mask: :null}
Returns a normalized policy map with all required fields.
@spec omits_column?(column_policy()) :: boolean()
Checks if a column policy omits the column.
@spec requires_mask?(column_policy()) :: boolean()
Checks if a column policy requires masking.
@spec schema_allow() :: :allow
Creates an allow policy for schemas.
@spec schema_deny() :: :deny
Creates a deny policy for schemas.
@spec table_allow() :: :allow
Creates an allow policy for tables.
@spec table_deny() :: :deny
Creates a deny policy for tables.
Validates if a value is a valid column policy.
Validates if a value is a valid schema policy.
Validates if a value is a valid table policy.
@spec validate_mask_strategy!(any()) :: mask_strategy() | no_return()
Validates a mask strategy, raising if invalid.