wttj / ecto_anon Goto Github PK
View Code? Open in Web Editor NEWData anonymization for your Ecto models !
License: MIT License
Data anonymization for your Ecto models !
License: MIT License
Based on https://github.com/revelrylabs/ecto_soft_delete
We could add a anonymized_columns()
for migrations and without_anonymized
/with_anonymized
query helpers
status
, requested_at
and finished_at
fields to the table structure and fill them with your own data)
{source_id, source_type}
identifier tuple may serve as well to find it laterid | source_id | source_type | serialized_changeset | inserted_at |
---|---|---|---|---|
1 | 2345 | User | '{email,<<"redacted">>}' | 2021-12-12-00:00:00 |
serialized_changeset
can be created with:
:io_lib.format("~p", [email: "redacted"]) |> :lists.flatten()
Currently it is only possible to anonymise a field with a value different from the default value providing a custom function for each field.
For example:
defmodule User do
use Ecto.Schema
use EctoAnon.Schema
anon_schema [
name: &__MODULE__.custom_string/3
email: &__MODULE__.custom_string/3
]
schema "users" do
field :name, :string
field :age, :integer
field :email, :string
anonymized()
end
def custom_string(:string, %__MODULE__{} = _user, _opts \\ []), do: "[REDACTED]"
end
user = Repo.get(User, id)
%User{name: "jane", age: 24, email: "[email protected]"}
EctoAnon.run(user, Repo)
{:ok, %User{name: "[REDACTED]", age: 24, email: "[REDACTED]"}}
My suggestion is to have an alternative to provider a different value per type.
For example:
defmodule User do
use Ecto.Schema
use EctoAnon.Schema
anon_schema(
[:name, :email],
anonymized_values: [string: "[REDACTED]"]
)
schema "users" do
field :name, :string
field :age, :integer
field :email, :string
anonymized()
end
end
user = Repo.get(User, id)
%User{name: "jane", age: 24, email: "[email protected]"}
EctoAnon.run(user, Repo)
{:ok, %User{name: "[REDACTED]", age: 24, email: "[REDACTED]"}}
I am not thinking about the implementation details now, only the public interface and its usage for the sake of the discussion of the new feature. ๐
What do you think?
As for now, we only have default anonymizing functions. It would be great to provide functions that are more business aware to keep anonymous data more readable.
Examples:
XX-XX-XX-XX-02
where locale
is configurable)[email protected]
, where domain
and tld
are configurable)Implement the anon_with:
option in anon_field
Being able to specify an option for the runner like cascade: true
and let it anonymize associations of our object could be awesome ! ๐
Right now, you have to precise email: [:anonymized_email, options: [partial: true]]
to enable the option instead of something like email: [:anonymized_email, options: [:partial]]
Would be great in migration & schema for field anonymized
to have an option for a custom name as anonymized
could be already taken !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.